Hi. Just wondering if anyone could tell me what's wrong with the temp_layer here? I am using the temp layer to avoid problems with the PointToRaster_conversion and data sources with joins. (error 000055)
import arcpy
from arcpy.sa import *
arcpy.env.workspace = r"C:\Users\aazma\Desktop\Incomplete(503)\Incomplete"
arcpy.env.overwriteOutput = True
in_csv = r"C:\Users\aazma\Desktop\Incomplete(503)\Incomplete\PCBsData.csv"
out_raster = r"C:\Users\aazma\Desktop\Incomplete(503)\Incomplete\output.tif"
layer_name = "temp_layer"
x_field = "X"
y_field = "Y"
spatial_reference = arcpy.SpatialReference(4326)
arcpy.MakeXYEventLayer_management(in_csv, x_field, y_field, layer_name, spatial_reference)
cellsize = 0.1
value_field = "value"
assignment_type = "MEAN"
arcpy.PointToRaster_conversion(layer_name, value_field, out_raster, assignment_type, value_field, cellsize)
arcpy.Delete_management(layer_name)
Solved! Go to Solution.
Have you tried the "memory" example? You're currently writing to your desktop/user data folder, there could be organisational or personal setup restrictions on executables writing to this location so I'd also try a folder within a drive e.g. C:\Testing\Testing.gdb
I'd also always try the script on a very small subset of data initially.
I'd say it's having an issue accessing the layer, parentheses in the workspace path could be an issue. Maybe write to memory or try a different workspace path, or make the temp location explicit. psb writing to memory example:
import arcpy
from arcpy.sa import *
arcpy.env.overwriteOutput = True
in_csv = r"C:\Users\aazma\Desktop\Incomplete(503)\Incomplete\PCBsData.csv"
out_raster = r"C:\Users\aazma\Desktop\Incomplete(503)\Incomplete\output.tif"
layer_name = r"memory\temp_layer"
x_field = "X"
y_field = "Y"
spatial_reference = arcpy.SpatialReference(4326)
arcpy.MakeXYEventLayer_management(in_csv, x_field, y_field, layer_name, spatial_reference)
cellsize = 0.1
value_field = "value"
assignment_type = "MEAN"
arcpy.PointToRaster_conversion(layer_name, value_field, out_raster, assignment_type, value_field, cellsize)
try:
arcpy.Delete_management(layer_name)
del layer_name
except:
pass
Added the recommendations, and removed the underscore from temp_layer, as pictured. any other ideas? my dataset is also many years of time, so potentially splitting the data into years and then processing could help? I couldn't find anything about file size limitations online but just an idea.
import arcpy
from arcpy.sa import *
arcpy.env.workspace = r"C:\Users\aazma\Desktop\Incomplete503\Incomplete"
arcpy.env.overwriteOutput = True
in_csv = r"C:\Users\aazma\Desktop\Incomplete503\Incomplete\PCBsData.csv"
out_raster = r"C:\Users\aazma\Desktop\Incomplete503\Incomplete\output.tif"
layer_name = r"C:\Users\aazma\Desktop\Incomplete503\Incomplete\templayer"
x_field = "X"
y_field = "Y"
spatial_reference = arcpy.SpatialReference(4326)
arcpy.MakeXYEventLayer_management(in_csv, x_field, y_field, layer_name, spatial_reference)
cellsize = 0.1
value_field = "value"
assignment_type = "MEAN"
arcpy.PointToRaster_conversion(layer_name, value_field, out_raster, assignment_type, value_field, cellsize)
try:
arcpy.Delete_management(layer_name)
del layer_name
except:
pass
Have you tried the "memory" example? You're currently writing to your desktop/user data folder, there could be organisational or personal setup restrictions on executables writing to this location so I'd also try a folder within a drive e.g. C:\Testing\Testing.gdb
I'd also always try the script on a very small subset of data initially.
I tried a sample .csv of only a few lines, and that worked. So then I split the data up into 2001.csv, 2002.csv, etc and found that I got the same error. because of this I simply shortened each year to 150 samples, and cleaned a few columns I didn't end up using, and this worked. Below is the final version of the code, thank you for all the help!
import arcpy
from arcpy.sa import *
arcpy.env.workspace = r"C:\Testing"
arcpy.env.overwriteOutput = True
in_csv_list = ["2001.csv", "2002.csv", "2003.csv", "2004.csv", "2005.csv", "2006.csv", "2007.csv", "2008.csv", "2009.csv", "2010.csv", "2011.csv"]
for in_csv in in_csv_list:
out_raster = in_csv.split(".")[0] + ".tif"
layer_name = r"C:\Testing\templayer"
x_field = "X"
y_field = "Y"
spatial_reference = arcpy.SpatialReference(4326)
arcpy.MakeXYEventLayer_management(in_csv, x_field, y_field, layer_name, spatial_reference)
cellsize = 0.08
value_field = "Total_PCB(ppm)"
assignment_type = "RANGE"
arcpy.PointToRaster_conversion(layer_name, value_field, out_raster, assignment_type, value_field, cellsize)
arcpy.Delete_management(layer_name)
del layer_name