Clip Raster by Polygon
Clip raster data to a polygon boundary
What Is Raster Clipping?
Raster clipping β also called raster cropping, raster masking or "clip raster by polygon" β is the operation of trimming a raster dataset to the extent of a polygon (or set of polygons). The output is a new raster that contains only the pixels falling inside the clip geometry; everything outside is replaced with nodata or removed entirely. Clipping is one of the most common preprocessing steps in any raster workflow because most analyses care about a specific area of interest (AOI), not the full satellite tile or DEM extent.
The Clip Raster by Polygon tool on gis.tools loads a GeoTIFF and a vector polygon (GeoJSON, KML, Shapefile or drawn on the map), then crops the raster to the polygon boundary in the browser. People search for "clip raster by polygon", "raster clipping gis", "crop geotiff to shapefile", "extract by mask raster" and "qgis clip raster" because this is one of the most heavily used operations in QGIS Processing, ArcGIS Spatial Analyst (Extract by Mask) and the GDAL command line (gdalwarp -cutline).
Clipping is conceptually simple but operationally important: removing irrelevant pixels speeds up downstream calculations, reduces file sizes, sharpens cartographic output and prevents bias in statistics like mean elevation or NDVI within an AOI.
How Raster Clipping Works
Two operations happen during a clip: a bounding-box crop and a per-pixel mask test.
Step 1: Bounding-Box Crop
The tool computes the rectangular extent of the clip polygon in the raster's CRS, then extracts the sub-array of the raster that intersects that bounding box. This first step alone shrinks the raster from a full scene to a small rectangle and is sometimes all you need.
Step 2: Pixel-by-Pixel Mask Test
For each cell in the cropped sub-array, the tool tests whether the cell's centre lies inside the clip polygon. Cells inside keep their original value; cells outside are set to nodata. The point-in-polygon test uses the standard winding-number or even-odd rule used by Turf.js, JTS and Shapely.
Two Modes: Crop-to-Cutline and Mask-Only
- Crop to cutline: the output raster bounds shrink to the polygon's bounding box. Saves disk space and speeds downstream processing.
- Mask only: the output raster keeps the original bounds but pixels outside the polygon are nodata. Useful when you need to preserve the original grid alignment.
GDAL's gdalwarp -cutline -crop_to_cutline performs the first; gdalwarp -cutline alone performs the second.
Multi-Polygon Clipping
If your clip layer has multiple polygons, the tool unions them implicitly: a pixel is kept if it lies inside any of the polygons. You can also clip to one polygon at a time and produce separate outputs.
Key Parameters and Options
Clip Geometry
A polygon or multi-polygon vector layer in any format the gis.tools loader accepts: GeoJSON, KML, Shapefile, GPKG. You can also draw the polygon on the map with the Draw Points/Lines/Polygons tool.
Crop to Cutline
Toggle on to shrink the output bounds to the clip extent. Toggle off to preserve the original raster bounds.
Inverted Clip
Some workflows want everything outside the polygon (a "donut hole" mask). The tool offers an invert option that swaps the inside and outside of the polygon.
Touched vs Centred Pixel Inclusion
Decide whether a pixel is kept when its centre is inside the polygon (centroid rule) or whenever any part of the pixel touches the polygon (touched rule). The touched rule retains a 1-pixel border outside the polygon β useful for visualisation, less useful for statistics.
Output Nodata Value
Specify the nodata sentinel for masked cells. The tool defaults to the raster's existing nodata or to a sensible value for the data type.
CRS Handling
If the polygon and raster have different CRSes, the polygon is reprojected to the raster's CRS before clipping.
Practical Applications
Watershed Extraction
A hydrologist downloads a continental-scale DEM and clips it to a single watershed boundary derived from a flow accumulation analysis. The clipped DEM feeds downstream watershed modelling, runoff estimation and flood modelling β all of which would be impossibly slow on the full continental tile.
Sentinel-2 AOI Extraction
A precision-agriculture analyst downloads a full 100 km x 100 km Sentinel-2 tile and clips it to an individual farm boundary before computing NDVI. The 99% of the tile that is not the farm gets discarded, saving memory and runtime.
Country and Administrative Clipping
A national mapping agency clips global Landsat mosaics to its country boundary to produce a national imagery product. Official outputs only contain pixels inside national borders.
Urban Heat Island Studies
A climate scientist clips a thermal raster to the boundary of a city to compute mean land surface temperature inside vs outside the urban footprint, then maps the heat island intensity.
Conservation Area Monitoring
A protected-area manager clips an annual land-cover product to a national park boundary to track changes in forest cover, agricultural encroachment and settlement growth inside the park.
Geological Mapping
A field geologist clips a regional geophysical raster (gravity, magnetics, radiometrics) to a survey block before interpretation, removing extraneous data outside the project area.
Cartographic Production
A cartographer clips a hillshade or hypsometric tint to the boundary of a printed map sheet to keep the output rectangular and free of bleeding pixels along irregular edges.
Step-by-Step Workflow in gis.tools
- Open the Clip Raster by Polygon page on gis.tools.
- Drag a GeoTIFF into the raster slot. The file is decoded locally with
geotiff.js. - Drag a polygon vector file (GeoJSON, KML, Shapefile, GPKG) into the polygon slot, or draw a polygon directly on the map.
- The tool checks CRS compatibility and reprojects the polygon to the raster CRS if needed.
- Choose crop-to-cutline or mask-only, plus pixel inclusion mode (centroid or touched).
- Click Clip. The tool computes the bounding box, extracts the sub-array and applies the mask test.
- Preview the clipped raster on the map. Verify that the boundary lines up with the polygon.
- Export the result as a GeoTIFF (preserving CRS, georeferencing and nodata) for downstream use.
- Chain into NDVI Calculator, Zonal Statistics or Hillshade Generator on the clipped output.
Worked Example: Clipping a Landsat NDVI to a Vineyard
You have a Landsat 9 NDVI raster covering Sonoma County, California, and a GeoJSON file with a vineyard boundary polygon (about 80 hectares). The full NDVI tile is 7800x7900 Float32 pixels (~250 MB in memory). You drop both files into the Clip Raster by Polygon tool. The tool detects the polygon is in WGS84 and the NDVI is in UTM 10N, reprojects the polygon, computes the bounding box (about 1100x900 pixels), and runs the mask. Crop-to-cutline is on. Within a couple of seconds you have a tight 1100x900 NDVI raster covering just the vineyard, with everything outside set to nodata. You export the clipped GeoTIFF and feed it into Zonal Statistics to compute mean NDVI per management block β a job that would have taken much longer on the full uncropped scene.
Common Pitfalls and Gotchas
- CRS mismatch is the most common error: confirm both layers share a CRS before clipping, or let the tool reproject.
- Polygons with self-intersections, slivers or unclosed rings can crash the clip β fix them first with GeoJSON Validator & Fixer or Geometry Repair.
- The centroid rule can drop edge pixels that visually overlap the polygon; the touched rule keeps them but may introduce a one-pixel halo in statistics.
- Multi-polygon clip layers union implicitly; if you want one output per polygon, clip iteratively.
- Crop-to-cutline aligns the new bounds to the original pixel grid, not to the polygon corners β the output is slightly larger than the polygon's bounding box.
- Floating-point rasters with NaN nodata may need explicit nodata configuration.
- Edge effects: any pixel that straddles the polygon boundary contains a mix of inside and outside ground. For high-precision statistics consider buffering the polygon inward.
- Very small polygons (smaller than one pixel) may produce empty outputs.
Tips for Best Results
- Reproject the polygon to the raster's CRS rather than the other way around β reprojecting a vector is fast and lossless.
- Use crop-to-cutline whenever you do not need the original grid alignment β it saves memory and disk space.
- For statistics use the centroid rule (default) to avoid double-counting edge pixels.
- Validate the polygon geometry before clipping with GeoJSON Validator & Fixer.
- If your polygon has many features, dissolve them with GIS Dissolve Tool (Merge by Field) first to reduce overhead.
- Always check that the clipped raster preserves the original CRS and nodata value.
- For very large rasters, clip first and then run any downstream operation rather than the reverse.
- Use Raster Value Probe on the clipped output to spot-check pixel values.
Comparison with Other GIS Approaches
GDAL's gdalwarp -cutline polygon.shp -crop_to_cutline -dstnodata -9999 input.tif output.tif is the canonical command-line implementation. ArcGIS Spatial Analyst's Extract by Mask and QGIS's "Clip raster by mask layer" tool wrap the same operation behind a graphical interface. In Python, rasterio + shapely provides full programmatic control. The Clip Raster by Polygon tool on gis.tools delivers identical semantics in the browser without an install. The trade-off is that the entire raster must fit in browser memory; multi-tile workflows are still better suited to GDAL or Python.
Performance Considerations
Clipping is O(n) in the number of pixels in the bounding box, plus O(p) where p is the polygon vertex count for the point-in-polygon test. The point-in-polygon test is by far the more expensive part for complex polygons. For 4000x4000 pixel rasters and polygons with up to a few thousand vertices, the operation runs in under a second. Larger polygons or rasters should be downsampled with Raster Resampler before clipping.
Data Privacy and Browser-Based Processing
Both your raster and your polygon stay in the browser. The File API reads each file, the GeoTIFF and vector parsers run locally, and the clip operation executes in JavaScript with WebAssembly acceleration. Nothing is uploaded. This matters for proprietary survey rasters, classified terrain models, sensitive boundary polygons (private land, military installations) and any workflow with strict data residency requirements.
Related GIS Concepts
Bounding-Box Crop: A pure rectangular crop without any polygon mask. The first step inside any clip operation.
Cookie-Cutter: A colloquial term for raster clipping by polygon, derived from the visual analogy.
Extract by Mask: ArcGIS terminology for the same operation.
Cutline: GDAL terminology for the polygon used in gdalwarp -cutline.
Erase / Difference: The vector analog of an inverted clip β keeps the parts of the input outside the mask. See Erase / Difference Tool.
Frequently Asked Questions
What is the difference between clipping and masking?
Clipping shrinks the raster to the polygon bounds; masking sets pixels outside the polygon to nodata while keeping the original extent. Most tools call both operations "clip" with a "crop to cutline" toggle.
Can I clip with multiple polygons at once?
Yes β multi-polygon clip layers are unioned implicitly. To produce separate outputs per polygon, clip iteratively.
What happens if the polygon and raster CRS differ?
The tool reprojects the polygon to the raster's CRS automatically.
Can I clip a multi-band raster?
Yes β all bands are clipped consistently, keeping the same band order and nodata values.
Why are there nodata pixels along the polygon boundary?
The pixel-inclusion test uses the cell centre by default. Pixels whose centres fall just outside the polygon boundary become nodata. Switch to the touched rule to retain them.
Can I export the clipped output as a Cloud-Optimized GeoTIFF?
Yes β the tool offers a COG export option that adds internal tiling and overviews.
Related Tools on gis.tools
Related Tools
View All ToolsGeoTIFF Viewer
View GeoTIFF bands with nodata handling and min/max stretch
Raster ToolsRaster to Contours
Generate contour lines from raster elevation data
Raster ToolsRaster Mosaic Preview
Preview multiple raster tiles as a single view
Raster ToolsSlope/Aspect Calculator
Calculate slope and aspect from elevation data
Raster ToolsRaster Value Probe
Click to sample raster values at any location
Raster ToolsRaster Reclass Tool
Reclassify raster values based on custom rules
Raster Tools100% client-side processing - your data stays private and never leaves your device