Skip to content

Commit 2df1ec3

Browse files
Format extract_xyz_rasterio
1 parent 58c82bf commit 2df1ec3

File tree

1 file changed

+83
-50
lines changed

1 file changed

+83
-50
lines changed

gemgis/vector.py

Lines changed: 83 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,60 +1477,76 @@ def extract_xyz_rasterio(
14771477
remove_total_bounds: bool = False,
14781478
threshold_bounds: Union[float, int] = 0.1,
14791479
) -> gpd.geodataframe.GeoDataFrame:
1480-
"""Extracting X and Y coordinates from a GeoDataFrame (Points, LineStrings, MultiLineStrings Polygons) and z values
1481-
from a rasterio object and returning a GeoDataFrame with X, Y, and Z coordinates as additional columns
1480+
"""Extract X and Y coordinates from a GeoDataFrame (Points, LineStrings, MultiLineStrings Polygons) and z values
1481+
from a rasterio object and returning a GeoDataFrame with X, Y, and Z coordinates as additional columns.
14821482
14831483
Parameters
14841484
__________
14851485
14861486
gdf : gpd.geodataframe.GeoDataFrame
1487-
GeoDataFrame created from vector data containing Shapely Points, LineStrings, MultiLineStrings or Polygons
1487+
GeoDataFrame created from vector data containing Shapely Points, LineStrings, MultiLineStrings or Polygons.
1488+
1489+
+----+-----------+------------------------+
1490+
| | formation | geometry |
1491+
+----+-----------+------------------------+
1492+
| 0 | Ton | POINT (19.150 293.313) |
1493+
+----+-----------+------------------------+
1494+
| 1 | Ton | POINT (61.934 381.459) |
1495+
+----+-----------+------------------------+
1496+
| 2 | Ton | POINT (109.358 480.946)|
1497+
+----+-----------+------------------------+
1498+
| 3 | Ton | POINT (157.812 615.999)|
1499+
+----+-----------+------------------------+
1500+
| 4 | Ton | POINT (191.318 719.094)|
1501+
+----+-----------+------------------------+
14881502
14891503
dem : rasterio.io.DatasetReader
1490-
Rasterio object containing the height values
1504+
Rasterio object containing the height values.
14911505
1492-
minz : float
1493-
Value defining the minimum elevation the data needs to be returned, e.g. ``minz=50``, default ``None``
1506+
minz : float, default: ``None``
1507+
Value defining the minimum elevation the data needs to be returned, e.g. ``minz=50``, default ``None``.
14941508
1495-
maxz : float
1496-
Value defining the maximum elevation the data needs to be returned, e.g. ``maxz=500``, default ``None``
1509+
maxz : float, default: ``None``
1510+
Value defining the maximum elevation the data needs to be returned, e.g. ``maxz=500``, default ``None```.
14971511
1498-
reset_index : bool
1499-
Variable to reset the index of the resulting GeoDataFrame, default ``True``
1512+
reset_index : bool, default: ``True``
1513+
Variable to reset the index of the resulting GeoDataFrame, e.g. ``reset_index=True``.
1514+
Options include: ``True`` or ``False``, default set to ``True``.
15001515
1501-
drop_level0 : bool
1502-
Variable to drop the level_0 column.
1503-
Options include: ``True`` or ``False``, default set to ``True``
1516+
drop_level0 : bool, default: ``True``
1517+
Variable to drop the level_0 column, e.g. ``drop_level0=True``.
1518+
Options include: ``True`` or ``False``, default set to ``True``.
15041519
1505-
drop_level1 : bool
1506-
Variable to drop the level_1 column.
1507-
Options include: ``True`` or ``False``, default set to ``True``
1520+
drop_level1 : bool, default: ``True``
1521+
Variable to drop the level_1 column, e.g. ``drop_level1=True``.
1522+
Options include: ``True`` or ``False``, default set to ``True``.
15081523
1509-
drop_index : bool
1510-
Variable to drop the index column.
1511-
Options include: ``True`` or ``False``, default set to ``True``
1524+
drop_index : bool, default: ``True``
1525+
Variable to drop the index column, e.g. ``drop_index=True``.
1526+
Options include: ``True`` or ``False``, default set to ``True``.
15121527
1513-
drop_id : bool
1528+
drop_id : bool, default: ``True``
15141529
Variable to drop the id column.
1515-
Options include: ``True`` or ``False``, default set to ``True``
1530+
Options include: ``True`` or ``False``, default set to ``True``.
15161531
1517-
drop_points : bool
1518-
Variable to drop the points column.
1519-
Options include: ``True`` or ``False``, default set to ``True``
1532+
drop_points : bool, default: ``True``
1533+
Variable to drop the points column, e.g. ``drop_points=True``.
1534+
Options include: ``True`` or ``False``, default set to ``True``.
15201535
1521-
target_crs : Union[str, pyproj.crs.crs.CRS, rasterio.crs.CRS]
1522-
Name of the CRS provided to reproject coordinates of the GeoDataFrame, e.g. ``target_crs='EPSG:4647'``
1536+
target_crs : Union[str, pyproj.crs.crs.CRS, rasterio.crs.CRS], default: ``None``
1537+
Name of the CRS provided to reproject coordinates of the GeoDataFrame, e.g. ``target_crs='EPSG:4647'``.
15231538
1524-
bbox : list
1525-
Values (minx, maxx, miny, maxy) to limit the extent of the data, e.g. ``bbox=[0, 972, 0, 1069]``
1539+
bbox : list, default: ``None``
1540+
Values (minx, maxx, miny, maxy) to limit the extent of the data, e.g. ``bbox=[0, 972, 0, 1069]``.
15261541
1527-
remove_total_bounds: bool
1528-
Variable to remove the vertices representing the total bounds of a GeoDataFrame consisting of Polygons
1529-
Options include: ``True`` or ``False``, default set to ``False``
1542+
remove_total_bounds: bool, default: ``False``
1543+
Variable to remove the vertices representing the total bounds of a GeoDataFrame consisting of Polygons,
1544+
e.g. ``remove_total_bounds=False``.
1545+
Options include: ``True`` or ``False``, default set to ``False``.
15301546
1531-
threshold_bounds : Union[float, int]
1532-
Variable to set the distance to the total bound from where vertices are being removed,
1533-
e.g. ``threshold_bounds=10``, default set to ``0.1``
1547+
threshold_bounds : Union[float, int], default: ``0.1``
1548+
Variable to set the distance to the total bounds from where vertices are being removed,
1549+
e.g. ``threshold_bounds=10``, default set to ``0.1``.
15341550
15351551
Returns
15361552
_______
@@ -1549,12 +1565,21 @@ def extract_xyz_rasterio(
15491565
>>> import rasterio
15501566
>>> gdf = gpd.read_file(filename='file.shp')
15511567
>>> gdf
1552-
id formation geometry
1553-
0 None Ton POINT (19.150 293.313)
1554-
1 None Ton POINT (61.934 381.459)
1555-
2 None Ton POINT (109.358 480.946)
1556-
3 None Ton POINT (157.812 615.999)
1557-
4 None Ton POINT (191.318 719.094)
1568+
1569+
+----+-----------+------------------------+
1570+
| | formation | geometry |
1571+
+----+-----------+------------------------+
1572+
| 0 | Ton | POINT (19.150 293.313) |
1573+
+----+-----------+------------------------+
1574+
| 1 | Ton | POINT (61.934 381.459) |
1575+
+----+-----------+------------------------+
1576+
| 2 | Ton | POINT (109.358 480.946)|
1577+
+----+-----------+------------------------+
1578+
| 3 | Ton | POINT (157.812 615.999)|
1579+
+----+-----------+------------------------+
1580+
| 4 | Ton | POINT (191.318 719.094)|
1581+
+----+-----------+------------------------+
1582+
15581583
15591584
>>> # Loading raster file
15601585
>>> dem = rasterio.open(fp='dem.tif')
@@ -1564,21 +1589,29 @@ def extract_xyz_rasterio(
15641589
>>> # Extracting X, Y, and Z Coordinates from Shapely Base Geometries and raster
15651590
>>> gdf_xyz = gg.vector.extract_xyz_rasterio(gdf=gdf, dem=dem, reset_index=reset_index)
15661591
>>> gdf_xyz
1567-
formation geometry X Y Z
1568-
0 Ton POINT (19.150 293.313) 19.15 293.31 364.99
1569-
1 Ton POINT (61.934 381.459) 61.93 381.46 400.34
1570-
2 Ton POINT (109.358 480.946) 109.36 480.95 459.55
1571-
3 Ton POINT (157.812 615.999) 157.81 616.00 525.69
1572-
4 Ton POINT (191.318 719.094) 191.32 719.09 597.63
1592+
1593+
+----+-----------+------------------------+-------+-------+-------+
1594+
| ID | formation | geometry | X | Y | Z |
1595+
+----+-----------+------------------------+-------+-------+-------+
1596+
| 0 | Ton | POINT (19.150 293.313) | 19.15 | 293.31| 364.99|
1597+
+----+-----------+------------------------+-------+-------+-------+
1598+
| 1 | Ton | POINT (61.934 381.459) | 61.93 | 381.46| 400.34|
1599+
+----+-----------+------------------------+-------+-------+-------+
1600+
| 2 | Ton | POINT (109.358 480.946)| 109.36| 480.95| 459.55|
1601+
+----+-----------+------------------------+-------+-------+-------+
1602+
| 3 | Ton | POINT (157.812 615.999)| 157.81| 616.00| 525.69|
1603+
+----+-----------+------------------------+-------+-------+-------+
1604+
| 4 | Ton | POINT (191.318 719.094)| 191.32| 719.09| 597.63|
1605+
+----+-----------+------------------------+-------+-------+-------+
1606+
15731607
15741608
See Also
15751609
________
15761610
1577-
extract_xyz_array : Extracting X, Y, and Z coordinates from a GeoDataFrame and Digital Elevation Model as array
1578-
extract_xyz : Extracting X, Y, and Z coordinates from a GeoDataFrame and Digital Elevation Model
1611+
extract_xyz : Extract X, Y, and Z coordinates from a GeoDataFrame and Digital Elevation Model
1612+
extract_xyz_array : Extract X, Y, and Z coordinates from a GeoDataFrame and Digital Elevation Model as array
15791613
15801614
"""
1581-
15821615
# Checking that the input data is of type GeoDataFrame
15831616
if not isinstance(gdf, gpd.geodataframe.GeoDataFrame):
15841617
raise TypeError("Loaded object is not a GeoDataFrame")
@@ -1725,7 +1758,7 @@ def extract_xyz_rasterio(
17251758

17261759
# Extracting the X and Y coordinates of the reprojected gdf
17271760
gdf = extract_xy(
1728-
gdf,
1761+
gdf=gdf,
17291762
reset_index=False,
17301763
drop_index=False,
17311764
drop_id=False,

0 commit comments

Comments
 (0)