1

I'm trying to use ArcPy to copy only the geometry from one feature class to another based on a certain condition. Here is my code so far:

source_fields = ['contition_field', 'SHAPE@']

icursor = arcpy.da.InsertCursor(target_fc, 'SHAPE@')

with arcpy.da.SearchCursor(source_fc, source_fields) as scursor:

    for row in scursor:
        if row[0] == 'condition1':
            icursor.insertRow(row[1])

When I try to run it, I get this:

TypeError                                 Traceback (most recent call last)
<ipython-input-14-bc6790d82eb2> in <module>
      6     for row in scursor:
      7         if row[0] == 'condition1':
----> 8             icursor.insertRow(row[1])
      9 
     10 

TypeError: cannot read geometry sequence. expected list of floats

I tried doing a few searches on this error, but it seems like most people don't have a problem with copying geometry, they have problem with copying other fields. However nothing seems to allow me to copy the feature geometry (like in this thread):

Insert Geometry and update attribute using arcpy.da.InsertCursor

What is wrong?

3
  • 1
    Are the input and output layers the same geometry type and coordinate system?
    – Hornbydd
    Nov 15, 2022 at 21:06
  • 4
    insertRow() expects a sequence of values but you're passing in a single geometry object, try passing in a single-item list: icursor.insertRow([row[1]])
    – mikewatt
    Nov 15, 2022 at 21:50
  • Thank you very much @mikewatt, that worked!
    – a_uly0003
    Nov 17, 2022 at 0:44

1 Answer 1

0

Change icursor.insertRow(row[1]) to icursor.insertRow([row[1]])

1
  • This could be improved by explaining why it's the correct answer, and why the former value failed the way it did (Hint: a Geometry has an iterator that generates Point objects)
    – Vince
    Nov 17, 2022 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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