1

I imported a shapefile into a feature class using arcpy.CopyFeatures_management(). It works and when I look at the feature class in ArcMap and TOAD, I see all the data and the SHAPE field is populated with the data I expect to see (min/max values, a blob for the points, etc.). I can drag the feature class on the map and the entities appear where they should. Life is good!

When I try to copy the contents of the SHAPE field from the feature class, the resulting SHAPE field is a tuple containing only two properties that appears to be a single point of the shape (not min or max values but somewhere in the middle).

The issue seems to be the arcpy.da.searchcursor doesn't return the entire shape. If I enumerate the results of the searchCursor, all the SHAPE fields are a single tuple with what appears to be an X and Y value.

The question, how do I copy rows from a feature class and get the entire SHAPE field?

update 2:

I had a thought this might be resource or size related so I scaled back everything, including the fields returned and the number of rows returned. Even when returning only the SHAPE field and a few records, a single coordinate is returned.

with arcpy.da.SearchCursor("XXX", "SHAPE") as tmpSC:

update 1:

I was able to confirm the searchCursor is only returning a single point out of the entire SHAPE field using the following code. The database contains all the information from the shapefile but the searchCursor doesn't return everything. So, what is the fix?

arcpy.env.workspace = "XXX.sde"

retVal = []

with arcpy.da.SearchCursor("XXX", "*") as tmpSC:
    for row in tmpSC:
        retVal.append(row)

print "Stop! Inspect the results... "
  • What is the geometry type of the features you are reading? (point/line/polygon) – Mintx Apr 1 '15 at 22:02
  • The geometry type is polygon. – DenaliHardtail Apr 1 '15 at 22:06
5

Use 'SHAPE@' anytime you want to get the geometry object. Using 'SHAPE' (and this is what '*' uses) will return a tuple of the x,y coordinates of the centroid.

I generally recommend against getting all fields with '*'. But if you must, get the field names with arcpy.ListFields (or arcpy.Describe) and swap in the 'SHAPE@' token.

fields = ['SHAPE@' if f.type == 'Geometry' else f.name for f in arcpy.ListFields(fc)]
with arcpy.da.SearchCursor(fc, fields) as tmpSC:
    for row in tmpSC:
        retVal.append(row)
1

I think you're only pulling out the centroid XY with SHAPE and with *. Try using this:

with arcpy.da.SearchCursor("XXX", "SHAPE@") as tmpSC:

The result from SHAPE@ should be a complete geometry object. You can also toggle the explode_to_points option in your search cursor if you would rather iterate over each vertex XY; see the help doc here: http://resources.arcgis.com/en/help/main/10.1/index.html#//018w00000011000000

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.