arcpy.AddField_management(inMemoryIntersect, "Traffic", "DOUBLE")
Solved! Go to Solution.
arcpy.AddMessage(str([field.name for field in arcpy.ListFields(inMemInt)]))
outstring = pprint.pformat([field.name for field in arcpy.ListFields(inMemInt)]) arcpy.AddMessage(outstring)
'"AGADT2005" * "Shape_Length"'
import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
fc = "Parcels"
arcpy.MakeFeatureLayer_management(fc, "IN_MEMORY\test")
arcpy.AddField_management("IN_MEMORY\test", "PIN", "DOUBLE")
lstFields = arcpy.ListFields("IN_MEMORY\test")
for field in lstFields:
print field.name
import csv, sys
import arcpy as gp
from arcpy import env
env.workspace = r"C:\\Users\\thob\\Projects\\Road_Length.gdb"
env.overwriteOutput = True
BSMB = gp.MakeFeatureLayer_management("\\BSMB\\pntBSMB", "BSMB")
ROADS = gp.MakeFeatureLayer_management("\\Background\\Local_network", "ROADS")
inMemBuf = "in_memory/Buffer"
inMemInt = "in_memory/Intersect"
inMemSum = "in_memory/Statistic"
print("All variables in memory")
lstCalcD = []
distance = "500 Meters"
rowsCohort = gp.SearchCursor(BSMB)
for Brow in rowsCohort:
BpntID = int(Brow.getValue("OldID"))
print(BpntID)
strSearch = "\"OldID\" = %s" %str(BpntID)
BpntX = Brow.getValue("POINT_X")
print BpntX
BpntY = Brow.getValue("POINT_Y")
gp.SelectLayerByAttribute_management(BSMB, "NEW_SELECTION", strSearch)
gp.Buffer_analysis(BSMB, inMemBuf, distance)
inF = [inMemBuf, ROADS]
gp.Intersect_analysis(inF, inMemInt)
gp.ListFields(inMemInt)
gp.CalculateField_management(inMemInt, "Traffic", "[AGADT2005] * [Shape_Length]", "VB", "")
statF = [["Traffic", "SUM"]]
gp.Statistics_analysis(inMemInt, inMemSum, statF, "ID")
lstB = [BpntID, BpntX, BpntY, inMemSum]
print(lstB)
lstCalcD.append(lstB)
csvfile = open(r"C:\\User\\thob\\Projects\\lstTraf_x_d.csv", 'wb')
csvFile = csv.writer(csvfile, dialect='excel', delimiter=',')
csvFile.writerow(['ID,X,Y,Traffic_Load'])
csvFile.writerows(lstCalcD)
csvfile.close()
gp.Delete_management("in_memory")
calcExpression = "'" + siteName + "'" arcpy.CalculateField_management(singleSurveyImageLocationsDD_FCIM,"SiteName",calcExpression,"PYTHON_9.3","#")
gp.CalculateField_management(inMemInt, "Traffic", "[AGADT2005] * [Shape_Length]", "VB", "")
arcpy.AddMessage(str(arcpy.ListFields(inMemInt)))
arcpy.AddMessage(str(arcpy.ListFields(inMemInt)))
!AGADT2005! * !Shape_Length!comes with ERROR 000539: Invalid field Shape_Length
arcpy.AddMessage(str([field.name for field in arcpy.ListFields(inMemInt)]))
outstring = pprint.pformat([field.name for field in arcpy.ListFields(inMemInt)]) arcpy.AddMessage(outstring)
'"AGADT2005" * "Shape_Length"'
unfortunately the result of
always comes as "<Field object at 0x55c7f90[0x577c590]>" and I never get the field name.
str([field.name for field in arcpy.ListFields(inMemInt)])
One thing that may be tripping you up is if you go through shapefile format at some point in your processing, Shape_Length is more than 10 characters, so it can get truncated to SHAPE_LENG.