It looks like you are having a single vs. double quotes issue. I'm pretty sure you cannot have single quotes within other single quotes.
Try this:
in_features = "spain_1901_1.shp"
out_layer0 = "spain_1901_1"
where_clause = "'NAME' = 'LA MESA'"
workspace = "C:/output"
Edit --------------
The quote issue above is probably a minor problem.
You stated that you are exporting a Raster
. This however, doesn't work for the details you have in the script provided. You cannot have a Raster
Layer that is saved as a Shapefile
. You need to first make sure the type of features you are exporting and what you are exporting to.
The other issue is that the Where
clause is specifying a field of title Name
in the shapefile where the values are equal to La Mesa. Unless you have specifically created an attribute table for your Raster
, the only contents you would be able to select for would be a field named Value
, and the contents would be Integer values, not text.
As I said in my comment above, please provide more detail and I'll edit this answer as more info is available.
Edit 2 -----------------
Edit 3 -----------------
Simplicity is the answer here. One thing that is often confusing in ArcGIS is when you have to actually save a layer to disk, thus saving the actual Raster Dataset, or when you may use the Raster Layer as the input to a new function. Based on the script you added above, it looks like a number of the functions may actually be left out.
The first step is to Make a NetCDF Raster Layer
The output of this is a Raster Layer
, which is essentially the ArcGIS Raster object properties with your NetCDF Layer
as the source.
This step negates the need for a couple of steps in your original script, which are as follows:
- Make Feature Layer - This is not necessary for 2 reasons. The first is that it is the wrong function. Since you are dealing with a Raster, you would use the Make Raster Layer.
Feature Layers
deal with vector data, whereas Raster Layers
deal with grid based data, and each has specific unique properties. The 2nd reason it is not necessary is that the Make NetCDF Raster Layer
function outputs the same type of layer as this function would.
- Save Layer File - This simply saves a
.lyr
file to disk, thus letting you bring up the Raster again with the same properties saved. It does not actually create a new Raster Dataset. That would be accomplished with a different function, which may be an option down below.
As I mentioned above, it is sometimes hard to determine when you can work with a Raster Layer
as an input, or when you need to actually reference a Raster Dataset
that is saved to disk. For that reason, I will include two different versions of the script. The 2nd version will include the intermediate step of saving the NetCDF Raster to a .tif
on disk, and then referencing that in the Zonal Statistics
function.
Version #1:
#MAKE RASTER FILE
# Import system modules
import arcpy
from arcpy import env
from arcpy import sa
# Set Local variables
inNetCDFFile = "C:/Users/ESS/Desktop/temp/tmpy1901m01.nc"
variable = "tmp"
XDimension = "lon"
YDimension = "lat"
outRasterLayer = "C:/Users/ESS/Desktop/out/spain_1901_1"
bandDimmension = ""
dimensionValues = ""
valueSelectionMethod = ""
# Execute MakeNetCDFRasterLayer
arcpy.MakeNetCDFRasterLayer_md(inNetCDFFile, variable, XDimension, YDimension, outRasterLayer, bandDimmension, dimensionValues, valueSelectionMethod)
#Perform Spatial Statistics calculations using Spatial Analyst
# Set environment settings
env.workspace = "C:/Users/ESS/Desktop/out"
# Set local variables
inZoneData = "es2001.shp"
zoneField = "FIDS"
inValueRaster = outRasterLayer
outTable = "spain_1901_1_data.dbf"
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Execute ZonalStatisticsAsTable
outZSaT = ZonalStatisticsAsTable(inZoneData, zoneField, inValueRaster,
outTable, "NODATA", "ALL")
A couple of important points to note: I have removed the references to saving a .shp
file from your output Raster in the NetCDF Raster function. This is because the Shapefile format is a vector
format and would likely generate an error upon running. Also, I have simply passed through the variable for the layer name of the output from the first function, to the variable for the input of the 2nd function.
In case the above doesn't work because the Zonal Statistics script requires an actual Raster dataset as input, I am including another version where the NetCDF Raster Layer output is saved to a Raster .tif
file using the Raster Copy function.
Version 2:
#MAKE RASTER FILE
# Import system modules
import arcpy
from arcpy import env
from arcpy import sa
# Set Local variables
inNetCDFFile = "C:/Users/ESS/Desktop/temp/tmpy1901m01.nc"
variable = "tmp"
XDimension = "lon"
YDimension = "lat"
outRasterLayer = "C:/Users/ESS/Desktop/out/spain_1901_1"
bandDimmension = ""
dimensionValues = ""
valueSelectionMethod = ""
# Execute MakeNetCDFRasterLayer
arcpy.MakeNetCDFRasterLayer_md(inNetCDFFile, variable, XDimension, YDimension, outRasterLayer, bandDimmension, dimensionValues, valueSelectionMethod)
#Save Raster Layer to disk as .tif file
inrasterlayer = outRasterLayer
outRastertif = "C:/Users/ESS/Desktop/out/spain_1901_1.tif"
try:
arcpy.CopyRaster_management(inrasterlayer,outRastertif)
except:
print "Copy Raster example failed."
print arcpy.GetMessages()
#Perform Spatial Statistics calculations using Spatial Analyst
# Set environment settings
env.workspace = "C:/Users/ESS/Desktop/out"
# Set local variables
inZoneData = "es2001.shp"
zoneField = "FIDS"
inValueRaster = "spain_1901_1.tif"
outTable = "spain_1901_1_data.dbf"
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Execute ZonalStatisticsAsTable
outZSaT = sa.ZonalStatisticsAsTable(inZoneData, zoneField, inValueRaster,
outTable, "NODATA", "ALL")
Hopefully this will help, let me know if there are still problems.