Hi,here is the code I'm using and I just figured out that the AddField function is working. So it must be the CalculateField function. I'm not sure how to address the fields stored within the dataset in memory. The error I'm getting is Error 999999: Error executing function. Failed to execute (CalculateField).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")
- We are living in the 21st century.
GIS moved on and nobody needs a format consisting out of at least three files! No, nobody needs shapefiles, not even for the sake of an exchange format. Folks, use GeoPackage to exchange data with other GIS!