1

I am trying to add two different rasters using the Con function. I am iterating the raster layer using the for loop to obtain two rasters belonging to the same species and their formats are in grid and tif format. On running the below scripts i am not able to execute the con function. If anyone has a way to solve this issue, let me know your suggestion.

# 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"

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

# 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)

    rastersHab = arcpy.ListRasters("hab_species_str", "GRID")

    rastersCnty = arcpy.ListRasters("cnty_species_str", ".tif") 

    species_richness = os.path.join(output_workspace,  "_richness" + species_str + ".tif")

    (Con(("%rastersHab%" > 0)&("%rastersCnty%" == 1),1,0),species_richness)

    print j

    j = j+1
1

The main issue is trying to force raster lists as input into the Con function. Take a look at this similar post that searches a directory for rasters and then plugs-in a different name into the raster path to create a second, corollary path. Additionally, this post highlights how to use band math to make calculations, which is a more intuitive way to perform your type of calculations than Con.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.