I am looking for an easy solutions with Map Algebra for this one without Saving:
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
# Set environment settings
env.workspace = "C:/temp"
# Set local variables
inRaster = "DOM.tif"
inMask = "Mask.shp"
maskBuffer = "C:/temp/maskBuffer.shp"
temp = "C:/temp/temp.tif"
arcpy.Buffer_analysis(inMask, maskBuffer, "5 Meters")
outExtractByMask = ExtractByMask(inRaster, maskBuffer)
#is it possible to get the Minumum and Maximum directly from this Map Algebra?
outExtractByMask.save(temp)
tempRaster = Raster(outExtractByMask)
print(tempRaster.minumum)
This is a try to get the height of buildings in a loop, so I will ExtractByMask for each Feature in maskBuffer.
2 Answers 2
outExtractByMask
is a Raster
object, no need to use tempRaster = Raster(outExtractByMask)
.
Raster
objects have minimum
and maximum
properties.
You just need to calculate statistics to ensure those properties are not None
.
outExtractByMask = ExtractByMask(inRaster, maskBuffer)
arcpy.CalculateStatistics_management(outExtractByMask)
print(outExtractByMask.minumum)
Although your question doesn’t explicitly ask for it, based on the description of your problem you may prefer to use Zonal Statistics As Table with your building footprints as zones (with a unique identifier field value for each building), with the "MIN_MAX" statistic.
That would avoid the requirement for looping. Just perform the zonal statistics operation and join the resulting table back to your building footprint layer.