What Is Clipping?
Clipping cuts GeoJSON features to the boundary of a specified polygon or bounding box. Any geometry that falls outside the clip boundary is removed, and geometries that cross the boundary are trimmed to fit. The result contains only the portions of features that overlap with the clip region.
How to Use the Clip Tool
Provide the GeoJSON data you want to clip and a clipping polygon. The tool computes the intersection of each feature with the clip boundary and returns a new FeatureCollection containing only the clipped results.
Features entirely inside the clip boundary pass through unchanged. Features entirely outside are removed. Features that cross the boundary are split at the edge.
Trimming a Dataset to a Study Area
- Extracting features within a city or county boundary from a larger dataset
- Trimming a national dataset to a specific region of interest
- Cropping map data to a viewport or tile boundary
- Removing offshore data from a coastal dataset
Related spatial operations: turf.intersect() (overlap between two layers), andturf.difference() (subtract one layer from another).
Three Landmarks and a Midtown Box
Clip three NYC landmarks to a Midtown bounding rectangle. Use the landmarks as data input and the polygon below as the clip boundary:
GeoJSON{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": { "name": "Central Park" },
"geometry": { "type": "Point", "coordinates": [-73.9654, 40.7829] }
},
{
"type": "Feature",
"properties": { "name": "Times Square" },
"geometry": { "type": "Point", "coordinates": [-73.9855, 40.7580] }
},
{
"type": "Feature",
"properties": { "name": "Brooklyn Bridge" },
"geometry": { "type": "Point", "coordinates": [-73.9969, 40.7061] }
}
]
}Clip polygon covering Midtown (40th St to 60th St):
GeoJSON{
"type": "Feature",
"properties": { "name": "Midtown Clip" },
"geometry": {
"type": "Polygon",
"coordinates": [[[-74.01, 40.75], [-73.96, 40.75], [-73.96, 40.77], [-74.01, 40.77], [-74.01, 40.75]]]
}
}The result contains only Times Square, because it is the only point inside the Midtown clip boundary. Central Park is north of the clip region and Brooklyn Bridge is far south, both are excluded.
Two Different Operations, Reported Separately
Polygon features are intersected with the boundary through @turf/intersect, which computes new vertices where edges cross. That is a true clip against the outline.
Points and lines take a different path, because that intersection is areal and rejects them. They are handled against the boundary's bounding box instead: a point is kept if it falls inside the box, a line is trimmed to it. For a rectangular boundary the two paths agree. For a concave one they do not, so a point outside an L-shaped boundary but inside its box will be kept.
The tool states which path each feature took and how many fell outside entirely, so you never have to compare input and output counts yourself. GeometryCollection features are skipped and reported; split one into separate features first.