ArcGIS Pro 2.7
Hello,
I am trying to set up an attribute rule that will pull from the NAME field of a streets center line layer and populate it into a STREET field in the feature class I am adding the rule to. I know the same function does not exist in Attribute Rules as it does for NEAREST_FEATURE in Attribute Assistant, but I am trying to come up with an Arcade expression to do the same thing. The search distance I want to use is 100 ft. Attached is the snip of the code I started with but I keep getting an error.
Some guidance would be much appreciated!
Solved! Go to Solution.
Hi @GISUSER6 ,
I did a test with a local coordinate system and it will work with some minor adjustments:
You will need to:
var streetLayer = FeatureSetByName($datastore, "streets_WGS_Project", ["NAME"]);
var searchDistance = 100;
var streetIntersect = Intersects(streetLayer, Buffer($feature, searchDistance, "feet"));
var cnt = Count(streetIntersect);
var minDistance = Infinity;
var name = Null
if (cnt > 0) {
for (var street in streetIntersect) {
var dist = Distance(street, $feature, "feet");
if (dist < minDistance) {
name = street.NAME;
minDistance = dist
}
}
} else {
// pass no features found within search distance, name remains null
}
return name;
Hi @GISUSER6 ,
You can do something like this:
var streetLayer = FeatureSetByName($datastore, "streets", ["NAME"]);
var searchDistance = 100;
var streetIntersect = Intersect(streetLayer, BufferGeodetic($feature, searchDistance, "feet"));
var cnt = Count(streetIntersect);
var minDistance = Infinity;
var name = Null
if (cnt > 0) {
for (street in streetIntersect) {
var dist = DistanceGeodetic(street, $feature, "feet");
if (dist < minDistance) {
name = street.NAME;
minDistance = dist
}
}
} else {
// pass no features found within search distance, name remains null
}
return name;
Hi @XanderBakker ,
This looks great. Thanks for your help. I see that this function is limited to Web Mercator (wkid 3857) or a WGS 84 (wkid 4326) spatial reference. ( https://developers.arcgis.com/arcade/function-reference/geometry_functions/ ) I think this is the reason I am coming up with an error message when I use the code you provided. Do you know if there is a work around for this? I am working with a Wisconsin county reference system.
I worked with ESRI customer service on this issue but we have been unsuccessful so far. I even tried projecting the streets layer that the BufferGeodetic is being use to WGS 1984 but this still produces the Error on line 3. Projection is invalid. There's got to be something that I am doing wrong still or there has to be a work-around.. otherwise Attribute Rules is super restricting when it comes to this! A text file as been attached with my latest Arcade code.
Hi @GISUSER6 ,
I did a test with a local coordinate system and it will work with some minor adjustments:
You will need to:
var streetLayer = FeatureSetByName($datastore, "streets_WGS_Project", ["NAME"]);
var searchDistance = 100;
var streetIntersect = Intersects(streetLayer, Buffer($feature, searchDistance, "feet"));
var cnt = Count(streetIntersect);
var minDistance = Infinity;
var name = Null
if (cnt > 0) {
for (var street in streetIntersect) {
var dist = Distance(street, $feature, "feet");
if (dist < minDistance) {
name = street.NAME;
minDistance = dist
}
}
} else {
// pass no features found within search distance, name remains null
}
return name;
This worked perfectly! Thank you so much.
Anna