I'm writing a data expression to show which polygon (mmz) each point (leaks) resides within. I also need to keep a few fields from the leaks feature. I can populate the 'mmz' field, but I'm having trouble getting the other fields I need. Here's what I have so far and the results:
var port = Portal('my portal')
var mmz = FeatureSetByPortalItem(port, 'c879aa9267604224a3f6d492fc997a50', 7,['ZONE_NAME'],true)
var leaks = FeatureSetByPortalItem(port, '44fa0f9330e449c289dfadf2553d805b', 0,['leakloss','leaktype','dateshot','leaks_count','material','maindiameter'],true)
var features = []
var feat
for (var zone in mmz){
var pts = Contains(zone,leaks)
for (var pt in pts){
feat = {attributes:{
mmz: zone ['ZONE_NAME'],
leakloss: pt ['leakloss'],
leaktype: pt ['leaktype'],
dateshot: pt ['dateshot'],
leaks_count: pt ['leaks_count'],
material: pt ['material'],
maindiameter: pt ['maindiameter']
}
}
Push(features,feat)
}
}
var dict = {
fields: [
{name: "mmz", alias:"Zone", type:"esriFieldTypeString"},
{name: "leakloss", alias:"Gallons Lost", type:"esriFieldTypeInteger"},
{name: "leaks_count", alias:"Number of Leaks", type:"esriFieldTypeInteger"},
{name: "leaktype", alias:"Leak Type", type:"esriFieldTypeString"},
{name: "dateshot", alias:"Date", type:"esriFieldTypeDate"},
{name: "material", alias:"Material", type:"esriFieldTypeString"},
{name: "maindiameter", alias:"Diameter", type:"esriFieldTypeInteger"},
],
geometryType:"",
features:features
}
return FeatureSet(Text(dict))
Results: