Migrating Code in ScriptOperator
Name changes of variables available in scripts
Carmenta Engine 4.x | Carmenta Engine 5 |
---|---|
geoObjects or gobs | features |
geoObject or gob | feature |
arguments | userProperties |
updateInfo | viewInfo |
Code examples
'Attribute setter' example
var name = args("attributeName");
var value = args("attributeValue");
var atts = gob.Attributes;
atts(name) = value;
gob.Attributes = atts;
name = userProperties['attributeName']
value = userProperties['attributeValue']
feature.attributes[name] = value
'Center of polygon' example
var lg = new ActiveXObject("SpatialAce4.LineGeometry");
lg.CreateEx(gob.Points);
var pg = new ActiveXObject("SpatialAce4.PolygonGeometry");
var mlg = new ActiveXObject("SpatialAce4.MultiLineGeometry");
mlg.Create(0);
pg.Create(lg, mlg);
var cpg = pg.Center();
var gp = new ActiveXObject("SpatialAce4.GeoPoint");
gp.CreateEx(gob.RefSys, cpg.GetPoint());
gp.Attributes = gob.Attributes;
return gp;
polygon = feature.getGeometryAsPolygon()
if polygon:
return Feature(PointGeometry(polygon.center), feature.crs, feature.attributes)
'Largest value filter' (AllAtOnce-mode) example
var catName = args("category");
var valName = args("value");
var numObjects = gobs.Count;
var categoryToObject = {};
for(var i=0; i<numObjects; i++) {
var curgob = gobs.Item(i);
var curcat = curgob.Attributes(catName);
var bestgob = categoryToObject[curcat];
if (bestgob == null) {
categoryToObject[curcat] = curgob;
} else {
var bestval = bestgob.Attributes(valName);
var curval = curgob.Attributes(valName);
if (curval > bestval)
categoryToObject[curcat] = curgob;
}
}
var retVal = new ActiveXObject("SpatialAce4.GeoObjects");
for(var cat in categoryToObject) {
var gob = categoryToObject[cat];
retVal.Add(gob);
}
return retVal;
categoryName = userProperties['category']
valueName = userProperties['value']
largestValues = {}
for feature in features:
category = feature.attributes[categoryName]
if category in largestValues:
largest = largestValues[category].attributes[valueName]
if feature.attributes[valueName] > largest:
largestValues[category] = feature
else:
largestValues[category] = feature
return list(largestValues.values())