Skip to content

Commit 4235824

Browse files
Format clip_by_polygon
1 parent 70296a0 commit 4235824

File tree

1 file changed

+83
-37
lines changed

1 file changed

+83
-37
lines changed

gemgis/vector.py

Lines changed: 83 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4333,50 +4333,80 @@ def clip_by_polygon(
43334333
drop_level0: bool = True,
43344334
drop_level1: bool = True,
43354335
) -> gpd.geodataframe.GeoDataFrame:
4336-
"""Clipping vector data contained in a GeoDataFrame to a provided bounding box/extent
4336+
"""Clip vector data contained in a GeoDataFrame to a provided bounding box/extent.
43374337
43384338
Parameters
43394339
__________
43404340
43414341
gdf : gpd.geodataframe.GeoDataFrame
4342-
GeoDataFrame containing vector data that will be clipped to a provided bounding box/extent
4342+
GeoDataFrame containing vector data that will be clipped to a provided bounding box/extent.
43434343
4344-
polygon : polygon: shapely.geometry.polygon
4344+
+----+-----------------------------+
4345+
| ID | geometry |
4346+
+----+-----------------------------+
4347+
| 0 | POINT (281.526 902.087) |
4348+
+----+-----------------------------+
4349+
| 1 | POINT (925.867 618.577) |
4350+
+----+-----------------------------+
4351+
| 2 | POINT (718.131 342.799) |
4352+
+----+-----------------------------+
4353+
| 3 | POINT (331.011 255.684) |
4354+
+----+-----------------------------+
4355+
| 4 | POINT (300.083 600.535) |
4356+
+----+-----------------------------+
4357+
4358+
polygon : shapely.geometry.Polygon
43454359
Shapely Polygon defining the extent of the data,
4346-
e.g. ``polygon = Polygon([[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]])``
4360+
e.g. ``polygon = Polygon([[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]])``.
43474361
4348-
reset_index : bool
4349-
Variable to reset the index of the resulting GeoDataFrame.
4350-
Options include: ``True`` or ``False``, default set to ``True``
4362+
reset_index : bool, default: ``True``
4363+
Variable to reset the index of the resulting GeoDataFrame, e.g. ``reset_index=True``.
4364+
Options include: ``True`` or ``False``, default set to ``True``.
43514365
4352-
drop_level0 : bool
4353-
Variable to drop the level_0 column.
4354-
Options include: ``True`` or ``False``, default set to ``True``
4366+
drop_level0 : bool, default: ``True``
4367+
Variable to drop the level_0 column, e.g. ``drop_level0=True``.
4368+
Options include: ``True`` or ``False``, default set to ``True``.
43554369
4356-
drop_level1 : bool
4357-
Variable to drop the level_1 column.
4358-
Options include: ``True`` or ``False``, default set to ``True``
4370+
drop_level1 : bool, default: ``True``
4371+
Variable to drop the level_1 column, e.g. ``drop_level1=True``.
4372+
Options include: ``True`` or ``False``, default set to ``True``.
43594373
4360-
drop_index : bool
4361-
Variable to drop the index column.
4362-
Options include: ``True`` or ``False``, default set to ``True``
4374+
drop_index : bool, default: ``True``
4375+
Variable to drop the index column, e.g. ``drop_index=True``.
4376+
Options include: ``True`` or ``False``, default set to ``True``.
43634377
4364-
drop_id : bool
4365-
Variable to drop the id column.
4366-
Options include: ``True`` or ``False``, default set to ``True``
4378+
drop_id : bool, default: ``True``
4379+
Variable to drop the id column, e.g. ``drop_id=True``.
4380+
Options include: ``True`` or ``False``, default set to ``True``.
43674381
4368-
drop_points : bool
4369-
Variable to drop the points column.
4370-
Options include: ``True`` or ``False``, default set to ``True``
4382+
drop_points : bool, default: ``True``
4383+
Variable to drop the points column, e.g. ``drop_points=True``.
4384+
Options include: ``True`` or ``False``, default set to ``True``.
43714385
43724386
Returns
43734387
_______
43744388
43754389
gdf : gpd.geodataframe.GeoDataFrame
4376-
GeoDataFrame containing vector data clipped by a bounding box
4390+
GeoDataFrame containing vector data clipped by a bounding box.
4391+
4392+
+----+-----------------------------+---------+---------+
4393+
| | geometry | X | Y |
4394+
+----+-----------------------------+---------+---------+
4395+
| 0 | POINT (281.526 902.087) | 281.53 | 902.09 |
4396+
+----+-----------------------------+---------+---------+
4397+
| 1 | POINT (925.867 618.577) | 925.87 | 618.58 |
4398+
+----+-----------------------------+---------+---------+
4399+
| 2 | POINT (718.131 342.799) | 718.13 | 342.80 |
4400+
+----+-----------------------------+---------+---------+
4401+
| 3 | POINT (331.011 255.684) | 331.01 | 255.68 |
4402+
+----+-----------------------------+---------+---------+
4403+
| 4 | POINT (300.083 600.535) | 300.08 | 600.54 |
4404+
+----+-----------------------------+---------+---------+
43774405
43784406
.. versionadded:: 1.0.x
43794407
4408+
.. versionchanged:: 1.2
4409+
43804410
Example
43814411
_______
43824412
@@ -4385,12 +4415,21 @@ def clip_by_polygon(
43854415
>>> import geopandas as gpd
43864416
>>> gdf = gpd.read_file(filename='file.shp')
43874417
>>> gdf
4388-
id geometry
4389-
0 None POINT (281.526 902.087)
4390-
1 None POINT (925.867 618.577)
4391-
2 None POINT (718.131 342.799)
4392-
3 None POINT (331.011 255.684)
4393-
4 None POINT (300.083 600.535)
4418+
4419+
+----+-----------------------------+
4420+
| ID | geometry |
4421+
+----+-----------------------------+
4422+
| 0 | POINT (281.526 902.087) |
4423+
+----+-----------------------------+
4424+
| 1 | POINT (925.867 618.577) |
4425+
+----+-----------------------------+
4426+
| 2 | POINT (718.131 342.799) |
4427+
+----+-----------------------------+
4428+
| 3 | POINT (331.011 255.684) |
4429+
+----+-----------------------------+
4430+
| 4 | POINT (300.083 600.535) |
4431+
+----+-----------------------------+
4432+
43944433
43954434
>>> # Returning the length of the original gdf
43964435
>>> len(gdf)
@@ -4405,12 +4444,20 @@ def clip_by_polygon(
44054444
>>> # Clipping data by the polygon
44064445
>>> gdf_clipped = gg.vector.clip_by_polygon(gdf=gdf, polygon=polygon)
44074446
>>> gdf_clipped
4408-
geometry X Y
4409-
0 POINT (281.526 902.087) 281.53 902.09
4410-
1 POINT (925.867 618.577) 925.87 618.58
4411-
2 POINT (718.131 342.799) 718.13 342.80
4412-
3 POINT (331.011 255.684) 331.01 255.68
4413-
4 POINT (300.083 600.535) 300.08 600.54
4447+
4448+
+----+-----------------------------+---------+---------+
4449+
| | geometry | X | Y |
4450+
+----+-----------------------------+---------+---------+
4451+
| 0 | POINT (281.526 902.087) | 281.53 | 902.09 |
4452+
+----+-----------------------------+---------+---------+
4453+
| 1 | POINT (925.867 618.577) | 925.87 | 618.58 |
4454+
+----+-----------------------------+---------+---------+
4455+
| 2 | POINT (718.131 342.799) | 718.13 | 342.80 |
4456+
+----+-----------------------------+---------+---------+
4457+
| 3 | POINT (331.011 255.684) | 331.01 | 255.68 |
4458+
+----+-----------------------------+---------+---------+
4459+
| 4 | POINT (300.083 600.535) | 300.08 | 600.54 |
4460+
+----+-----------------------------+---------+---------+
44144461
44154462
>>> # Returning the length of the clipped gdf
44164463
>>> len(gdf_clipped)
@@ -4419,10 +4466,9 @@ def clip_by_polygon(
44194466
See Also
44204467
________
44214468
4422-
clip_by_bbox : Clipping vector data with a bbox
4469+
clip_by_bbox : Clip vector data with a bbox
44234470
44244471
"""
4425-
44264472
# Checking if the gdf is of type GeoDataFrame
44274473
if not isinstance(gdf, gpd.geodataframe.GeoDataFrame):
44284474
raise TypeError("gdf must be of type GeoDataFrame")

0 commit comments

Comments
 (0)