OutCur = arcpy.InsertCursor(os.path.join(OutPath, OutPoly)) for k in PolyData: v = PolyDataarray = arcpy.Array() # print k, len(v) for xy in v: point = arcpy.Point() point.X = xy[0] point.Y = xy[1] array.add(point) FcPoly = OutCur.newRow() FcPoly.setValue("PMLNo", k) FcPoly.shape = array OutCur.insertRow(FcPoly) del OutCur
OutCur = arcpy.da.InsertCursor(os.path.join(OutPath, OutPoly + "2"), ["PMLNo", "SHAPE@"]) for k in PolyData: v = PolyDataarray = arcpy.Array() # print k, len(v) for xy in v: point = arcpy.Point() point.X = xy[0] point.Y = xy[1] array.add(point) polygon = arcpy.Polygon(array) data = [k, polygon] OutCur.insertRow(data) del OutCur
Solved! Go to Solution.
OutCur = arcpy.da.InsertCursor(os.path.join(OutPath, OutPoly + "2"), ["PMLNo", "SHAPE@"]) desc = arcpy.Describe(os.path.join(OutPath, OutPoly + "2")) sr = desc.spatialReference for k in PolyData: v = PolyDataarray = arcpy.Array() # print k, len(v) for xy in v: point = arcpy.Point() point.X = xy[0] point.Y = xy[1] array.add(point) polygon = arcpy.Polygon(array, sr) data = [k, polygon] OutCur.insertRow(data) del OutCur
OutCur = arcpy.da.InsertCursor(os.path.join(OutPath, OutPoly + "2"), ["PMLNo", "SHAPE@"]) desc = arcpy.Describe(os.path.join(OutPath, OutPoly + "2")) sr = desc.spatialReference for k in PolyData: v = PolyDataarray = arcpy.Array() # print k, len(v) for xy in v: point = arcpy.Point() point.X = xy[0] point.Y = xy[1] array.add(point) polygon = arcpy.Polygon(array, sr) data = [k, polygon] OutCur.insertRow(data) del OutCur
FcPoly.setValue("PMLNo", k) polygon = arcpy.Polygon(array) FcPoly.shape = polygon
Hi Chris,
I am creating geometries using the data access module similarly but I see strange performance.
The first time I created the tool from the script that reads xy from one shapefile and inserts to another. When tested with 2000 points it was completed a second. Then I started testing with other shapefiles and changed the geometry source from shapefile to Access database table. Now the tool takes 13 seconds with even lesser number of points. I retested with the original shapefile, still slow performance.
I am deleting the cursors at the end of the Execution. Is there anything else I need to clear ?
Appreciate your help!
Chris,
regardless of the slight difference in code, the "old" way has worked for ages.
The InsertCursor is pointing at a newly created Fc inside a Fd, so seems carry with it all those good things defined by the Fd.
These polygons are being created in a GCS and are quite small. About 800m by 300m in UTM projected space. Approx 0.007 of a degree and less. So, you were correct that some rounding / resolution issue was the problem with the da.InsertCursor way.
Its just that the da.InsertCursor isn't "aware" of the spatial resolution / crs of the feature it is inserting into. The old InsertCursor plainly was!
Cheers,
N
polygon = arcpy.Polygon(array)
FcPoly = OutCur.newRow() FcPoly.setValue("PMLNo", k) FcPoly.shape = array