I am getting a error as follows File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy__init__.py", line 2292, in NumPyArrayToRaster return _NumPyArrayToRaster(*args, **kwargs) ValueError: Argument in_array: A two or three dimensional NumPy array is require.
Basically i am trying apply con function on two raster layers. let me know if any you guys know how i should define the array for Numpy. Thank you.
# Import arcpy module
import arcpy
import os
from arcpy.sa import Con
# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
# Overwrite the ouptut
arcpy.env.overwriteOutput = 1
# set environmental settings # Location of the rasters
output_workspace = "C:\\GIS_Analysis_programming\\GAPanalysisData\\Output"
#arcpy.env.workspace = r"C:/GIS_Analysis_programming/GAPanalysisData/Output"
arcpy.env.workspace = "C:\\GIS_Analysis_programming\\GAPanalysisData\\Output"
allMamRows = arcpy.SearchCursor("C:\\GIS_Analysis_programming\\GAPanalysisData\\Flmammal.dbf")
# loop through mammal list and load code to list
mamList = []
i=0
for row in allMamRows:
mamList.append(row.getValue("CODE"))
# print mamList[i]
i = i +1
# species_str = str(species)
# Local variables:
# Creating a list of rasters from the workspace.
# Iterations through (only 10) mammals
j=0
for species in mamList:
if j < 10 :
species_str = str(species)
B4 = arcpy.ListRasters("hab_"+species_str)
B5 = arcpy.ListRasters("cnty_"+species_str+".tif")
species_richness = []
for str_GRID_File in B4:
for str_TIF_File in B5:
print str_GRID_File
print str_TIF_File
species_str = str(species)
output_workspace = "species_richness"+species_str
str_GRID_File = arcpy.Raster("hab_"+species_str)
str_TIF_File = arcpy.Raster("cnty_"+species_str+".tif")
#i'm assuming both rasters are the same extents/cellsize
lowerLeft = arcpy.Point(str_GRID_File.extent.XMin, str_GRID_File.extent.YMin)
cellSize = str_GRID_File.meanCellWidth
nodata = str_GRID_File.noDataValue
numpy_GRID = arcpy.RasterToNumPyArray(str_GRID_File)
numpy_TIFF = arcpy.RasterToNumPyArray(str_TIF_File)
species_richness = (("%numpy_TIFF%" > 0)|("%numpy_GRID%" == 1),1,0)
newRaster = arcpy.NumPyArrayToRaster(species_richness,lowerLeft,cellSize,value_to_nodata=nodata)
newRaster.save(output_workspace)
print j
j = j+1