Hi All,
I have an arcade script that I often use to return the closest value to a given point. In this case, an address number. When I try it in this particular instance, I receive "Test execution error: Execution error - Cannot access value using a key of this type. Verify test data."
This is my script. The funny thing is that I copied it from another calculation (in field maps) just to return an ID from a water main. I am not sure why this one isn't working.
Solved! Go to Solution.
Where are you running this? Depending on the context, $map may not be available.
The function Intersects returns a FeatureSet. Your expression replaces closestPlace with place if there's a feature found within the buffer, but if there isn't then closestPlace will still be a FeatureSet.
Personally, I would avoid re-using a variable for different types of objects. You might try something like this. By creating a placeholder place with a null value, and by keeping the FeatureSet and the Feature in their own variables, we don't get issues when we try to call the value at the end.
And yes, a dictionary and Feature are different types of objects, I know, but in this case, you can call their attributes in the same way.
var address = FeatureSetByName($map, "Addresses")
var searchDistance = 1
var closePlaces = Intersects(address, Buffer($feature, searchDistance, 'miles'))
var minDistance = Infinity
// create placeholder closest place with a building number
var closestPlace = {'bldg_num':null}
for (var place in closePlaces){
var placeDistance = Distance(place, $feature, 'mile');
if (placeDistance < minDistance){
minDistance = placeDistance;
closestPlace = place;
}
};
return closestPlace['bldg_num']
Try running one line at a time, or use Console to check output, to see where the error occurs.
Where are you running this? Depending on the context, $map may not be available.
The function Intersects returns a FeatureSet. Your expression replaces closestPlace with place if there's a feature found within the buffer, but if there isn't then closestPlace will still be a FeatureSet.
Personally, I would avoid re-using a variable for different types of objects. You might try something like this. By creating a placeholder place with a null value, and by keeping the FeatureSet and the Feature in their own variables, we don't get issues when we try to call the value at the end.
And yes, a dictionary and Feature are different types of objects, I know, but in this case, you can call their attributes in the same way.
var address = FeatureSetByName($map, "Addresses")
var searchDistance = 1
var closePlaces = Intersects(address, Buffer($feature, searchDistance, 'miles'))
var minDistance = Infinity
// create placeholder closest place with a building number
var closestPlace = {'bldg_num':null}
for (var place in closePlaces){
var placeDistance = Distance(place, $feature, 'mile');
if (placeDistance < minDistance){
minDistance = placeDistance;
closestPlace = place;
}
};
return closestPlace['bldg_num']
Hi Josh,
This is running in the calculate section where you set up arcade for field maps.
The only reason I am stumped as to why this one doesn't work, is because I am using the exact same expression (just different layers) in another field maps field and it works just fine.
I will give what you have a shot and see if that works instead.
Have you checked the following?
You can also use Console statements to check variable values, which should appear in the browser developer console.
Yep, I checked both of these. bldg_num is in the layer (directly added from the variables tab). and I don't think closest place should ever be null, but it may be possible. There are also no null features in the feature layer.