Map Algebra with ImageMath
You can open the ImageMath raster calculator under
Calculate NDVI
Make sure to open the testdatasets for this example
Under Code Snippets –> Indices select NDVI. Select
enmap_potsdam.bsq
as your input.Alternatively, enter this code directly in the editor. Make sure to alter the names according to your raster. You do not need to alter Output Grid and Processing for now.
# select the red band red = enmap[38] # select the nir band nir = enmap[64] # calculate ndvi ndvi = (nir-red)/(nir+red)
Click the run button . The result should be listed in the Data Sources panel.
Mask raster with vector
Make sure to open the testdatasets for this example
Select
enmap_potsdam.bsq
under Inputs and name itenmap
. Further selectlandcover_potsdam_polygon.gpkg
and name itmask
.Under Outputs specify output path and file and name it
result
Enter this code in the editor
result = enmap # set all cells not covered by mask to nodata result[:, mask[0] == 0] = noDataValue(enmap) # specify nodata value setNoDataValue(result, noDataValue(enmap)) # copy metadata to result raster setMetadata(result, metadata(enmap))
Click the run button . The result should be listed in the Data Sources panel.