@@ -4333,50 +4333,80 @@ def clip_by_polygon(
4333
4333
drop_level0 : bool = True ,
4334
4334
drop_level1 : bool = True ,
4335
4335
) -> 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.
4337
4337
4338
4338
Parameters
4339
4339
__________
4340
4340
4341
4341
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.
4343
4343
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
4345
4359
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]])``.
4347
4361
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``.
4351
4365
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``.
4355
4369
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``.
4359
4373
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``.
4363
4377
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``.
4367
4381
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``.
4371
4385
4372
4386
Returns
4373
4387
_______
4374
4388
4375
4389
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
+ +----+-----------------------------+---------+---------+
4377
4405
4378
4406
.. versionadded:: 1.0.x
4379
4407
4408
+ .. versionchanged:: 1.2
4409
+
4380
4410
Example
4381
4411
_______
4382
4412
@@ -4385,12 +4415,21 @@ def clip_by_polygon(
4385
4415
>>> import geopandas as gpd
4386
4416
>>> gdf = gpd.read_file(filename='file.shp')
4387
4417
>>> 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
+
4394
4433
4395
4434
>>> # Returning the length of the original gdf
4396
4435
>>> len(gdf)
@@ -4405,12 +4444,20 @@ def clip_by_polygon(
4405
4444
>>> # Clipping data by the polygon
4406
4445
>>> gdf_clipped = gg.vector.clip_by_polygon(gdf=gdf, polygon=polygon)
4407
4446
>>> 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
+ +----+-----------------------------+---------+---------+
4414
4461
4415
4462
>>> # Returning the length of the clipped gdf
4416
4463
>>> len(gdf_clipped)
@@ -4419,10 +4466,9 @@ def clip_by_polygon(
4419
4466
See Also
4420
4467
________
4421
4468
4422
- clip_by_bbox : Clipping vector data with a bbox
4469
+ clip_by_bbox : Clip vector data with a bbox
4423
4470
4424
4471
"""
4425
-
4426
4472
# Checking if the gdf is of type GeoDataFrame
4427
4473
if not isinstance (gdf , gpd .geodataframe .GeoDataFrame ):
4428
4474
raise TypeError ("gdf must be of type GeoDataFrame" )
0 commit comments