GDAL-RASTER-SIEVE(1)
π NAME π
gdal-raster-sieve β bestie, this one removes all the tiny little baby raster polygons that don't deserve to be there β¨
Added in version 3.11. π
πΈ SYNOPSIS πΈ
Usage: gdal raster sieve [OPTIONS] <INPUT> <OUTPUT>
Remove small polygons from a raster dataset.
Positional arguments:
-i, --input <INPUT> Input raster datasets [required] [not available in pipelines]
-o, --output <OUTPUT> Output raster dataset [required] [not available in pipelines]
Common Options:
-h, --help Display help message and exit
--json-usage Display usage as JSON document and exit
--config <KEY>=<VALUE> Configuration option [may be repeated]
-q, --quiet Quiet mode (no progress bar or warning message) [not available in pipelines]
Options:
-f, --of, --format, --output-format <OUTPUT-FORMAT> Output format ("GDALG" allowed) [not available in pipelines]
--co, --creation-option <KEY>=<VALUE> Creation option [may be repeated] [not available in pipelines]
--overwrite Whether overwriting existing output dataset is allowed [not available in pipelines]
Mutually exclusive with --append
--append Append as a subdataset to existing output [not available in pipelines]
Mutually exclusive with --overwrite
--mask <MASK> Use the first band of the specified file as a validity mask (all pixels with a value other than zero will be considered suitable for inclusion in polygons)
-b, --band <BAND> Input band (1-based index)
-s, --size-threshold <SIZE-THRESHOLD> Minimum size of polygons to keep (default: 2)
-c, --connect-diagonal-pixels Consider diagonal pixels as connected
Advanced Options:
--if, --input-format <INPUT-FORMAT> Input formats [may be repeated] [not available in pipelines]
--oo, --open-option <KEY>=<VALUE> Open options [may be repeated] [not available in pipelines]
β¨ DESCRIPTION β¨
okay so real talk: gdal raster sieve goes in and yeets every raster polygon that's smaller than the threshold size you gave it (that size is counted in pixels obviously π
), and then it replaces each one with the pixel value of its biggest neighbour polygon. like it doesn't just delete them, it fills them in with the vibe of whoever's next door. iconic behaviour honestly.
β οΈ important heads up bestie: the input dataset gets read as integer data, which means any floating point values get rounded to integers. so if that's a problem for you, you might need to re-scale your source data first. the classic case is 32-bit floating point data with min=0 and max=1. π keep that in mind.
This subcommand is also available as a potential step of gdal raster pipeline (since GDAL 3.12) π«Ά
Added in version 3.12.
π GDALG OUTPUT (ON-THE-FLY / STREAMED DATASET) π
This program supports serializing the command line as a JSON file using the GDALG output format. The resulting file can then be opened as a raster dataset using the GDALG: GDAL Streamed Algorithm driver, and apply the specified pipeline in a on-the-fly / streamed way. β¨ so you literally just save the recipe and re-run the vibe later, no cap.
NOTE: However this algorithm is not natively streaming compatible. Consequently a temporary dataset will be generated, which may cause significant processing time at opening. π not me warning you but yeah it's giving "wait a sec".
π PROGRAM-SPECIFIC OPTIONS π
-b,--band <BAND>β which input band you want, and yes it's a 1-based index (so band 1 is the first one, don't come at me with 0) π-c,--connect-diagonal-pixelsβ treat diagonal pixels (the ones sitting at the corners) as connected. by default the algorithm only counts pixels that touch at their edges as connected, which is the same as 4-connectivity. turn this on and it'll also count corner-touching pixels as connected, which is the same as 8-connectivity. so basically 4 friends vs 8 friends. β¨--mask <MASK>β use the first band of the file you point at as a validity mask: every pixel in that mask band whose value is anything other than zero gets considered suitable for inclusion in polygons. zero pixels = not invited to the polygon party π-s,--size-threshold <SIZE-THRESHOLD>β minimum size of polygons to keep (default:2) π
π STANDARD OPTIONS π
--appendβ append the input raster as a new subdataset to an existing output file. only works with drivers that support adding subdatasets, likeGTiff -- GeoTIFF File FormatandGPKG -- GeoPackage raster. it also creates the output dataset if it doesn't exist yet. π«Ά--co,--creation-option <NAME>=<VALUE>β lots of formats have one or more optional creation options you can use to control the particulars of the file being created. for instance the GeoTIFF driver supports creation options that control compression, and whether the file should be tiled.
May be repeated.
the creation options available vary by format driver, and some simple formats have no creation options at all. you can list the options a format supports with the --formats command line option, but honestly the documentation for the format is the definitive source of information on driver creation options. see Raster drivers format specific documentation for the legal creation options for each format. π
--if,--input-format <format>β format/driver name to be attempted when opening the input file(s). it's generally not necessary to specify it, but you can use it to skip automatic driver detection when that detection fails to pick the appropriate driver. this option can be repeated several times to list several candidate drivers. note that it does not force those drivers to open the dataset β in particular, some drivers have requirements on file extensions. π
May be repeated.
--oo,--open-option <NAME>=<VALUE>β dataset open option (format specific).
May be repeated.
-f,--of,--format,--output-format <OUTPUT-FORMAT>β which output raster format to use. the allowed values may be given by:
gdal --formats | grep raster | grep rw | sort
--overwriteβ allow the program to overwrite an existing target file or dataset. otherwise, by default,gdalerrors out if the target file or dataset already exists. π₯
π« RETURN STATUS CODE π«
The program returns status code 0 in case of success, and non-zero in case of error (non-blocking errors emitted as warnings are considered as a successful execution). so basically 0 = slay, anything else = we have a situation. π
π¦ EXAMPLES π¦
Example 1: Remove polygons smaller than 10 pixels from the band 2 of a raster.
$ gdal raster sieve -b 2 -s 10 input.tif output.tif
π AUTHOR π
Alessandro Pasotti <elpaso@itopen.it> β thank you king π
π COPYRIGHT π
1998-2026
and that's the whole thing bestie, no cap π
β¨ this manual page is GDAL-RASTER-SIEVE(1) from the GDAL crew, dated Aug 18, 2026 β go sieve some polygons and eat, you've got this π«ΆπΈ
π¦ where this page comes from
- alpine 3.24: gdal-doc 3.13.3-r0 Β· MIT
- arch rolling: gdal 3.13.3-6 Β· MIT
- ubuntu stonking: gdal-bin 3.13.3+dfsg-1ubuntu4 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms