Select to view content in your preferred language

access geom obj in arcpy.da.SearchCursor with "*" field param

1273
2
Jump to solution
02-12-2013 12:14 PM
JamieKass
Regular Contributor
Although I appreciate the new accessibility of fields and field methods in the da cursors in 10.1 via geometry tokens, I can't figure out how to access the geometry object when I use "*" (all) for my fields parameter. If I find the index of "Shape" and then call row[index[shapeIndex]], I get a tuple of coordinates, not the geometry object. It seems only accessible via the token "SHAPE@". I need to use the "*" field parameter because I am inserting new rows into a blank fc after reading rows from an existing with SearchCursor based on these fields, but also need to access the geometry object as input for a different function that spits out new geometry. Here is the old code below. What is the new way to write this? Thanks.

def segmentLine(ref,fc,pSegDist):     irows = arcpy.InsertCursor(fc)     fields = arcpy.ListFields(ref)      rows = arcpy.SearchCursor(ref)     for row in rows:         feat = row.shape         if feat.length > pSegDist:             shapeList = segLineShapeList(feat,pSegDist)              for pt in shapeList:                 newRow = irows.newRow()                 for f in fields:                     if f.editable:                         newRow.setValue(f.name,row.getValue(f.name))                 newRow.shape = pt                 irows.insertRow(newRow)         else:             irows.insertRow(row)     del rows,irows
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChrisFox3
Frequent Contributor
You can just use the following code:

rows = arcpy.da.SearchCursor(fc, ("SHAPE@", "*"))


This will return a tuple where the first item is the geometry followed by all the fields from the feature class. It will still contain tuple of coordinates like you saw before, but you can just ignore this. We did this because returning the full geometry is slower than just the coordinates of the centroid.

View solution in original post

0 Kudos
2 Replies
ChrisFox3
Frequent Contributor
You can just use the following code:

rows = arcpy.da.SearchCursor(fc, ("SHAPE@", "*"))


This will return a tuple where the first item is the geometry followed by all the fields from the feature class. It will still contain tuple of coordinates like you saw before, but you can just ignore this. We did this because returning the full geometry is slower than just the coordinates of the centroid.
0 Kudos
JamieKass
Regular Contributor
Thanks, that makes everything clear.
0 Kudos