1

I am creating a list of tuples of coordinates of a feature class.

Feature class is created as such:

inFC = arcpy.GetParameterAsText(0)

The inFC is a point feature class.

I then have the following code to get the coordinates of all points in the feature class:

field = ['SHAPE@XY']
coordsList = []
with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:
        coordsList.append(row)

I was expecting an output of a list of tuples as below;

[(250000, 230000), (234567, 2859340)...]

However instead I am getting a list of tuples of a tuple and a commma, as below:

[((251075.0, 237048.0),), ((250687.0, 236717.0),),...]

What is the error in my code or my approach?

1
  • 1
    What is the length of "row"? Have you tried coordsList.append(row[0])?
    – Vince
    Jan 14, 2016 at 17:18

1 Answer 1

5

This is expected behavior. Each row is returned as a tuple of field values, as stated in the help docs. When you use the SHAPE@XY, it returns a tuple of the coordinates. If you only have one field and want to make a list of your xy tuples, As Vince mentioned you'll have to get by index:

with arcpy.da.SearchCursor(fc, ['SHAPE@XY']) as rows:
    coordList = [r[0] for r in rows]

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.