Select to view content in your preferred language

Get polygon vertexes for attribute rules

639
1
Jump to solution
06-07-2022 06:37 AM
mody_buchbinder
Frequent Contributor

I would like to do some checks on a new created polygon using attribute rules.

For example count the vertexes or check if they exists as points in a different layer.

I could not find a way to do it.

Possible way is to convert the feature geometry to JSON.

I found FromJSON but not ToJSON. There are many functions to translate from JSON to feature but not the other way around.

Is there any way to do it?

Thanks  

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Documentation for polygons and polylines: Type System | ArcGIS Arcade | ArcGIS Developer

Polygons have a rings attribute, polylines have a paths attribute. These are three-dimensional lists of numbers, representing point coordinates of multiple line segments / rings.

 

 

// get the number of vertices in a polygon
var rings = Geometry($feature).rings
var vertex_count = 0
for(var i in rings) {
    vertex_count += Count(rings[i])
    // for polygons, the first and last point of a ring are the same, so we have to subract 1
    vertex_count -= 1
}
return vertex_count

 

 

 

// get number of points on vertices
var rings = Geometry($feature).rings
var point_fc = FeatureSetByName($datastore, "TestPoints", ["OBJECTID"], true)
var points_on_vertices = 0
for(var i in rings) {
    for(var j in rings[i]) {
        var vertex = rings[i][j]
        points_on_vertices += Count(Intersects(vertex, point_fc))
    }
}
return points_on_vertices

 


Have a great day!
Johannes

View solution in original post

0 Kudos
1 Reply
JohannesLindner
MVP Frequent Contributor

Documentation for polygons and polylines: Type System | ArcGIS Arcade | ArcGIS Developer

Polygons have a rings attribute, polylines have a paths attribute. These are three-dimensional lists of numbers, representing point coordinates of multiple line segments / rings.

 

 

// get the number of vertices in a polygon
var rings = Geometry($feature).rings
var vertex_count = 0
for(var i in rings) {
    vertex_count += Count(rings[i])
    // for polygons, the first and last point of a ring are the same, so we have to subract 1
    vertex_count -= 1
}
return vertex_count

 

 

 

// get number of points on vertices
var rings = Geometry($feature).rings
var point_fc = FeatureSetByName($datastore, "TestPoints", ["OBJECTID"], true)
var points_on_vertices = 0
for(var i in rings) {
    for(var j in rings[i]) {
        var vertex = rings[i][j]
        points_on_vertices += Count(Intersects(vertex, point_fc))
    }
}
return points_on_vertices

 


Have a great day!
Johannes
0 Kudos