Not sure how best to word this. I am looking for arcpy solutions/ideas on connecting the endpoints of stacked polyine features together in order to build it into a polygon feature class.
This task done manually is quite simple: just add a new polyline(s) from one start point to the startpoint of the polyline below it and continue this until an entire "side" of the stacked polylines are connected. Then it's just a matter of doing this same thing to the other "side" on the endpoints of each polyline feature. See:
Solved! Go to Solution.
Thanks but I really am unintersted in model builder and need to implement this into a Python Add-In. Here's what I came up with that works just fine:
ptarrL = arcpy.Array() ptarrR = arcpy.Array() for l in listoflayers: for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == str(l): print "layer: " + str(lyr.name) with arcpy.da.SearchCursor(lyr, ["SHAPE@"]) as lyrCur: for row in lyrCur: xL, yL = row[0].firstPoint.X, row[0].firstPoint.Y xR, yR = row[0].lastPoint.X, row[0].lastPoint.Y ptarrL.add(arcpy.Point(xL, yL)) ptarrR.add(arcpy.Point(xR, yR)) with arcpy.da.InsertCursor(lyr, ["SHAPE@"]) as inscur: polyline = arcpy.Polyline(ptarrL) inscur.insertRow([polyline]) with arcpy.da.InsertCursor(lyr, ["SHAPE@"]) as inscur: polyline = arcpy.Polyline(ptarrR) inscur.insertRow([polyline]) del inscur, lyrCur
So in your example you are trying to create that green polyline, in this case it is compose of only 3 vertices?
OK several questions:
Yes, I would like to create the green line you see between each feature.
1. Yes, always stacked one above the other.
2. Doesn't matter really. The next step would simply run this polyline FC thru a ToPolygon conversion.
3. Each "set" of polylines is a single feature class. The 3 polylines you see in the image is 1 FC.
Thanks!
This can be done with a very simple model (if you have the Advanced license, which you do not state). The model is shown below with the final result (green polyline)
The only assumption is that the order of the polylines in the shapefile dictates the order of the extracted nodes which is the order the vertices are in your green line.
Thanks but I really am unintersted in model builder and need to implement this into a Python Add-In. Here's what I came up with that works just fine:
ptarrL = arcpy.Array() ptarrR = arcpy.Array() for l in listoflayers: for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == str(l): print "layer: " + str(lyr.name) with arcpy.da.SearchCursor(lyr, ["SHAPE@"]) as lyrCur: for row in lyrCur: xL, yL = row[0].firstPoint.X, row[0].firstPoint.Y xR, yR = row[0].lastPoint.X, row[0].lastPoint.Y ptarrL.add(arcpy.Point(xL, yL)) ptarrR.add(arcpy.Point(xR, yR)) with arcpy.da.InsertCursor(lyr, ["SHAPE@"]) as inscur: polyline = arcpy.Polyline(ptarrL) inscur.insertRow([polyline]) with arcpy.da.InsertCursor(lyr, ["SHAPE@"]) as inscur: polyline = arcpy.Polyline(ptarrR) inscur.insertRow([polyline]) del inscur, lyrCur