0

This is very similar to Python script to iterate through geodatabase and assign field value based on spatial location and Assigning field value based on location without join just different data. This worked at home on my test data but when I changed the data and ran it at work It field Calculates one time then hits me with the error below. The difference between the two systems is work is at 10.5 and home is schools 10.7. After I get this to work I was going to add in the loop through the dataset because I have 50 features and 3 more feature zones to run this through but I haven't gotten that far and I'm not sure how to name the looped layer so I don't get an error.

import arcpy

arcpy.env.overwriteOutput = True

arcpy.env.workspace = r'\scw\ONUS_Joffre.gdb\Water'

arcpy.MakeFeatureLayer_management(r'\GDB\Basemap.gdb\Zones\BraggArea', "Bragg_area")

for fc in arcpy.ListFeatureClasses():

arcpy.MakeFeatureLayer_management(fc, lyr.name) # Create a search cursor for the Area rows = arcpy.SearchCursor("Bragg_Area")

for row in rows:

import arcpy

# Set overwrite option
arcpy.env.overwriteOutput = True

# KEEPING ORIGINAL LAYERS (NOT CREATING ADDITIONAL "JOINED" LAYER)
# Create FeatureLayers
arcpy.MakeFeatureLayer_management(r'\\GDB\Basemap.gdb\Zones\BraggArea', "Bragg_area")
arcpy.MakeFeatureLayer_management(r'\\scw\ONUS_Joffre.gdb\Water\ONUS_wMain_1', "WMain")
# Create a search cursor for the Area
rows = arcpy.SearchCursor("Bragg_Area")
for row in rows:
    # What you'll do is select each Area one at a time, and then select all the Features in that Area and calculate the field
    # NOTE: If you are using not using shapefiles, then you'll have to change the FID in the line below to OBJECTID (or similar)
    arcpy.SelectLayerByAttribute_management("Bragg_Area", "NEW_SELECTION", "\"OBJECTID\" = " + str(row.getValue("OBJECTID")))
    arcpy.SelectLayerByLocation_management("WMain", "WITHIN", "Bragg_area", "", "NEW_SELECTION")
    arcpy.CalculateField_management("WMain", "InstallationID", "'{0}'".format(str(row.getValue("InstallationID"))), "PYTHON_9.3", "")
    print "Finished processing " + str(row.getValue("InstallationID"))

Runtime error Traceback (most recent call last): File "", line 17, in File "", line 1108, in getValue return convertArcObjectToPythonObject(self._arc_object.GetValue(*gp_fixargs(args))) RuntimeError: ERROR 999999: Error executing function.

WaterMain

WaterMain

Bragg Area Feature

enter image description here

2

I suspect "InstallationID" isn't a field in your table. Double check the field name.

>>> curs = arcpy.SearchCursor ("Meters_RandomSel_geocoded")
>>> row = curs.next ()
>>> row.getValue ("fgfdgdfgfd")
Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\arcobjects\arcobjects.py", line 1100, in getValue
    return convertArcObjectToPythonObject(self._arc_object.GetValue(*gp_fixargs(args)))
RuntimeError: ERROR 999999: Error executing function.
>>> 

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.