Hello!
Wondering if I could get some help with this rule.
"x.DBO.CapacityBlockface" - Contains a GUID field ['Blockface_GUID'] and a null count field ['Capacity'] to be populated by this rule.
"x.DBO.StreetParking" has a GUID field, ['Blockface_GUID,'] which is auto-populated by an attribute rule that identifies the nearest "CapacityBlockface" GUID through a buffer and intersect operation. Additionally, it includes a field called ['NumberCars'], which is populated by an attribute rule that calculates the number of cars that can fit within that segment.
What I would like this rule to do is - on the insert, update, or delete of a "StreetParking" feature, I want it to automatically calculate the number of available parking spots between all features that share a GUID. When it calculates the total, I want it to write to the "CapacityBlockface" feature that shares that GUID.
Example:
Three "StreetParking" segments (orange) contain different available parking based on length. They also contain the same GIUD (11E6 - last 4 of GUID) as the "CapacityBlockface" (white). On the insert, update, or delete of a "StreetParking" feature, I want the total number of cars between all that share a GUID to be pushed to the blockface feature field ['Capacity']. Therefore 11E6 will have 10 cars.
Using this code, I can return the total number of cars through console, but I am running into issue when trying to return it to the "CapacityBlockface" layer. I get the error "Dictionary Type Expected" on the GlobalID on line 18.
Any input would be greatly appreciated!!
var blockface = FeatureSetByName($datastore, "x.DBO.CapacityBlockface", ["Blockface_GUID", "Capacity", "GlobalID"], false)
var parking = FeatureSetByName($datastore,"x.DBO.StreetParking",["Blockface_GUID", "NumberCars"],false)
var parking_GUID = $feature.Blockface_GUID
var sql = 'Blockface_GUID LIKE @parking_GUID'
var masterFilter = Filter(parking,sql)
var countCars = 0
for(var i in masterFilter){
countCars += i.NumberCars
}
return {
'edit': [{
'className': "x.DBO.CapacityBlockface",
'updates': [{
'GlobalID': blockface.GlobalID,
'attributes': {
'Capacity': 'countCars'
}
}]
}]
}
Solved! Go to Solution.
Thank you Mike!
This is what I got working.
var blockface = FeatureSetByName($datastore, "x.DBO.CapacityBlockface", ["Blockface_GUID", "Capacity", "GlobalID"], false);
var parking = FeatureSetByName($datastore, "x.DBO.StreetParking", ["Blockface_GUID", "NumberCars"], false);
var parking_GUID = $feature.Blockface_GUID;
var sql = 'Blockface_GUID = @parking_GUID';
var filterParking = Filter(parking, sql);
var filterBlockface = Filter(blockface, sql);
var sumCars = 0;
for (var i in filterParking) {
sumCars += i.NumberCars;
}
var filterblockface_GlobalID = "";
for (var i in filterBlockface) {
filterblockface_GlobalID = i.GlobalID;
}
return {
'edit': [{
'className': "x.DBO.CapacityBlockface",
'updates': [{
'GlobalID': filterblockface_GlobalID,
'attributes': {
'Capacity': sumCars
}
}]
}]
};