Select to view content in your preferred language

ArcGIS Pro Attribute Rules Equivalent to NEAREST_FEATURE Function in Attribute Assistant

3775
4
Jump to solution
02-26-2021 11:09 AM
Labels (2)
GISUSER6
Regular Contributor

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! 

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi @GISUSER6 ,

 

I did a test with a local coordinate system and it will work with some minor adjustments:

XanderBakker_0-1615556627727.png

 

You will need to:

  • Use Buffer instead of BufferGeodetic
  • Use Distance instead of DistanceGeodetic
  • Place "var" before street in the for loop.
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;

 

View solution in original post

4 Replies
XanderBakker
Esri Esteemed Contributor

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;
GISUSER6
Regular Contributor

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. 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @GISUSER6 ,

 

I did a test with a local coordinate system and it will work with some minor adjustments:

XanderBakker_0-1615556627727.png

 

You will need to:

  • Use Buffer instead of BufferGeodetic
  • Use Distance instead of DistanceGeodetic
  • Place "var" before street in the for loop.
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;

 

GISUSER6
Regular Contributor

This worked perfectly! Thank you so much.

 

Anna

0 Kudos