Hi everybody,
I'm attempting to develop an Arcade Rule that, given a feature geometry, identifies the closest address feature within a specified buffer distance. The script should then update the created or updated features attributes with the closest attributes of the closest address feature. However, as so often, I'm encountering an issue with the script.
heres the script im using:
var featureGeometry = Geometry($feature)
if(isEmpty(featureGeometry)){
return Null
}
var addressesLN = FeatureSetByName($datastore, 'VG_ADDRESSES_LN', ['*'], true)
var addressesPT = FeatureSetByName($datastore, 'VG_ADDRESSES_LN', ['*'], true)
var addressesAR = FeatureSetByName($datastore, 'VG_ADDRESSES_LN', ['*'], true)
var bufferSize = 20
var bufferPolygon = Buffer(featureGeometry, bufferSize, 'meters')
var bufferIntersectingLN = Intersects(addressesLN, featureGeometry)
var bufferIntersectingPT = Intersects(addressesPT, featureGeometry)
var bufferIntersectingAR = Intersects(addressesAR, featureGeometry)
var mostInformativeAddresses = Null
if(!isEmpty(bufferIntersectingPT)){
mostInformativeAddresses = bufferIntersectingPT
} else if (!isEmpty(bufferIntersectingLN)){
mostInformativeAddresses = bufferIntersectingLN
} else if (!isEmpty(bufferIntersectingAR)){
mostInformativeAddresses = bufferIntersectingAR
} else {
return
}
if(isEmpty(mostInformativeAddresses)){
return
}
var closestFeature = Null
var closestDistance = 9999
for(var addressFeature in mostInformativeAddresses){
var currentDistance = Distance(featureGeometry, Geometry(addressFeature), 'meters')
if (currentDistance < closestDistance){
closestFeature = currentFeature
closestDistance = currentDistance
}
}
return{
"result":{
"attributes":{
"ADM_KEY_COMM": closestFeature.ADM_KEY_COMM,
"ADM_KEY_STREET": closestFeature.ADM_KEY_STREET,
"ADM_KEY_COMMPART": closestFeature.ADM_KEY_COMMPART,
"ADM_KEY_ADDRESS": closestFeature.ADM_KEY_ADDRESS,
"ADDRESS_TEXT": closestFeature.ADDRESS_TEXT
}
}
}
The script validates without errors, but it doesn't return any values, even though there is a valid address feature within a reasonable distance.
Can anybody help me find the issue here or suggest any improvements to the script?
Any assistance would be greatly appreciated!
Thanks,
Stefan