AnsweredAssumed Answered

I am getting an error "Cannot acquire a lock" when trying to calculate values in multiple fields.

Question asked by RNoyes_JoCo on Apr 19, 2018
Latest reply on Apr 29, 2018 by rastrauch

So, I have created a script that adds 6 fields to a shapefile: Situs_city, Situs_St, Situs_Zip, Latitude, Longitude, and GIS_Acres. Further, the script is set to calculate the values for the Latitude, Longitude, and GIS_Acres fields. The script will work fine until after creating the GIS_acres field. Once this field is created the next step is to calculate and that is when I get an Error 999999: cannot acquire a lock. The weird aspect is once in a while the script will run all the way through just fine... anyway, I am stumped. I am pretty new to creating python scripts. If anyone has a suggestion that would be awesome.

 

 

import arcpy
import os

 

# Step 1  -  Copy new [Taxlots_TEST_DeleteME.shp] from \\cove\Department Shares\Common\Assessor\ArcGIS to E:\STAGING (IKRIT)
#set variables

 

in_data = "S:\Common\Assessor\ArcGIS\Taxlots_TEST_DeleteME.shp"
Shapefile = "E:\\STAGING\\Taxlots_TEST_DeleteME.shp"
#out_data = "E:\STAGING\Taxlots_TEST_DeleteME.shp"
arcpy.Copy_management(in_data, Shapefile)
print "Step 1 complete"

 

#Step 2: Add Situs fields
# Create a new field - Situs_City (string, 25)
arcpy.AddField_management(Shapefile, "Situs_City", "TEXT", "","","25","","NULLABLE","NON_REQUIRED","")
print "Step 2a: Add Situs_City complete."

 

# Create a new field - Situs_St (string, 2)
arcpy.AddField_management(Shapefile, "Situs_St", "TEXT", "#", "#", "2", "#", "NULLABLE", "NON_REQUIRED", "#")
print "Step 2b: Add Situs_St complete."

 

# Create a new field - Situs_Zip (string, 10)
arcpy.AddField_management(Shapefile, "Situs_Zip", "TEXT", "#", "#", "10", "#", "NULLABLE", "NON_REQUIRED", "#")
print "Step 2c: Add Situs_Zip complete."
print "Step 2: Create situs fields complete."

 

# Step 3: Create and calculate Latitude and Longitude fields.
latLonRef = "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj"
Taxlot_shp = "E:\STAGING\Taxlots_TEST_DeleteME.shp"
featureClassesList = Taxlot_shp.split(";")
field_Type = "DOUBLE"
field_precision_1 = 12
field_scale_1 = 8

 

for featureClass in featureClassesList:
 arcpy.AddMessage("Calculating XY coordinates for: " + featureClass)
 arcpy.AddField_management(featureClass, "Latitude", field_Type, field_precision_1, field_scale_1)
 arcpy.AddField_management(featureClass, "Longitude", field_Type, field_precision_1, field_scale_1)
 rows = arcpy.UpdateCursor(featureClass, "", latLonRef)
for row in rows:
 feat = row.getValue("shape")
 cent = feat.centroid
                # To get the polygon area: cent = feat.area
 row.Latitude = cent.Y
 row.Longitude = cent.X
 rows.updateRow(row)
  #arcpy.AddMessage(str(lat) + ", " + str(lon))
print "Step 3: Add Lat and Long complete"

 

# Step 4: Create a new field - GIS_Acres (Double, 15, 3)
Shapefile3 = "E:\STAGING\Taxlots_TEST_DeleteME.shp"
#Set local variables
field_Name = "GIS_Acres"
field_Type = "DOUBLE"
field_Precision = 15 #total number of digits stored
field_Scale = 4 #number of decimals places

 

arcpy.AddField_management(Shapefile3, field_Name, field_Type, field_Precision, field_Scale)
arcpy.CalculateField_management(Shapefile3, field_Name, '!SHAPE.area@ACRES!', "PYTHON_9.3")
print "Step 4: Calculate acres complete"

 

print "Congratulations! You have completed adding fields to to the Taxlots feature class. "

Outcomes