Attribute rule to create polygon feature from line features.

796
4
03-23-2023 04:13 PM
Labels (3)
katherinealexander_USGS
New Contributor II

Hello, 

I am hoping someone might be able to help me with writing an attribute rule that will generate polygons in a feature class triggered by the creation of lines that form closed areas in another feature class. 

I imagine this rule would work by looking at whether the line created closes a shape (based on some topology) and if 'yes' then a polygon is created if 'no' then a polygon is not created.

This rule would be a huge help for those of us creating maps that would like to see what our maps are looking like in real time rather than having to run the features to polygons tool over and over.

There would need to be some other attributes for the polygons, but I thought I'd start with generating a polygon first. 

Thanks so much for any help you might provide.

@ Hussein Nasser

@Xander Bakker

 

0 Kudos
4 Replies
JohannesLindner
MVP Frequent Contributor

You could do something like this:

 

// Calculation Attribute Rule on the Line fc
// field: leave empy
// triggers: insert
// exclude from application evaluation

// get the vertices
var vertices = Geometry($feature).paths[0]

// if first vertex isn't the same as last vertex, abort
var same = vertices[0].x == vertices[-1].x && vertices[0].y == vertices[-1].y
if(!same) { return }

// create the polygon
var sr = Geometry($feature).spatialReference
var poly_vertices = []
for(var v in vertices) {
    var vertex = [vertices[v].x, vertices[v].y]
    Push(poly_vertices, vertex)
}
var poly = Polygon({rings: [poly_vertices], spatialReference: sr})

// insert the polygon into the polygon fc
return {
    edit: [{
        className: "NameOfYourPolygonFC",
        adds: [{
            geometry: poly,
            attributes: {} // you can add attributes here
        }]
    }]
}

Have a great day!
Johannes
KristjanHlynurIngolfsson
New Contributor II

Hey @JohannesLindner and thanks for a great solution.

I have a similar problem, being that I need polygons to be created automatically in one feature when a point is created in another one, the polygons being a buffer for the point set to a default radius.

So to sum up, a point is created in a feature and automatically a polygon (buffer) is added in another polygon feature (with the respective point being the polygon/buffer center).

Any tips on how such a attribute rule might look like?

With regards, Hlynur.

0 Kudos
JohannesLindner
MVP Frequent Contributor

Hey Hlynur,

 

this scenario is described in this blog: https://www.esri.com/arcgis-blog/products/arcgis-pro/data-management/advanced-gdb-attribute-rules-ed...

 


Have a great day!
Johannes
0 Kudos
KristjanHlynurIngolfsson
New Contributor II

Great! Thanks @JohannesLindner and happy 2024 to all!

0 Kudos