Skip to content

Commit

Permalink
Format extract_xyz_rasterio
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderJuestel committed Jul 27, 2024
1 parent 58c82bf commit 2df1ec3
Showing 1 changed file with 83 additions and 50 deletions.
133 changes: 83 additions & 50 deletions gemgis/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1477,60 +1477,76 @@ def extract_xyz_rasterio(
remove_total_bounds: bool = False,
threshold_bounds: Union[float, int] = 0.1,
) -> gpd.geodataframe.GeoDataFrame:
"""Extracting X and Y coordinates from a GeoDataFrame (Points, LineStrings, MultiLineStrings Polygons) and z values
from a rasterio object and returning a GeoDataFrame with X, Y, and Z coordinates as additional columns
"""Extract X and Y coordinates from a GeoDataFrame (Points, LineStrings, MultiLineStrings Polygons) and z values
from a rasterio object and returning a GeoDataFrame with X, Y, and Z coordinates as additional columns.
Parameters
__________
gdf : gpd.geodataframe.GeoDataFrame
GeoDataFrame created from vector data containing Shapely Points, LineStrings, MultiLineStrings or Polygons
GeoDataFrame created from vector data containing Shapely Points, LineStrings, MultiLineStrings or Polygons.
+----+-----------+------------------------+
| | formation | geometry |
+----+-----------+------------------------+
| 0 | Ton | POINT (19.150 293.313) |
+----+-----------+------------------------+
| 1 | Ton | POINT (61.934 381.459) |
+----+-----------+------------------------+
| 2 | Ton | POINT (109.358 480.946)|
+----+-----------+------------------------+
| 3 | Ton | POINT (157.812 615.999)|
+----+-----------+------------------------+
| 4 | Ton | POINT (191.318 719.094)|
+----+-----------+------------------------+
dem : rasterio.io.DatasetReader
Rasterio object containing the height values
Rasterio object containing the height values.
minz : float
Value defining the minimum elevation the data needs to be returned, e.g. ``minz=50``, default ``None``
minz : float, default: ``None``
Value defining the minimum elevation the data needs to be returned, e.g. ``minz=50``, default ``None``.
maxz : float
Value defining the maximum elevation the data needs to be returned, e.g. ``maxz=500``, default ``None``
maxz : float, default: ``None``
Value defining the maximum elevation the data needs to be returned, e.g. ``maxz=500``, default ``None```.
reset_index : bool
Variable to reset the index of the resulting GeoDataFrame, default ``True``
reset_index : bool, default: ``True``
Variable to reset the index of the resulting GeoDataFrame, e.g. ``reset_index=True``.
Options include: ``True`` or ``False``, default set to ``True``.
drop_level0 : bool
Variable to drop the level_0 column.
Options include: ``True`` or ``False``, default set to ``True``
drop_level0 : bool, default: ``True``
Variable to drop the level_0 column, e.g. ``drop_level0=True``.
Options include: ``True`` or ``False``, default set to ``True``.
drop_level1 : bool
Variable to drop the level_1 column.
Options include: ``True`` or ``False``, default set to ``True``
drop_level1 : bool, default: ``True``
Variable to drop the level_1 column, e.g. ``drop_level1=True``.
Options include: ``True`` or ``False``, default set to ``True``.
drop_index : bool
Variable to drop the index column.
Options include: ``True`` or ``False``, default set to ``True``
drop_index : bool, default: ``True``
Variable to drop the index column, e.g. ``drop_index=True``.
Options include: ``True`` or ``False``, default set to ``True``.
drop_id : bool
drop_id : bool, default: ``True``
Variable to drop the id column.
Options include: ``True`` or ``False``, default set to ``True``
Options include: ``True`` or ``False``, default set to ``True``.
drop_points : bool
Variable to drop the points column.
Options include: ``True`` or ``False``, default set to ``True``
drop_points : bool, default: ``True``
Variable to drop the points column, e.g. ``drop_points=True``.
Options include: ``True`` or ``False``, default set to ``True``.
target_crs : Union[str, pyproj.crs.crs.CRS, rasterio.crs.CRS]
Name of the CRS provided to reproject coordinates of the GeoDataFrame, e.g. ``target_crs='EPSG:4647'``
target_crs : Union[str, pyproj.crs.crs.CRS, rasterio.crs.CRS], default: ``None``
Name of the CRS provided to reproject coordinates of the GeoDataFrame, e.g. ``target_crs='EPSG:4647'``.
bbox : list
Values (minx, maxx, miny, maxy) to limit the extent of the data, e.g. ``bbox=[0, 972, 0, 1069]``
bbox : list, default: ``None``
Values (minx, maxx, miny, maxy) to limit the extent of the data, e.g. ``bbox=[0, 972, 0, 1069]``.
remove_total_bounds: bool
Variable to remove the vertices representing the total bounds of a GeoDataFrame consisting of Polygons
Options include: ``True`` or ``False``, default set to ``False``
remove_total_bounds: bool, default: ``False``
Variable to remove the vertices representing the total bounds of a GeoDataFrame consisting of Polygons,
e.g. ``remove_total_bounds=False``.
Options include: ``True`` or ``False``, default set to ``False``.
threshold_bounds : Union[float, int]
Variable to set the distance to the total bound from where vertices are being removed,
e.g. ``threshold_bounds=10``, default set to ``0.1``
threshold_bounds : Union[float, int], default: ``0.1``
Variable to set the distance to the total bounds from where vertices are being removed,
e.g. ``threshold_bounds=10``, default set to ``0.1``.
Returns
_______
Expand All @@ -1549,12 +1565,21 @@ def extract_xyz_rasterio(
>>> import rasterio
>>> gdf = gpd.read_file(filename='file.shp')
>>> gdf
id formation geometry
0 None Ton POINT (19.150 293.313)
1 None Ton POINT (61.934 381.459)
2 None Ton POINT (109.358 480.946)
3 None Ton POINT (157.812 615.999)
4 None Ton POINT (191.318 719.094)
+----+-----------+------------------------+
| | formation | geometry |
+----+-----------+------------------------+
| 0 | Ton | POINT (19.150 293.313) |
+----+-----------+------------------------+
| 1 | Ton | POINT (61.934 381.459) |
+----+-----------+------------------------+
| 2 | Ton | POINT (109.358 480.946)|
+----+-----------+------------------------+
| 3 | Ton | POINT (157.812 615.999)|
+----+-----------+------------------------+
| 4 | Ton | POINT (191.318 719.094)|
+----+-----------+------------------------+
>>> # Loading raster file
>>> dem = rasterio.open(fp='dem.tif')
Expand All @@ -1564,21 +1589,29 @@ def extract_xyz_rasterio(
>>> # Extracting X, Y, and Z Coordinates from Shapely Base Geometries and raster
>>> gdf_xyz = gg.vector.extract_xyz_rasterio(gdf=gdf, dem=dem, reset_index=reset_index)
>>> gdf_xyz
formation geometry X Y Z
0 Ton POINT (19.150 293.313) 19.15 293.31 364.99
1 Ton POINT (61.934 381.459) 61.93 381.46 400.34
2 Ton POINT (109.358 480.946) 109.36 480.95 459.55
3 Ton POINT (157.812 615.999) 157.81 616.00 525.69
4 Ton POINT (191.318 719.094) 191.32 719.09 597.63
+----+-----------+------------------------+-------+-------+-------+
| ID | formation | geometry | X | Y | Z |
+----+-----------+------------------------+-------+-------+-------+
| 0 | Ton | POINT (19.150 293.313) | 19.15 | 293.31| 364.99|
+----+-----------+------------------------+-------+-------+-------+
| 1 | Ton | POINT (61.934 381.459) | 61.93 | 381.46| 400.34|
+----+-----------+------------------------+-------+-------+-------+
| 2 | Ton | POINT (109.358 480.946)| 109.36| 480.95| 459.55|
+----+-----------+------------------------+-------+-------+-------+
| 3 | Ton | POINT (157.812 615.999)| 157.81| 616.00| 525.69|
+----+-----------+------------------------+-------+-------+-------+
| 4 | Ton | POINT (191.318 719.094)| 191.32| 719.09| 597.63|
+----+-----------+------------------------+-------+-------+-------+
See Also
________
extract_xyz_array : Extracting X, Y, and Z coordinates from a GeoDataFrame and Digital Elevation Model as array
extract_xyz : Extracting X, Y, and Z coordinates from a GeoDataFrame and Digital Elevation Model
extract_xyz : Extract X, Y, and Z coordinates from a GeoDataFrame and Digital Elevation Model
extract_xyz_array : Extract X, Y, and Z coordinates from a GeoDataFrame and Digital Elevation Model as array
"""

# Checking that the input data is of type GeoDataFrame
if not isinstance(gdf, gpd.geodataframe.GeoDataFrame):
raise TypeError("Loaded object is not a GeoDataFrame")
Expand Down Expand Up @@ -1725,7 +1758,7 @@ def extract_xyz_rasterio(

# Extracting the X and Y coordinates of the reprojected gdf
gdf = extract_xy(
gdf,
gdf=gdf,
reset_index=False,
drop_index=False,
drop_id=False,
Expand Down

0 comments on commit 2df1ec3

Please sign in to comment.