I am trying to convert a ploy line feature class to polygon without using Arc info Advanced Licence.The code i am using runs fine and converts polyline to polygon. I have run the "tool feature to polygon" to make a comparison.My code is not converting all lines to polygon(See Screenshot).I have also attached my code.please guide me to get the same results.
Polyline :Red(to be converted)
Mycode:Brown
Feature to polygon: Blue
import arcpy
import arcpy
import os
from arcpy import env
env.overwriteOutput = True
starttime = time.time()
localtime = time.asctime( time.localtime(time.time()) )
# Create a value table that will hold the input feature classes for Merge
mxd=arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "")[0]
for lyr in arcpy.mapping.ListLayers(mxd,"",df):
if not lyr.isGroupLayer:
arcpy.AddMessage(lyr.name)
if "Export" in lyr.name :
break
desc = arcpy.Describe(lyr)
shapefieldname = desc.ShapeFieldName
outPolys=r'C:\RAECGIStoCAD\test.gdb\temp'
arcpy.DeleteFeatures_management(r'C:\RAECGIStoCAD\test.gdb\temp')
joinoutput=r'C:\RAECGIStoCAD\test.gdb\join'
spatialRef = arcpy.Describe(lyr).spatialReference
featureList = []
#array = arcpy.Array()
cursor = arcpy.da.InsertCursor(outPolys, ['SHAPE@'])
rows = arcpy.SearchCursor(lyr)
for row in rows:
# Create the geometry object
feat = row.getValue(shapefieldname)
#print "Feature %i: " % row.getValue(desc.OIDFieldName)
partnum = 0
part_list = []
# Step through each part of the feature
for part in feat:
polygonArray = arcpy.Array()
for pnt in feat.getPart(partnum):
if pnt:
# Add to list
part_list.append([pnt.X, pnt.Y])
polygonArray.add(arcpy.Point(pnt.X,pnt.Y))
partnum += 1
print partnum
print part_list
polygon = arcpy.Polygon(polygonArray)
featureList.append(polygon)
cursor.insertRow([polygon])
del cursor
endtime = time.time()
totaltime = endtime-starttime
print "\nScript took " + str(totaltime/60) + " minutes to run"
Dear Luke,
Actually my client dont have advanced license.yes i was storing only vertices coordinates and drawing a new polygon. Is it possible to construct polygon using python script? any suggestion
I am unable to come up with a decent algorithym.... and I love a challenge!
I feel ESRI have constructed a decent tool, and knowing this, put it behind an advanced license for 'commercial' reasons I would advise looking at the open source tools provided in our other threads, as this is a not a simple task to accomplish.
Unless you have any good ideas of how the algorithm should work I could try to implement