3

I am struggling with a very simple task of inserting "SHAPE@XY" into a point feature class. Following is what I have:

xy = [(361087.15436001675, 198747.07296730898), (361530.56426259346, 198976.62248019245),
      (361692.3015462744, 197815.78617074457), (361845.0959187896, 198297.07296730898),
      (362135.3345548634, 197552.7531621556)]

fc = "C:/temp/xy.shp"
cursor = arcpy.da.InsertCursor(fc, ["SHAPE@XY"])
for row in xy:
    cursor.insertRow(row)

del cursor

it throws back error:

TypeError: sequence size must match size of the row

I used field calculator to add x and y field into the same shapefile form where I retrieved these points, and it works fine to add above set of co-ordinates to a multiline feature class, but above set of lines fail. Any suggestions?

3
  • 5
    Try cursor.insertRow([row]) instead Jan 17 '14 at 4:50
  • great! it worked.
    – Ibe
    Jan 17 '14 at 4:55
  • it returns with; AttributeError: 'arcpy.da.SearchCursor' object has no attribute 'insertCursor'
    – mertmcd
    Dec 30 '16 at 6:17
2

I found this article on ESRI an support page.

You've got a syntax error in your definition of xy. According to the website,

To be properly recognized, a single value tuple should be written with a trailing comma.

Try the following:

xy = [((361087.15436001675, 198747.07296730898),), ((361530.56426259346, 198976.62248019245),), ((361692.3015462744, 197815.78617074457),), ((361845.0959187896, 198297.07296730898),), ((362135.3345548634, 197552.7531621556),)]

The rest of your code should work fine.

It's kind of a pain, but it worked for me.

enter image description here

1
  • I haven't tried it yet but will give it a shot later. Above one liner provided by @Jason worked.
    – Ibe
    Jan 17 '14 at 4:56

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.