GDAL-RASTER-CLIP(1)
π NAME π
gdal-raster-clip β clip a raster dataset βοΈπΊοΈ
Added in version 3.11. β¨
π SYNOPSIS π
Usage: gdal raster clip [OPTIONS] <INPUT> <OUTPUT>
Clip a raster dataset.
okay so that's the whole vibe, and here's every single knob you can turn, bestie π
π Positional arguments
-i,--input <INPUT>β the input raster datasets. Required, and π« not available in pipelines.-o,--output <OUTPUT>β the output raster dataset. Required, and π« not available in pipelines.
π«Ά Common Options
-h,--helpβ show the help message and dip π--json-usageβ print the usage as a JSON document and exit. very| jqof it π--config <KEY>=<VALUE>β configuration option. may be repeated π-q,--quietβ quiet mode: no progress bar, no warning messages. π« not available in pipelines.
π¦ Options
-f,--of,--format,--output-format <OUTPUT-FORMAT>β which output format to use ("GDALG"allowed π«’). π« not available in pipelines.--co,--creation-option <KEY>=<VALUE>β creation option. may be repeated π. π« not available in pipelines.--overwriteβ whether overwriting an existing output dataset is allowed. π« not available in pipelines. Mutually exclusive with--append.--appendβ append as a subdataset to an existing output. π« not available in pipelines. Mutually exclusive with--overwrite.--bbox <BBOX>β clipping bounding box, written asxmin,ymin,xmax,ymax. Mutually exclusive with--window,--geometry,--like.--bbox-crs <BBOX-CRS>β the CRS of that clipping bounding box π--window <WINDOW>β raster window ascol,line,width,height, in pixels. Mutually exclusive with--bbox,--geometry,--like.--geometry <GEOMETRY>β clipping geometry (WKT or GeoJSON). Mutually exclusive with--bbox,--window,--like.--geometry-crs <GEOMETRY-CRS>β the CRS of the clipping geometry π--like <DATASET>β a dataset to use as a template for the bounds. Mutually exclusive with--bbox,--window,--geometry.--like-sql <SELECT-STATEMENT>β a SELECT statement to run on the 'like' dataset. Mutually exclusive with--like-where.--like-layer <LAYER-NAME>β the name of the layer of the 'like' dataset.--like-where <WHERE-EXPRESSION>β a WHERE SQL clause to run on the 'like' dataset. Mutually exclusive with--like-sql.--only-bboxβ for'geometry'and'like', only consider their bounding box π¦--allow-bbox-outside-sourceβ allow the clipping box to include pixels outside the input dataset.--add-alphaβ adds an alpha mask band to the destination when the source raster has none. π«₯
π§ 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 πΈ
gdal raster clip can be used to clip a raster dataset using georeferenced coordinates. slay.
Either --bbox or --like must be specified. non-negotiable, bestie π«Ά
The output dataset is in the same SRS as the input one, and the original resolution is preserved. Bounds are rounded to match whole pixel locations β which is just a fancy way of saying there is no resampling involved. no glow-up for your pixels, they stay exactly as they were β¨
clip can also be used as a step of gdal raster pipeline. iconic honestly π
π PROGRAM-SPECIFIC OPTIONS π
--add-alphaβ Adds an alpha mask band to the destination when the source raster has none. π«₯--allow-bbox-outside-sourceβ If set, allows the bounds indicated by--bboxto cover an extent that is greater than the input dataset. Output pixels from areas beyond the input extent will be set to zero or the NoData value of the input dataset. π³οΈ--bbox <xmin>,<ymin>,<xmax>,<ymax>β Bounds to which to clip the dataset. They are assumed to be in the CRS of the input dataset, unless--bbox-crsis specified. The X and Y axis are the "GIS friendly ones" β that is, X is longitude or easting, and Y is latitude or northing. π The bounds are expanded if necessary to match input pixel boundaries. By default,gdal raster clipwill produce an error if the bounds indicated by--bboxare greater than the extents of the input dataset. This check can be bypassed using--allow-bbox-outside-source.--bbox-crs <CRS>β CRS in which the<xmin>,<ymin>,<xmax>,<ymax>values of--bboxare expressed. If not specified, it is assumed to be the CRS of the input dataset. π Note that specifying--bbox-crsdoes not cause the raster to be reprojected. Instead, the bounds are reprojected from the bbox-crs to the CRS of the input dataset. no cap.--geometry <WKT_or_GeoJSON>β Geometry as a WKT or GeoJSON string of a polygon (or multipolygon) to which to clip the dataset. Raster areas within the bounding box of the geometry but not inside the geometry itself will be set to the nodata value of the raster, or0if there is none. All pixels overlapping the geometry will be selected. βοΈ
If the input geometry is GeoJSON, its CRS is assumed to be WGS84, unless there is a CRS defined in the GeoJSON geometry or --geometry-crs is specified. If the input geometry is WKT, its CRS is assumed to be the one of the input dataset, unless --geometry-crs is specified. The X and Y axis are the "GIS friendly ones" β that is, X is longitude or easting, and Y is latitude or northing. π§ Mutually exclusive with --bbox and --like. pick one, bestie, you can't do both π
--geometry-crs <CRS>β CRS in which the coordinate values of--geometryare expressed. If not specified, it is assumed to be the CRS of the input dataset. The bounds are reprojected from the geometry-crs to the CRS of the input dataset. π--like <DATASET>β Vector or raster dataset to use as a template for bounds. If the specified dataset is a raster, its rectangular bounds are used as the clipping geometry. If the specified dataset is a vector dataset, its polygonal geometries are unioned together to form the clipping geometry. If several layers are present,--like-sqlor--like-layermust be specified. ποΈ Raster areas within the bounding box of the geometry but not inside the geometry itself will be set to the nodata value of the raster, or0if there is none. Mutually exclusive with--bboxand--geometry.--like-layer <LAYER-NAME>β Select the named layer from the vector clip dataset. Mutually exclusive with--like-sql. π―--like-sql <SELECT-STATEMENT>β Select desired geometries from the vector clip dataset using an SQL query. e.g.SELECT geom FROM my_layer WHERE country = 'France'. π«π· The SQL dialect used will be the default one of the like dataset (OGR SQL for Shapefile, SQLite for GeoPackage, PostgreSQL for PostGIS, etc.). Mutually exclusive with--like-layerand--like-where.--like-where <WHERE-EXPRESSION>β Restrict desired geometries from the vector clip dataset layer based on an attribute query. e.g.country = 'France'. πΊοΈ--only-bboxβ For--geometryand--like, only consider the bounding box of the geometry. π¦ that's it, that's the whole geometry now.--window <column>,<line>,<width>,<height>β Added in version 3.12. β¨
Selects a subwindow from the source image for copying based on pixel/line location. Pixel/line offsets (column and line) are measured from the left and top of the image. πΌοΈ If the subwindow extends beyond the bounds of the source dataset, output pixels will be written with a value of zero, unless a NoData value is defined either the source dataset.
π STANDARD OPTIONS π
--co,--creation-option <NAME>=<VALUE>β Many formats have one or more optional creation options that can be used to control particulars about the file created. For instance, the GeoTIFF driver supports creation options to 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. A list of options supported for a format can be listed with the --formats command line option but the documentation for the format is the definitive source of information on driver creation options. See Raster drivers format specific documentation for legal creation options for each format. π
--if,--input-format <format>β Format/driver name to be attempted to open the input file(s). It is generally not necessary to specify it, but it can be used to skip automatic driver detection, when it fails to select the appropriate driver. π This option can be repeated several times to specify 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. π
-f,--of,--format,--output-format <OUTPUT-FORMAT>β Which output raster format to use. Allowed values may be given bygdal --formats | grep raster | grep rw | sortπ₯οΈ--oo,--open-option <NAME>=<VALUE>β Dataset open option (format specific). π§
May be repeated. π
--overwriteβ Allow program to overwrite existing target file or dataset. Otherwise, by default,gdalerrors out if the target file or dataset already exists. no write pokey, it's taken π
β RETURN STATUS CODE β
The program returns status code 0 in case of success, and non-zero in case of error β where non-blocking errors emitted as warnings are considered as a successful execution. β
β
β¨ EXAMPLES β¨
okay bestie this is the part where it all clicks, fr fr. four whole scenarios, all of them slay π₯
πΈ Example 1: Clip a GeoTIFF file to the bounding box from longitude 2, latitude 49, to longitude 3, latitude 50 in WGS 84
$ gdal raster clip --bbox=2,49,3,50 --bbox-crs=EPSG:4326 in.tif out.tif --overwrite
classic. give it a --bbox, tell it what CRS those numbers live in with --bbox-crs, and it's giving crop-to-taste π
π¦ Example 2: Clip a GeoTIFF file using the bounds of reference.tif
$ gdal raster clip --like=reference.tif in.tif out.tif --overwrite
not me just copying someone else's whole extent with --like and calling it a personality. iconic behavior, no notes π
π§ Example 3: Clip a GeoTIFF file from raster column 1000 and line 2000, for a width of 500 pixels and a height of 600 pixels
$ gdal raster clip --window=1000,2000,500,600 in.tif out.tif --overwrite
pixel-exact windowing, literally so satisfying. column 1000, line 2000, then 500 pixels wide and 600 tall β the --window order is xoff,yoff,xsize,ysize and yes you WILL get it wrong the first time, we've all been there π«Ά
π Example 4: Clip a GeoTIFF using a bounding box extending beyond the source extent, and write the result as a COG
here's the plot twist: sometimes your bbox is just built different and hangs off the edge of the raster. that's an ERROR by default. Use --allow-bbox-outside-source to suppress the error ERROR 1: Computed source window -180 2943 6269 6235 falls partially outside source raster extent when the bounding box exceeds the raster extent.
like, look at her. she's screaming:
ERROR 1: Computed source window -180 2943 6269 6235 falls partially outside source raster extent
and if you're like "bestie I know it goes outside, that's the point", you hand her --allow-bbox-outside-source and she stops yelling. periodt.
$ gdal raster clip \
--bbox=3757032.814272985,-626172.1357121654,4383204.9499851465,0 \
--bbox-crs=EPSG:3857 \
--allow-bbox-outside-source \
in.tif out.tif \
--overwrite \
--output-format COG
also notice the line continuations β that's the backslash \ at the end of each line keeping it all one command, so it stays readable instead of being one cursed 300-character scroll. and we're writing a COG at the end via --output-format COG because obviously we are. main character output format β
π AUTHOR
Even Rouault <even.rouault@spatialys.com>
π COPYRIGHT
1998-2026
okay that's the whole page bestie, you made it to the end, I'm so proud π₯Ή this is from the GDAL Aug 18, 2026 manual, page GDAL-RASTER-CLIP(1) β go clip something cute, ily, mwah π
β¨π
π¦ 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