[GIS] SearchCursor doesn’t return entire SHAPE field, how to copy a row containing a SHAPE field

arcgis-10.1arcpy

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... "

Best Answer

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)