I am working on a script that iterates through the records of "feature class A", performs a spatial selection (flow tracing) with each individual "A" record on "feature class B" and then field calculates an attribute from "A" into the resulting selected records in "B"
Basically for each downstream-most node on a sewer pipe network, trace upstream and assign the ID of that downstream node to all upstream features.
The attribute value will always be a whole number, but sometimes field in A is formatted as text and sometimes as a number.
I can successfully perform this calulation if:
A is formatted as TEXT
and
B is formatted as LONG
the operation fails to calculate anything if:
A is formatted as LONG
and
B is Formatted as LONG
What am I missing so that this will work for both potential input cases if the ID for A is either text whole number or an integer whole number format?
...
for row in cursor:
ID = (str(row.getValue(str(flagname))))
whereclause = ((str(flagname)) +str(' = ') + "'%s'" %ID)
fc=str(r"outfalls_lyr")
arcpy.MakeFeatureLayer_management(traceflag, fc)
try:
arcpy.SelectLayerByAttribute_management(fc, "NEW_SELECTION",str(whereclause))
arcpy.MakeFeatureLayer_management( fc,r"in_memory\temp_of")
arcpy.TraceGeometricNetwork_management(geomnet, r"in_memory\outNet",r"in_memory\temp_of" , "TRACE_UPSTREAM", "", "", "","", "", "NO_TRACE_ENDS", "NO_TRACE_INDETERMINATE_FLOW", "", "", "AS_IS", "", "", "", "AS_IS")
for layer in arcpy.mapping.Layer(r"in_memory\outNet"):
try:
print arcpy.mapping.ListLayers(layer)
calc = str('"%s"' %ID)
arcpy.CalculateField_management (layer, fieldname, calc,"","")
except:
print arcpy.GetMessages()
except:
print arcpy.GetMessages()
Cross-posted to Stack Overflow, too.