This to me sounded very simple so I am probably missing something basic here. What I need to do is to create a copy of a polygon shapefile to a new shapefile with slightly different attributes.
Where I got stuck is in copying the geometry - Geometry doesn't have to change at all in the new shapefile. The actual 'copying' of the polygon geometry is not the problem. I loop through the input shapefile:
> for row in rows: > partnum = 0 > feat=row.getValue("SHAPE")
And then I enter this shape in the output feature class:
Problem is, I also want to calculate the Area, Perimeter and centroid of the polygon and I can't seem to 'cast' the feat variable to a polygon so I can then get the polygon properties (area, centroid, etc). Can you do that somehow?
One of the things I tried was to create the polygon from scratch, i.e. loop though the vertices of the input polygon and create a new polygon/array to use for the new polygon. This method apart from being IMO over the top, it also had the problems with the multi-part polygons. My polygons ended up corrupted - although I followed the steps outlined here
I didn't dwell too much with it since what I did instead is create a dummy Polygon which I then passed to it the current geometry value in the cursor.
# Create a dummy polygon dummyArray=arcpy.Array() dummyPoint = arcpy.Point() coordList = [[[1,2], [2,4], [3,7]],[[6,8], [5,7], [7,2], [9,5]]] for feature in coordList: for coordPair in feature: dummyPoint.X = coordPair dummyPoint.Y = coordPair dummyArray.add(dummyPoint) dummyArray.add(dummyArray.getObject(0)) parcel=arcpy.Polygon(dummyArray) parcel=feat ### --> This is where I replace the dummy geometry value with the current value in the loop parcel_c=arcpy.Point() parcel_c=parcel.centroid # I can now get to the polygon properties c_x=parcel_c.X c_y=parcel_c.Y
Although this works fine, I am not really happy with it as its a bit of a hacking and -as mentioned in the beginning- I think I am missing something vital!