3

I have a python code that is generating coordinates one by one. Is there a way to display them directly in ArcMap as they are generated? I am aware of the insert cursor but the lock on the table prevents python from writing into it.

Ok, now that I used the Python window in ArcMap new error has occured. Could it be because the "czk" is a list?

Here is the code:

czk=[413960.0, 47130.0]
cursor = arcpy.da.InsertCursor("C:/GIS/AlJeba/Tocke/Tocke.shp", ("SHAPE@XY"))
for row in czk:
    cursor.insertRow(row)
del cursor

And here is the error:

Runtime error Traceback (most recent call last): File "", line 333, in TypeError: argument must be sequence of values

5
  • 1
    Is this a stand-alone python script, or with arcpy run within Arcmap?
    – Martin
    Commented Aug 4, 2014 at 11:46
  • If by run in ArcMap you mean using Python window in program then no. I'm running the script in the Python Shell using IDLE.
    – Alešinar
    Commented Aug 4, 2014 at 12:02
  • 2
    Why is the insert cursor not working. Is this layer being edited by another user? Can you post your code?
    – artwork21
    Commented Aug 4, 2014 at 12:03
  • Would you be able to edit your question to revise it with any requested clarifications, please?
    – PolyGeo
    Commented Aug 4, 2014 at 12:19
  • Can you include the czk list in your code?
    – artwork21
    Commented Aug 4, 2014 at 15:11

3 Answers 3

7

The problem is that you are passing in Shape@XY as the argument for the field names. This expects a tuple of the feature's centroid x,y coordinates to be passed in when you use the insert cursor ( see http://resources.arcgis.com/en/help/main/10.1/index.html#//018w0000000t000000)

However, czk=[413960.0, 47130.0] is a list containing two floating point numbers. When you say:

    for row in czk:
        cursor.insertRow(row)

You are only passing a single floating point number in when it expects a tuple with two items in it (one x and one y coordinate).

If 413960.0, 47130.0 is your x,y pair then you need to change your code to something like this:

    czk=(413960.0, 47130.0)
    cursor = arcpy.da.InsertCursor("C:/GIS/AlJeba/Tocke/Tocke.shp", ("SHAPE@XY"))
    cursor.insertRow(czk)
    del cursor
1
  • A yes now I completely understand. The cursor was trying to insert x into first row and y in the second. Thank you for explanation
    – Alešinar
    Commented Aug 4, 2014 at 16:29
4

Try this:

czk = [(413960.0, 47130.0)]
cursor = arcpy.da.InsertCursor("C:/GIS/AlJeba/Tocke/Tocke.shp", ("SHAPE@XY"))
for row in czk:
    cursor.insertRow(row)

del cursor
0

It looks like you are trying to attempt the code in the second example on this help page? Is your czk list in the same structure as the example, also note that you are using () instead of [] around you field list when you create the cursor.

I think this is just a case of you stopping and reading the help file to make sure you are writing your code carefully?

4
  • I don't know. I read the entire page but in the end I had to convert czk to tuple and append it to new empty list. Well now it works, thank you. However I thought that ArcMap will be adding points to the map as they are created and inserted to the table one by one. Is this even possible?
    – Alešinar
    Commented Aug 4, 2014 at 15:13
  • Also had to delete parentheses around "SHAPE@XY".
    – Alešinar
    Commented Aug 4, 2014 at 15:21
  • I don't think that happens nor would you want it. The whole map display would keep refreshing which is a time consuming process. So insert the points then refresh the map display.
    – Hornbydd
    Commented Aug 4, 2014 at 15:23
  • So you think this is not a good idea? I thought it would be nice for a presentation to see how script actually works.
    – Alešinar
    Commented Aug 4, 2014 at 15:30

Your Answer

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

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