ZonalStatistics¶
This application computes zonal statistics
Description¶
This application computes zonal statistics from label image, or vector data. The application inputs one input multiband image, and another input for zones definition. Zones can be defined with a label image (inzone.labelimage.in) or a vector data layer (inzone.vector.in). The following statistics are computed over each zones: mean, min, max, and standard deviation. Statistics can be exported in a vector layer (if the input zone definition is a label image, it will be vectorized) or in a XML file
This application has several output images and supports “multi-writing”. Instead of computing and writing each image independently, the streamed image blocks are written in a synchronous way for each output. The output images will be computed strip by strip, using the available RAM to compute the strip size, and a user defined streaming mode can be specified using the streaming extended filenames (type, mode and value). Note that multi-writing can be disabled using the multi-write extended filename option: &multiwrite=false, in this case the output images will be written one by one. Note that multi-writing is not supported for MPI writers.
Parameters¶
Input Image -in image
Mandatory
Background value to ignore in statistics computation -inbv float
Type of input for the zone definitions -inzone [vector|labelimage]
Default value: vector
- Input objects from vector data
- Input objects from label image
Input objects from vector data options¶
Input vector data -inzone.vector.in vectorfile
Mandatory
Reproject the input vector -inzone.vector.reproject bool
Default value: false
Input objects from label image options¶
Input label image -inzone.labelimage.in image
Mandatory
No-data value for the input label image -inzone.labelimage.nodata int
Format of the output stats -out [vector|xml|raster]
Default value: vector
- Output vector data
- Output XML file
- Output raster image
Output vector data options¶
Filename for the output vector data -out.vector.filename vectorfile
Mandatory
Output XML file options¶
Filename for the output xml file -out.xml.filename string
Mandatory
Output raster image options¶
File name for the raster image -out.raster.filename image [dtype]
Mandatory
Background value for the output raster -out.raster.bv float
Available RAM (MB) -ram int
Default value: 256
Available memory for processing (in MB).
Examples¶
From the command-line:
otbcli_ZonalStatistics -in input.tif -inzone.vector.in myvector.shp -out.vector.filename myvector_with_stats.shp
From Python:
import otbApplication
app = otbApplication.Registry.CreateApplication("ZonalStatistics")
app.SetParameterString("in", "input.tif")
app.SetParameterString("inzone.vector.in", "myvector.shp")
app.SetParameterString("out.vector.filename", "myvector_with_stats.shp")
app.ExecuteAndWriteOutput()
Limitations¶
- The inzone.vector.in must fit in memory (if “inzone” is “vector”). 2) The vectorized label image must also fit in memory (if “out” is “vector”): if not, consider using “out” to “xml”