Hi there,
I've been working on a data expression that creates a data dictionary using some existing fire hydrant fields to calculate a value for a new field. I have the expression mostly working but it is only returning one feature. I don't have any filters in my featureset and when I return the variable for Hydrants with the rest of the expression commented out, it returns all the features. I've done similar dictionaries in past without calculating a new value and have worked fine, I just cant figure out what I'm missing here. The resulting table should have a new field for PSI difference, calculated by the difference in Calculated PSI and Measured PSI.
ArcGIS Enterprise 10.9.1
var tvwdportal = Portal('https://mapping.tvwd.org/portal')
var Hydrants = FeatureSetByPortalItem(tvwdportal,"b24772e427084f21b1f208a685d07fcc",5,['MaintainedBy','LifeCycleStatus','CalcStaticPSI','MeasuredStaticPSI', 'UniqueID'],True) ;
var out_dict = {
'fields':[{name: 'PSIDifference', type: 'esriFieldTypeInteger'},
{name: 'CalculatedPSI', type: 'esriFieldTypeInteger'},
{name: 'MeasuredPSI', type: 'esriFieldTypeInteger'}],
'geometryType': '',
'features': []}
for (var f in Hydrants) {
var f_CalcStaticPSI = Number(f['CalcStaticPSI'])
var f_MeasuredPSI = Number(f['MeasuredStaticPSI'])
var f_PSIDifference = Number(sum(f['CalcStaticPSI']- f['MeasuredStaticPSI']))
}
Push(out_dict['features'], {'attributes': {'CalculatedPSI':f_CalcStaticPSI,'MeasuredPSI': f_MeasuredPSI,'PSIDifference':f_PSIDifference}})
console(out_dict)
return FeatureSet(Text(out_dict))
Solved! Go to Solution.
Line 21 should be inside the for loop.
for (var f in Hydrants) {
var f_CalcStaticPSI = Number(f['CalcStaticPSI'])
var f_MeasuredPSI = Number(f['MeasuredStaticPSI'])
var f_PSIDifference = Number(sum(f['CalcStaticPSI']- f['MeasuredStaticPSI']))
Push(out_dict['features'], {'attributes': {'CalculatedPSI':f_CalcStaticPSI,'MeasuredPSI': f_MeasuredPSI,'PSIDifference':f_PSIDifference}})
}
Line 21 should be inside the for loop.
for (var f in Hydrants) {
var f_CalcStaticPSI = Number(f['CalcStaticPSI'])
var f_MeasuredPSI = Number(f['MeasuredStaticPSI'])
var f_PSIDifference = Number(sum(f['CalcStaticPSI']- f['MeasuredStaticPSI']))
Push(out_dict['features'], {'attributes': {'CalculatedPSI':f_CalcStaticPSI,'MeasuredPSI': f_MeasuredPSI,'PSIDifference':f_PSIDifference}})
}
Yep that was it. I knew it was going something easy like that. I really appreciate you getting a second pair of eyes on it and getting back to me. Have a great weekend!