Select to view content in your preferred language

Trying to convert a .csv with XY coordinates to .tiff raster

729
2
04-12-2023 07:43 AM
Labels (1)
AlexanderZirilli
Emerging Contributor

I wish to take a .csv with lat long values for "fish catches" and rasterize the values to a .tiff for the sake of displaying the different concentration levels of the "Total_PCB" column. I created a function to calculate the latitude of each catch, based on the reference point given in the dataset, the NYC battery (-74.015700, 40.703160) (GCS_WGS_1984 for all points) and the "river mile" column giving exactly how many miles upstream from the battery this catch was. I want to create a raster that symbolizes the "Total_PCB" , perhaps as a choropleth. Right now I have the code listed below, but yield

ERROR 000055: Cannot create a Query Table for this workspace
Failed to execute (MakeXYEventLayer).

 

import arcpy
from arcpy.sa import *

arcpy.env.workspace = r"C:\Users\aazma\Desktop\Incomplete(503)\Incomplete"
arcpy.env.overwriteOutput = True

in_csv = "PCBs_in_Hudson_River_Fish_Data.csv"
out_raster = "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)

0 Kudos
2 Replies
DavidPike
MVP Frequent Contributor

Have you missed the full filepath to your CSV? 'in_csv'

0 Kudos
AlexanderZirilli
Emerging Contributor

 

Added file paths, AND r" ", but still get the same error, at line 15 instead of line 7 this time. Some other solutions online suggest pandas?

 

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\PCBs_in_Hudson_River_Fish_Data.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)

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\PCBs_in_Hudson_River_Fish_Data.csv"
out_raster = "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)

0 Kudos