Select to view content in your preferred language

Intersect point and polygon layers to get an intersected polygon attribute and populate a point attribute

950
4
12-21-2023 04:54 AM
JoséMartinho
Emerging Contributor

In ArcGIS Pro, I have a map with a polygon layer, called Cont_Freg_CAOP2022, which has a text-type attribute, 6 characters long, called DICOFRE (e.g. "010121").
In addition to this, I have another layer of points, called Arvores_PGIFU, which has a text attribute, also called Dicofre.
I want to intersect the point layer with the polygon layer, return the value of the DICOFRE attribute of the intersected polygon and write this value in the point Dicofre field.
To do this, I created the expression:

// Determines the DICOFRE attribute of the Cont_Freg_CAOP2022 layer
// identified by the intersection with a point in the Arvores_PGIFU layer

var Dicofre_Fregs = FeatureSetByName($map, 'Cont_Freg_CAOP2022', ['DICOFRE'])

// Intersect the current location with the polygons and return the dicofre

var Dicofre_Int = First(Intersects($feature, Dicofre_Fregs))

// If the current location intersects a polygon, return DICOFRE, otherwise return null.

if (!IsEmpty(Dicofre_Int)) {
return Dicofre_Int['DICOFRE']
} else {
return null
}

When checking the expression I get the error message:

Invalid expression.
Error on line 4.
Object not found $map

Any help?

Captura de Ecrã (96).png

 

0 Kudos
4 Replies
BobBooth1
Esri Contributor

Might be simpler to split it into a couple steps.

Try spatial join to get the polygon layer attributes on the points

https://pro.arcgis.com/en/pro-app/latest/tool-reference/analysis/spatial-join.htm

and then use the field calculator to update the values on the target field.

JoséMartinho
Emerging Contributor

Dear Friend
Thank you for your contribution.
Doing it manually is no problem. The aim is to do it automatically by applying a rule to the attribute.
Any ideas on how to resolve the error?
Best regards

0 Kudos
BobBooth1
Esri Contributor

Ah, I did not see that you wanted to do this with attribute rules.

This thread seems to show something like what you want:

https://community.esri.com/t5/arcgis-pro-questions/attribute-rule-drilldown-other-layers/td-p/107224...

0 Kudos
JoséMartinho
Emerging Contributor

Thank you!

Continues to generate an error, this time:

// Determines the DICOFRE attribute of the Cont_Freg_CAOP2022 layer
// identified by the intersection with a point in the Arvores_PGIFU layer

var Dicofre_Fregs = FeatureClassByName($map, 'Cont_Freg_CAOP2022', ['DICOFRE'])

// Intersect the current location with the polygons and return the dicofre

var Dicofre_Int = First(Intersects($feature, Dicofre_Fregs))

// If the current location intersects a polygon, return DICOFRE, otherwise return null.

if (!IsEmpty(Dicofre_Int)) {
return Dicofre_Int['DICOFRE']
} else {
return null
}


Invalid expression.
Error on line 4.
Unknown function

0 Kudos