AnsweredAssumed Answered

Field calculations in Python

Question asked by nekama on Jul 10, 2012
Latest reply on Jul 11, 2012 by nekama
Hi there,

I have a simple point feature class called 'drillholes' in an 9.3.1 ArcSDE database.  This feature class has two numeric fields; one called 'GRND_ELEV' which is fully populated, and 'REF_ELEV' which is only partially populated.  I need to create a python script which will select all of the rows where 'REF_ELEV' is not populated and then assign the respective value of 'GRND_ELEV' to those rows.  I have used model builder with the 'Calculate Field' tool as a starting point and used the expression REF_ELEV = [GRND_ELEV] where [REF_ELEV] is 'NULL'.  Running this script generates the following error: File "D:\scripts\DH_Update\TEST.py" line 22, in <module> gp.calculateFieldManagement<GIS_ADMIN_DRILLHOLES__2_, "REF_ELEV"' "[GRND_ELEV] where [REF_ELEV] is 'NULL'", "VB", ""> arcgisscripting.ExecuteError: ERROR 999999: Error executing function.  Expected end of statement.  Failed to execute <CalculateField>.

Any thoughts or directions on where I'm going wrong?

# ---------------------------------------------------------------------------
# TEST.py
# Created on: Wed Jul 11 2012 02:56:01 PM
#   (generated by ArcGIS/ModelBuilder)
# ---------------------------------------------------------------------------

# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

# Load required toolboxes...
gp.AddToolbox("D:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")

# Local variables...
GIS_ADMIN_Drillholes = "Database Connections\\GIS_PROD_ADMIN.sde\\GIS.ADMIN.GROUNDWATER\\GIS.ADMIN.Drillholes"
GIS_ADMIN_Drillholes__2_ = "Database Connections\\GIS_PROD_ADMIN.sde\\GIS.ADMIN.GROUNDWATER\\GIS.ADMIN.Drillholes"

# Process: Calculate Field...
gp.CalculateField_management(GIS_ADMIN_Drillholes__2_, "REF_ELEV", "[GRND_ELEV] where [REF_ELEV] is 'NULL'", "VB", "")

Outcomes