Select to view content in your preferred language

Field Calculator — Get attribute of touching feature from different FC

137
2
Tuesday
Status: Open
Labels (1)
Bud
by
Esteemed Contributor

I have a POINTS FC and a POLYGONS FC.

In POINTS, I want to use the field calculator to populate a POINTS.ASSET_ID field with the ASSET_IDs from POLYGONS, where a point touches a polygon. The spatial relationship is 1:1.

In other words, I want to get the ASSET_ID from the intersecting polygon and use it to populate the ASSET_ID field in the point.

I want to do this all within a simple field calculation, not using multiple GP tools and joins.

I would also like this to work for cases where the ID fields don’t have the same name.

2 Comments
CraigWilliams

You can do this with Arcade in Calculate Field. Given the names you have above and with the Field Name of the calculate field tool being ASSET_ID on the Points layer:

var polygons = FeatureSetByName($datastore, "POLYGONS",['ASSET_ID'], true);
var polygonFeature = First(Intersects(polygons, $feature));
if (!IsEmpty(polygonFeature))
{
  return DefaultValue(polygonFeature, 'ASSET_ID', "9999");
}
else {
  return "9999";
}

 

SSWoodward

You could also implement this as an attribute rule on the point class using the Generate Spatial Join Attribute Rule GP tool, this way, if your point were ever to move, the ID field would update automatically to reflect the new polygon intersection.  Ensuring the rule triggers on updates to the shape field only will keep the rule from firing unnecessarily.