Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
share|improve this question
1  
species_richness is a list, not an array, you should be creating it with numpy.Array(x,y) not species_richness = [] or better yet do species_richness = arcpy.RasterToNumPyArray(str_TIF_File) then overwrite the values. –  Michael Miles-Stimson Apr 23 at 4:45
    
Hi Michael, Thanks it really helped. But now i am getting a error that raster dataset could not be saved in GRID format. Would you know how i can change the output to the TIFF format.Please look at the below script and also the errors. species_richness = arcpy.RasterToNumPyArray(str_TIF_File) errors - newRaster.save(output_workspace) RuntimeError: ERROR 010240: Could not save raster dataset to C:\GIS_Analysis_programming\GAPanalysisData\Output\species_richnessARJA with output format GRID. –  Mukhtar Ahmed Apr 23 at 5:10
    
It's probably that the name is too long, GRID has very severe limitations on naming. newRaster.save(output_workspace + "\\Result.tif") will save as type TIFF in the value of output_workspace. It looks like you could change output_workspace = "species_richness" + species_str + ".tif", but I'm not sure what's in species_str –  Michael Miles-Stimson Apr 23 at 5:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.