2

I am updating a field for a feature class that is on an enterprise geodatabase in SQL server. This is an ArcSDE connection.

My goal is to search for null values, and convert these to 0. The script is currently run through python on ArcCatalog 10.3. This is the part of the script in question:

fc= r"C:\Users\migrate\AppData\Roaming\ESRI\Desktop10.3\ArcCatalog\OZ@DB_MAPS.sde\DB.OZ.BaseMap\DB.OZ.PlantCenter"
arcpy.MakeFeatureLayer_management (fc, "fc_temp")   
with arcpy.da.UpdateCursor ("fc_temp", fieldID) as cursor:
    for row in cursor:
        if row[0] == None:
            row[0] = 0
            cursor.updateRow(row)

This dataset has about 20,000 entries, and the processing time is immense (over an hour at this point) for this part of the script. Is there a way to change the code to improve processing time for update cursors?

  • @PolyGeo, I've updated the value of fc variable. I'm processing with the where_clause method provided by cptpython, and it's been processing for about 30 minutes at this point – saoirse Jan 24 '17 at 19:51
  • I should have commented on this, but it sounds like your data is located on a server? If so, then this will cause delays and increase processing time. Try saving the file locally and see if this issue still persists. – cptpython Jan 24 '17 at 20:07
  • @cptpython, that is correct. I've hardcoded the fc to a local file, and the script runs very quickly. Now connected directly to the server, it will run for nearly an hour (and how much more I have no idea) – saoirse Jan 24 '17 at 20:21
  • 1
    Sadly, working with anything over the server dramatically increases processing times. All our workflow has been to perform processing locally and then upload which works for us and might now work for others. – cptpython Jan 24 '17 at 20:29
  • 2
    Can you do the processing in memory? "in_memory\\fc_temp" – JamesLeversha Jan 24 '17 at 23:07
3

You may want to use where_clause, so you are performing this function only on records with null values. This should speed up the script. Here is a sample script:

where_clause = 'fieldID IS NULL'
with arcpy.da.UpdateCursor ("fc_temp", fieldID, where_clause) as cursor:
    for row in cursor:
        row[0] = 0
        cursor.updateRow(row)
|improve this answer|||||
  • 1
    +1. You can also add an index on fieldID if this code block will be run multiple times. – Paul Jan 24 '17 at 23:15
2

Use Select by Attribute to select all records with a Null value in the relevant field, then Calculate that field with the desired value. I might be missing something, but I can't see a reason to use an update cursor.

A possible solution would be:

fc= r"C:\Users\migrate\AppData\Roaming\ESRI\Desktop10.3\ArcCatalog\OZ@DB_MAPS.sde\DB.OZ.BaseMap\DB.OZ.PlantCenter"
arcpy.MakeFeatureLayer_management (fc, "fc_temp")
arcpy.SelectLayerByAttribute_management("fc_temp","NEW_SELECTION",'"fieldID" IS NULL')
arcpy.CalculateField_management("fc_temp","fieldID","0","PYTHON","")
|improve this answer|||||

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.