Select to view content in your preferred language

Create duplicate polygons using Shape@ and Geometry objects in 10.1

634
1
03-18-2013 02:12 PM
DustinEdge
Deactivated User
Greetings All

I have a shapefile with 1 polygon in it. I want my script to read the geometry of the polygon and then create multiple polygons in the same file from the original polygon.

I can do this using Describe, ShapeFieldName & a polygon array. But I noticed new python functionality using Shape@WKT and FromWKT

The help section is truly lacking (even by ESRI standards) and I was wondering if anyone can help me join the dots.

It looks like you can use "Shape@WKT" to extract the polygon geometry and put it into a Geometry object, like so:

infc = "D:\\DDP_extent.shp"
infcFields = ["SHAPE@WKT"]

g = arcpy.Geometry()
gList = arcpy.CopyFeatures_management(infc, g)


The writing geometries help section only uses arrays as the input method, but surely I could use FromWkt to create a new geometry object for the InsertCursor?

Am I reading it right? or are arrays the only way to go?

Thanks in advance
Tags (2)
0 Kudos
1 Reply
DustinEdge
Deactivated User
ANSWER FOUND

(I cant believe it was this simple....as the ESRI help was not helpful at all)

infc = arcpy.GetParameterAsText(0)
repnum = arcpy.GetParameterAsText(1)

gRows = arcpy.da.SearchCursor(infc, "Shape@")
for row in gRows:
    origpoly = row
del gRows

aRows = arcpy.da.InsertCursor(infc, "Shape@")

for x in xrange(0, int(repnum)):
    aRows.insertRow(origpoly)
del aRows
0 Kudos