Trying to update some well data from another layer. I am trying to do this in Arcmap (10.6) with a tool/script (3.6.10 Python).
I need to transfer attributes from WellParcels to WellsPoints. I would like to do this with out starting a Edit session in python if possible as this tends to slow down the process...? I would manual start an edit session in ArcMap then run the tool/script when I have points selected, I currently have the following but error out on line 44. I am not sure this is the best/fastest way of doing it, so if someone has a different idea please share how I would do this with my data.
import arcpy,os
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r'Database Connections\Connection to blah.sde'
ptSelection = "WellPoints"
pointLayer = arcpy.env.workspace + os.sep + "WellPoints"
parcel = 'WellParcels'
sjpoints = "In_memory\sjpoints"
try:
ptCount = int(arcpy.GetCount_management(ptSelection).getOutput(0))
dsc = arcpy.Describe(ptSelection)
selection_set = dsc.FIDSet
if len(selection_set) == 0:
print "There are no features selected"
elif ptCount >= 1:
arcpy.SelectLayerByLocation_management(parcel,"INTERSECT",ptSelection)
arcpy.MakeFeatureLayer_management(parcel,"parcel_lyr")
arcpy.SpatialJoin_analysis(ptSelection, "parcel_lyr" , sjpoints)
#sourceFieldsList = 'WellID', 'dept', 'type', ' Geothermal' 'GeoWaterUs', 'Temp', 'TempDate'
#valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sjpoints, sourceFieldsList)}
fldList = ['WellID', 'dept', 'type', ' Geothermal' 'GeoWaterUs', 'Temp', 'TempDate']
fldDict ={}
print (fldDict)
targetFields = ['W_ID', 'dept', 'type', ' Geothermal' 'GeoWaterUs', 'Temp', 'TempDate']
with arcpy.da.UpdateCursor(ptSelection, targetFields) as cursor:
for row in cursor
row[0] = ['W_ID']
row[1] = ['dep']
row[2] = ['type']
row[3] = ['Geothermal']
row[4] = ['GeoWaterUs']
row[5] = ['Temp']
row[6] = ['TempDate']
#Attributes from Wellparcels
curosr.append(fldDict['Account', 'dept', 'type', ' Geothermal' 'GeoWaterUs', 'Temp', 'TempDate'])
except Exception, e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print("Line %i" % tb.tb_lineno)
arcpy.AddMessage("Line %i" % tb.tb_lineno)
print(e.message)
arcpy.AddMessage(e.message)
Try changing lines 9 and 10 in my Sept 27 response.
# From:
parcelFlds = ['WellID', 'W_DEPTH', 'Geothermal', 'GeoWaterUs', 'TEMP', 'TEMP_DATE']
pointFlds = ['WellID', 'W_DEPTH', 'Geothermal', 'GeoWaterUs', 'TEMP', 'TEMP_DATE', 'SHAPE@']
# To something like (just match fields by position in lists):
parcelFlds = ['field_A', 'field_1', 'field_B', 'field_2', 'field_C', 'field_3']
pointFlds = ['fieldA', 'field1', 'fieldB', 'field2', 'fieldC', 'field3', 'SHAPE@']