- GeoSeries.clip(mask, keep_geom_type=False)¶
Clip points, lines, or polygon geometries to the mask extent.
Both layers must be in the same Coordinate Reference System (CRS). The GeoSeries will be clipped to the full extent of the mask object.
If there are multiple polygons in mask, data from the GeoSeries will be clipped to the total boundary of all polygons in mask.
- maskGeoDataFrame, GeoSeries, (Multi)Polygon, list-like
Polygon vector layer used to clip gdf. The mask’s geometry is dissolved into one geometric feature and intersected with GeoSeries. If the mask is list-like with four elements
(minx, miny, maxx, maxy),
clipwill use a faster rectangle clipping (
clip_by_rect()), possibly leading to slightly different results.
- keep_geom_typeboolean, default False
If True, return only geometries of original type in case of intersection resulting in multiple geometry types or GeometryCollections. If False, return all resulting geometries (potentially mixed-types).
Vector data (points, lines, polygons) from gdf clipped to polygon boundary from mask.
top-level function for clip
Clip points (global cities) with a polygon (the South American continent):
>>> world = geopandas.read_file( ... geopandas.datasets.get_path('naturalearth_lowres')) >>> south_america = world[world['continent'] == "South America"] >>> capitals = geopandas.read_file( ... geopandas.datasets.get_path('naturalearth_cities')) >>> capitals.shape (202, 2)
>>> sa_capitals = capitals.geometry.clip(south_america) >>> sa_capitals.shape (12,)