Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
1  
Is this a stand-alone python script, or with arcpy run within Arcmap? –  Martin Aug 4 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 Aug 4 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 Aug 4 at 12:03
    
Would you be able to edit your question to revise it with any requested clarifications, please? –  PolyGeo Aug 4 at 12:19
    
Can you include the czk list in your code? –  artwork21 Aug 4 at 15:11

3 Answers 3

up vote 2 down vote accepted

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(czk)

del cursor
share|improve this answer

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
share|improve this answer
    
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 Aug 4 at 16:29
    
This answer is certainly better than the accepted one. –  nmpeterson Aug 4 at 17:19

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?

share|improve this answer
    
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 Aug 4 at 15:13
    
Also had to delete parentheses around "SHAPE@XY". –  Alešinar Aug 4 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 Aug 4 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 Aug 4 at 15:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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