Hello all, I am still learning and now cant find the solution. So, I have points and polygons, polygons have names. I need to select points which are inside polygon and give the same name as polygon. So, should be all points with specific names like polygon in which they are. Spatial join not suitable for me because it creates output and I need to work with the same feature class, just to edit it.
Any ideas?
Thanks!
Solved! Go to Solution.
Arcade, the script language developed by ESRI for the ArcGIS infrastructure, is perfect for that.
Use the Calculate Field tool on the point feature class, change the language to Arcade. Use this expression, edit the polygon feature class's name (first line) and the name field (last line):
// load the polygons
var polygons = FeaturesetByName($datastore, "PolygonFeatureclass")
// get the polygon that intersects the current point
var i_polygon = First(Intersects(polygons, $feature))
// return a default value if no polygon is intersecting
if(i_polygon == null) { return null }
// return the name of the Polygon
return i_polygon.Name
Arcade, the script language developed by ESRI for the ArcGIS infrastructure, is perfect for that.
Use the Calculate Field tool on the point feature class, change the language to Arcade. Use this expression, edit the polygon feature class's name (first line) and the name field (last line):
// load the polygons
var polygons = FeaturesetByName($datastore, "PolygonFeatureclass")
// get the polygon that intersects the current point
var i_polygon = First(Intersects(polygons, $feature))
// return a default value if no polygon is intersecting
if(i_polygon == null) { return null }
// return the name of the Polygon
return i_polygon.Name
Thank you, thats worked! I will try to combine it with iterator and model builder because have 2 polygon layers and more than 10 point layers
Cheers!
If you modify the rule, you can make it so that if it doesn't find an intersecting polygon in the first FC, it tries the second Polygon FC:
// load the polygons
var polygons = FeaturesetByName($datastore, "PolygonFeatureclass")
// get the polygon that intersects the current point
var i_polygon = First(Intersects(polygons, $feature))
// if no polygon is intersecting, try the second polygon fc
if(i_polygon == null) {
var polygons = FeaturesetByName($datastore, "PolygonFeatureclass_2")
var i_polygon = First(Intersects(polygons, $feature))
// if there is no0 intersecting polygon here, too, return null
if(i_polygon == null) { return null }
}
// return the name of the Polygon
return i_polygon.Name
Is that what you're trying to do?
Also, if this is a task you have to do often, you might want to consider making this expression into an Attribute Rule for each of the point fcs. Attribute Rules can be executed when a feature is inserted or edited. This way, the name would be updated automatically every time you edit a point.
I will check that might use it in the future. For now it's one time job because points do not changes often. I got 2 new fields in point layers in which I will put 2 polygon layers names for all point layers is the same.
Thanks again!
Great, glad I could help. Please mark my answer as solution, so that this question is shown as solved.
One more question, if I have point intersecting 2 polygons I want to return both (or more) values in one field. How should i do? Something like merge rule Join with delimiter
// load the polygons
var polygons = FeaturesetByName($datastore, "PolygonFeatureclass")
// get all intersecting polygons (instead of the first one)
polygons = Intersects(polygons, $feature)
// loop through the intersecting polygons and extract the names into an array
var names = []
for(var poly in polygons) {
Push(names, poly.Name)
}
// concatenate and return
return Concatenate(names, ", ")
I'm missing something here (but I've ordered an Arcade book).
I have a polygon layer containing 8 polygons and a points layer containing 67,000 locations. I'd like to create a field that uses an approach like this to assigns each point to a polygon based on its location - so that the field being calculated gets the appropriate polygon name.
When I use the above expression every data point gets the same polygon name regardless of its location.
Thanks for any help you can offer - I'm new to using Arcade.
Mark
Clearly - I'm not getting something... can you help?