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.
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
}]
}]
}