I'm working on converting Attribute Assistant Methods to Attribute Rules. The intent of the below AR is to populate several fields in a newly created Water Main (line feature) from attributes of an existing Water Main feature that intersects either the start point or the endpoint of the new feature.
So the Arcade expression is first looking to see if an existing Water Main intersects the startpoint of the new Water Main, and if so copy over the attributes. This part of the expression works just fine for all 4 attributes. No matter what I've tried, I can't seem to get the next part of the expression to work.
If I create a new feature where the startpoint doesn't intersect an existing feature but the endpoint does intersect an existing feature, the attributes of the new feature remain null. Similarly, if I create a new feature where neither the startpoint or endpoint intersect an existing feature, the attributes of the new feature remain null.
var linegeometry = Geometry($feature)
var wMain = FeatureSetByName($datastore,"wMain",["WATERLEVEL","PRESSUREZONE","PZONETYPE","SERVICEAREA"],true)
var startpoint = linegeometry.paths[0][0]
var endpoint = linegeometry.paths[-1][-1]
var startpoint_intMain = First(Intersects(wMain,startpoint))
var endpoint_intMain = First(Intersects(wMain,endpoint))
var waterlevel
var pressurezone
var pzonetype
var servicearea
if(!IsEmpty(startpoint_intMain)) {
waterlevel = startpoint_intMain.WATERLEVEL
pressurezone = startpoint_intMain.PRESSUREZONE
pzonetype = startpoint_intMain.PZONETYPE
servicearea = startpoint_intMain.SERVICEAREA
}
else if(!IsEmpty(endpoint_intMain)) {
waterlevel = endpoint_intMain.WATERLEVEL
pressurezone = endpoint_intMain.PRESSUREZONE
pzonetype = endpoint_intMain.PZONETYPE
servicearea = endpoint_intMain.SERVICEAREA
}
else {
waterlevel = 'NA'
pressurezone = 'NA'
pzonetype = 'NA'
servicearea = 'NA'
}
return {
"result": {
"attributes": {
"WATERLEVEL": waterlevel,
"PRESSUREZONE": pressurezone,
"PZONETYPE": pzonetype,
"SERVICEAREA": servicearea
}
}
}
Here is another attempt which provided the same result:
var linegeometry = Geometry($feature)
var wMain = FeatureSetByName($datastore,"wMain",["WATERLEVEL","PRESSUREZONE","PZONETYPE","SERVICEAREA"],true)
var startpoint = linegeometry.paths[0][0]
var endpoint = linegeometry.paths[-1][-1]
var startpoint_intMain = First(Intersects(wMain,startpoint))
var endpoint_intMain = First(Intersects(wMain,endpoint))
var waterlevel
var pressurezone
var pzonetype
var servicearea
if(!IsEmpty(startpoint_intMain)) {
waterlevel = startpoint_intMain.WATERLEVEL
pressurezone = startpoint_intMain.PRESSUREZONE
pzonetype = startpoint_intMain.PZONETYPE
servicearea = startpoint_intMain.SERVICEAREA
return {
"result": {
"attributes": {
"WATERLEVEL": waterlevel,
"PRESSUREZONE": pressurezone,
"PZONETYPE": pzonetype,
"SERVICEAREA": servicearea
}
}
}
}
else if(!IsEmpty(endpoint_intMain)) {
waterlevel = endpoint_intMain.WATERLEVEL
pressurezone = endpoint_intMain.PRESSUREZONE
pzonetype = endpoint_intMain.PZONETYPE
servicearea = endpoint_intMain.SERVICEAREA
return {
"result": {
"attributes": {
"WATERLEVEL": waterlevel,
"PRESSUREZONE": pressurezone,
"PZONETYPE": pzonetype,
"SERVICEAREA": servicearea
}
}
}
}
else {
waterlevel = 'NA'
pressurezone = 'NA'
pzonetype = 'NA'
servicearea = 'NA'
return {
"result": {
"attributes": {
"WATERLEVEL": waterlevel,
"PRESSUREZONE": pressurezone,
"PZONETYPE": pzonetype,
"SERVICEAREA": servicearea
}
}
}
}
Any idea why the else if / else statements might not be evaluating?
Thanks in advance for any thoughts!