I've defined a python function to take input raster and elevation and output path. The function should return raster with two values 0 for elevation equal to and greater than given elevation and 1 for rest of the pixels. This is what I've done so far:

import arcpy
from arcpy.sa import*

def getRaster(input, elevation, outputpath):
  • What happens when you try calling your function?
    – PolyGeo
    Mar 11, 2018 at 18:35
  • 3
    Have a read of Con resources.arcgis.com/en/help/main/10.2/index.html#/Con/… outputraster = arcpy.sa.Con(input >= elevation,0,1) would replace most of your getRaster function... you'll still need to call outputraster.save(outputpath) assuming input is a raster object (might work for a string but might not). Don't forget to del outputraster just after the save or you'll have an unnecessary object filling up your temp space if the process later crashes. Mar 11, 2018 at 21:42

1 Answer 1


you would have to use 'Con'in spatial analysis. for instance your code would have to look like this

import arcpy
from arcpy.sa import * 
arcpy.OverwriteOutput= True
def getRaster(inRaster,outRaster)
inRaster = path to raster
OutRaster = Con(inRaster(i.e. the raster you are using),elevation > 0(i.e. if your condition is True), elevation = 0 (i.e. if your condition is false, a "value" option is here to set your condition)

'Con' is versatile for Map algebra.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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