Select to view content in your preferred language

Centroid and beginning/ending vertices (nodes) with Arcade (and other questions)

1147
2
Jump to solution
02-02-2022 03:24 PM
ToddFagin
Frequent Contributor

Greetings Attribute Rules community.

Though a long-time GIS user, I am new to both Attribute Rules and Arcade.

I have what I believe to be a fairly simply problem and hope someone can help.

I have a colleague who would like me to develop a field map for her that includes a linear feature called transects. She then needs to derive the starting vertex X,Y, centroid X,Y, and ending vertex X,Y of the newly created feature. I figured that an attribute rule that automatically calculates it would be great.

The centroid rule seemed pretty easy--Round(Centroid($feature).X, 6) and Round(Centroid($feature).Y, 6) to calculate the X and Y centroids, respectively. Hurray. Well, no.

It works, but it appears to be calculating the centroid for the boundary geometry of the feature rather than the actual centroid of the linear feature (i.e. actually a point ON the line). Suggestions?

As for the beginning and ending vertices X,Y, I am at a loss. I can use something like Round(Geometry($feature).Y, 6) to find the coordinate of a point, but how can I implement this for a vertex in a line or polygon?

Lastly, and this is more philosophical, I suppose. Is there a way to calculate a spatial relationship with Arcade? (Again, being new to this, this may be a no brainer). For instance, if I plot a point that is within the geometry of a polygon, I would like to do some equivalent of a spatial join to assign the point attribute(s) from the polygon.

Thanks in advance.

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

It works, but it appears to be calculating the centroid for the boundary geometry of the feature rather than the actual centroid of the linear feature (i.e. actually a point ON the line). Suggestions?

Hmmm. I believe snapping the "false" centroid to the closest line segment would not yield the "correct" centroid, right?

As for the beginning and ending vertices X,Y, I am at a loss

// the geometry of line features has a "paths" attribute, which is a list of
// lists of points (multiple line segments)
// for polygons, the attribute is named "rings".
var first_point = Geometry($feature).paths[0][0]
var last_point = Geometry($feature).paths[-1][-1]

 

Is there a way to calculate a spatial relationship with Arcade? (Again, being new to this, this may be a no brainer). For instance, if I plot a point that is within the geometry of a polygon, I would like to do some equivalent of a spatial join to assign the point attribute(s) from the polygon.

// load the polygons using one of the FeatureSetBy* functions
var fs_polygons = FeatureSetByName($datastore, "PolygonFC")
// find polygons intersecting the $feature
var intersecting_polygons = Intersects(fs_polygons, $feature)
// no polygons found -> return early
if(Count(intersecting_polygons) == 0) { return null }
// intersecting_polygons is a feature set, we want to access the attributes 
// of polygon features, so we have to extract one of them. 
// easiest, but not always appropriate, way is to just grab the first one.
var polygon = First(polygons)
// return some attribute
return polygon.Attribute

 

If you didn't know yet, the Arcade functions and classes are pretty well documented:

Arcade functions:
Function Reference | ArcGIS Arcade | ArcGIS Developer

Arcade classes:
Type System | ArcGIS Arcade | ArcGIS Developer

 


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

It works, but it appears to be calculating the centroid for the boundary geometry of the feature rather than the actual centroid of the linear feature (i.e. actually a point ON the line). Suggestions?

Hmmm. I believe snapping the "false" centroid to the closest line segment would not yield the "correct" centroid, right?

As for the beginning and ending vertices X,Y, I am at a loss

// the geometry of line features has a "paths" attribute, which is a list of
// lists of points (multiple line segments)
// for polygons, the attribute is named "rings".
var first_point = Geometry($feature).paths[0][0]
var last_point = Geometry($feature).paths[-1][-1]

 

Is there a way to calculate a spatial relationship with Arcade? (Again, being new to this, this may be a no brainer). For instance, if I plot a point that is within the geometry of a polygon, I would like to do some equivalent of a spatial join to assign the point attribute(s) from the polygon.

// load the polygons using one of the FeatureSetBy* functions
var fs_polygons = FeatureSetByName($datastore, "PolygonFC")
// find polygons intersecting the $feature
var intersecting_polygons = Intersects(fs_polygons, $feature)
// no polygons found -> return early
if(Count(intersecting_polygons) == 0) { return null }
// intersecting_polygons is a feature set, we want to access the attributes 
// of polygon features, so we have to extract one of them. 
// easiest, but not always appropriate, way is to just grab the first one.
var polygon = First(polygons)
// return some attribute
return polygon.Attribute

 

If you didn't know yet, the Arcade functions and classes are pretty well documented:

Arcade functions:
Function Reference | ArcGIS Arcade | ArcGIS Developer

Arcade classes:
Type System | ArcGIS Arcade | ArcGIS Developer

 


Have a great day!
Johannes
ToddFagin
Frequent Contributor

I appreciate your assistance on this. I see I still have a lot to do to completely wrap my head around Attribute Rules and Arcade.

0 Kudos