Questions tagged [cursor]

Cursors are used by database programmers to process individual rows returned by database system queries.

Filter by
Sorted by
Tagged with
23
votes
3answers
5k views

Exporting table to XYZ ASCII file via ArcPy?

I'm looking for a way to export an ArcGIS table (created with the Sample tool) to a text file via ArcPy. I can do this in ArcGIS via the context menu by right-clicking the table, but have not found ...
18
votes
2answers
3k views

How is the data access cursor performance so enhanced compared to previous versions?

The data access module was introduced with ArcGIS version 10.1. ESRI describes the data access module as follows (source): The data access module, arcpy.da, is a Python module for working with ...
13
votes
5answers
1k views

Looping through 16 million records using ArcPy?

I have a table with 8 columns and ~16.7 million records. I need to run a set of if-else equations on the columns. I've written a script using UpdateCursor module, but after a few million records it ...
12
votes
3answers
695 views

Deleting cursor used in SearchCursor within dictionary comprehension?

If it is best to open cursors using a with statement to ensure it is deleted, like so: with arcpy.da.UpdateCursor(fc,fields) as cursor: Then, if a cursor is used as the iterable in a comprehension ...
12
votes
1answer
2k views

Fastest methods for modifying attribute tables with Python?

A while ago, I wrote a quick Python function for converting an attribute table to a python dictionary, where the key is taken from a user-specified unique ID field (typically the OID field). ...
11
votes
4answers
6k views

ArcGIS Python SearchCursor file locking?

I have a script that gets a value from a shapefile's field to return to the user. It seems that only when the arcpy.SearchCursor is called ArcMap 10.0 locks the file and it doesn't get removed ...
10
votes
6answers
13k views

Moving / offsetting point locations using ArcPy or ModelBuilder?

I have a number non-georeferenced CAD layers (see this question) that have text annotation features. I have created a model to convert the text to points, but after converting the annotation to a ...
10
votes
5answers
1k views

How to improve performance when using ArcGIS cursors in Python with big tables?

I have a pretty big point feature class in a file geodatabase (~4 000 000 records). This is a regular grid of points with a 100m resolution. I need to perform a kind of generalization on this layer. ...
9
votes
1answer
16k views

How to delete selected rows using ArcPy?

I want to delete all rows in a feature class but remain rows 1 to 5. In other hand I want to remain first five rows and delete others. I know that I have to use search cursor and update cursor but I ...
9
votes
2answers
7k views

Calculating Date Field with today's date from datetime.date.today()?

I'm working on part of tool that will use arcpy.CalculateField_management to add the current date to the attribut table. I've wandered far and wide on the interwebs and can't seem to find the ...
8
votes
5answers
847 views

How to access adjacent rows with cursor?

In the attached screenshot, the attributes contain two field of interest "a" and "b". I want to write a script to access the adjacent rows in order to make some calculations. To access a single row, ...
8
votes
1answer
1k views

Why del cursor/row objects of ArcPy?

Can someone help me understand what the last 2 lines of this code does: import arcpy arcpy.env.workspace = "c:/esripress/python/data/exercise07" arcpy.env.overwriteOutput = True copy = arcpy....
8
votes
3answers
6k views

Creating polygon feature class from X,Y coordinates using ArcPy?

I am trying to write a script that creates a new polygon feature class containing a single ( square ) polygon with the following coordinates: ( 0, 0 ), ( 0, 1,000 ), ( 1,000, 0 ), and ( 1,000, 1,000 )....
8
votes
3answers
5k views

Is it possible to sort an arcpy.da.UpdateCursor()?

I have an ArcPy Data Access update cursor that I would like to sort before making updates to it. The cursor makes updates if I don't sort, but if I add a sort to the cursor I get an error, "...
8
votes
2answers
3k views

Getting unique value of second field using arcpy.da.SearchCursor?

I have a feature class and using arcpy.da.SearchCursor I'm getting unique values of a field (e.g. Name). How can I use this method to get the associated row value of a different field (diff field = ...
8
votes
3answers
402 views

What technology is used behind ArcPy cursors?

I'm using ArcGIS Server 10.0. I have a geoprocessing using arcpy search, update and insert cursors. I'd like to know more about the technology behind these cursors. Does it use any driver or pool to ...
8
votes
2answers
7k views

Calculating XY coordinates in Decimal Degrees from projected dataset in model or script?

Is it possible to calculate points XY coordinates in Decimal Degrees in model or script when a feature class is in projected coordinate system? It's easy when a FC is in geographic coordinate system: ...
7
votes
3answers
448 views

Counting in for-loop using ArcPy Cursor?

When using the UpdateCursor, is there a "built-in" way to count within the loop? In the moment I am using a variable i and add 1 after each iteration: cur = arcpy.da.UpdateCursor("points.shp","ID1") ...
7
votes
1answer
11k views

Using ArcPy update cursor to replace <Null> value?

I have been combing the help associated with (None) values in arc, and have not been able to solve the following problem: I have a a field with mixed Null and integer values: 0 100 I would like ...
7
votes
1answer
5k views

Selecting specific row in attribute table using ArcPy (without iterating through whole table)? [closed]

I am using ArcGIS 10.2 and have assumed until now that it is possible to select a specific row in an attribute table. However, I can't seem to find a way to do this. The only available methods seem to ...
7
votes
1answer
1k views

How to improve performance of nested search cursors?

I have three nested SearchCursors. It works correctly but with slow performance. There are some solutions to improve the searchcursor performance like dictionary but i don't know how to use it with ...
7
votes
4answers
10k views

Debugging RuntimeError: workspace already in transaction mode from arcpy.da.UpdateCursor and ArcSDE feature classes?

I am making my first attempt at editing an ArcSDE feature class with python through a da.UpdateCursor. I'm essentially taking code I've written for a file geodatabase feature class and applying it to ...
7
votes
2answers
3k views

How to create an offset polyline in arcpy?

I am trying to create an offset polyline using arcpy, identical to the function in ArcObjects (constructoffset). After trying to access ArcObjects in arcpy, which I found difficult for those not well-...
7
votes
3answers
4k views

Cannot get rid of lock on file geodatabase and feature class created in Python script

I have a python script, (for ArcGIS 10), that creates a new file geodatabase, creates a new feature class in that file geodatabase and then reads data from an SDE feature class to populate the new ...
6
votes
4answers
15k views

Using arcpy.da.InsertCursor to insert entire row that is fetched from search cursor?

This is a simple process using the legacy cursors, but I cannot figure out how to do it with the newer Insert Cursor from the Data Access module. I basically want to take the entire row from a Search ...
6
votes
4answers
7k views

Accessing attribute table within shapefile and replace values?

I would like to find a Python script that will access an attribute table within a shapefile and either update or replace records inside a field column. More specifically, I would like to use the ...
6
votes
2answers
396 views

Remove duplicates from a field

I need to remove duplicates from a field named "Intersecti" Here is my code. I used list..set. It's not removing any duplicates. import arcpy duplicates = "G:\\xStreetNew\\Duplicates.shp" ...
6
votes
3answers
1k views

Zero filling attributes using ArcPy/Python?

I am just learning python and I need to convert a 2 digit numeric attribute in a table to a 2 digit zero-filled attribute in a script. For example, 9 needs to be 09.
6
votes
1answer
2k views

How to add Attributes to a polygon with arcpy

I have a question about arcpy. I want to create a polygon FeatureClass with attributes. The code below is just test-code that generates some polygons for speed testing. I want to add some additional ...
6
votes
3answers
8k views

Extracting data using arcpy.da.SearchCursor?

I have a shapefile of point features showing fire locations in a given year. One of the fields is named "YYYYMMDD" and indicates the corresponding date that that fire happened. In Python, I am trying ...
6
votes
1answer
89 views

Update Cursor skipping last row?

I have created a python function within field calculator to calculate the time difference between a timestamp (yyyy-MM-dd HH:mm:ss) in a row and the row after (the interval field in seconds). I have ...
6
votes
2answers
5k views

Calculating field in ArcGIS Desktop using ArcPy cursor?

I'm trying to calculate a field based on the values of others in the same layer in a calculation. I can't work out why its not working. I've even cut everything down to just be based on one field and ...
5
votes
4answers
5k views

Getting values of last row in table with ArcPy/SearchCursor?

I would like to base my query on the last row of a table? I know the basic syntax/functionality for my search cursor, how do I query only the last row; Below is an example of my search criteria, ...
5
votes
3answers
9k views

row.getValue() doesn't work but row[1] does

for some reason I can't get row.getValue to work properly... my script will only work if I use row[0] and get the value manually but I am sure the location/order of my fields will change from dataset ...
5
votes
3answers
10k views

Auto-incrementing in Python Script with ArcPy cursor?

I want to autoincrement values in a field within a Python script. I've done this using Field Calculator and the code referenced here. I tried using this code in the Python script below but it is not ...
5
votes
2answers
658 views

Is it a bad idea to convert a File Geodatabase table to a dictionary?

First, what am I trying to do? I am building a Python script that should be called from an ArcMap 10.0 toolbox. This scripts uses (among other inputs) data contained in huge gdb tables. It processes ...
5
votes
2answers
3k views

ArcPy Data Access Insert Cursor not writing geometries to feature class?

I'm using PyScripter and running ArcGIS 10.2.1. I am having troubles with the Insert Cursor in the arcpy module. I have an empty feature class in my geodatabase and have created the short script ...
5
votes
1answer
597 views

UpdateCursor gives Too few parameters Expected 1?

Can anyone tell me why my script isn't working? I can't figure out where I went wrong. I am working with an Access personal geodatabase. Adding a field, then updating that field with yes if the field ...
5
votes
2answers
5k views

ArcPy Insert Cursor not inserting all rows?

I have a script here that takes data from a cross-tabulated non-spatial dataset where monthly values are stored in a single table row for a given year and linearizes those data so that each monthly ...
5
votes
1answer
1k views

“Sequence size” doesn't match row in Python?

Essentially I am trying to calculate a value for a couple of fields after adding them. Below you can see how I am adding the fields and then an example on how my "for" statement is looping through the ...
5
votes
1answer
2k views

need to find max value among fields AND PRINT FIELD NAME

I have a Census dataset that contains eight fields with percentages. I would like a python script that finds the highest value between the eight fields, but also tells me which field the highest ...
5
votes
2answers
5k views

Getting XY coordinates and field values for each row in ArcPy SearchCursor?

I am trying to enumerate each row of a points shapefile and get a certain field's value (elevation) and the xy coordinates. But I see I can only use: arcpy.SearchCursor to get the field; OR arcpy....
5
votes
1answer
183 views

Update from/to Z from attributes using arcpy Update Cursor

Trying to update Z values onto some point and line features from the level attributes on each feature. My script works fine on points - the previous Z values of 0 now have the same values as the ...
5
votes
2answers
2k views

How to replace arcpy.CalculateField_management with an update cursor?

I'd like to replace this expression arcpy.CalculateField_management(bufferFile, "Shape_Area", "float('!shape.area@squaremeters!')", "PYTHON") with an arcpy.da.updatecursor. The reason for this is ...
5
votes
1answer
902 views

Deleting file locks in ArcPy?

I did not realize that I should have been deleting cursors after accessing attribute tables until today. Up until now I never did this, but I've noticed that there are lots of file locks after my ...
5
votes
1answer
2k views

Updating point geometry based on geometry of another feature class using arcgisscripting?

I'm looking to update the point geometry of lets say "oldFC" by obtaining the shape geometry of "newFC" and applying that to the "oldFC". I also want it to grab the value in the ID field in "newFC"...
5
votes
1answer
326 views

Writing points to a file

Trying to write the city name and point coords to a file. The following works with a polygon shapefile but not the point shapefile. I know I'm missing something basic. import arcpy # Set up the ...
5
votes
1answer
433 views

Comparing geometries using Search Cursors

I'm working on a little arcpy script to compare the geometry of features (linked by a matching ID field I've got a couple of search cursors populating dictionaries for the two feature classes which I ...
4
votes
3answers
1k views

Why [0] is needed in row[0] when using ArcPy (Data Access) cursors?

when running the following 2 sample codes, "[0]" is needed to be added after "row" in order to make code run well. I was confused. can anyone help explain? I know that it might be too easy for most of ...
4
votes
2answers
334 views

Does arcpy.da.SearchCursor store the results in an array?

When performing a query like this: var = 2 with arcpy.da.SearchCursor(in_table="table", field_names=['c1','c2'], where_clause = '[c1]' + '=' '\'' + str(var) +'\'') as cursor: I've just simply been ...