gemgis.vector.extract_xyz_array#

gemgis.vector.extract_xyz_array(gdf: geopandas.geodataframe.GeoDataFrame, dem: numpy.ndarray, extent: List[float], minz: float = None, maxz: float = None, reset_index: bool = True, drop_index: bool = True, drop_id: bool = True, drop_points: bool = True, drop_level0: bool = True, drop_level1: bool = True, target_crs: Union[str, pyproj.crs.crs.CRS] = None, bbox: Optional[Sequence[float]] = None, remove_total_bounds: bool = False, threshold_bounds: Union[float, int] = 0.1) geopandas.geodataframe.GeoDataFrame#

Extracting X and Y coordinates from a GeoDataFrame (Points, LineStrings, MultiLineStrings Polygons) and Z values from a NumPy nd.array 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

  • dem (np.ndarray) – NumPy ndarray containing the height values

  • extent (list) – List containing the extent of the np.ndarray, must be provided in the same CRS as the gdf, e.g. extent=[0, 972, 0, 1069]

  • minz (float) – 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

  • reset_index (bool) – Variable to reset the index of the resulting GeoDataFrame. 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_level1 (bool) – Variable to drop the level_1 column. 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_id (bool) – Variable to drop the id column. 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

  • target_crs (Union[str, pyproj.crs.crs.CRS]) – 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]

  • 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

  • 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

Returns

gdf – GeoDataFrame containing the X, Y, and Z coordinates

Return type

gpd.geodataframe.GeoDataFrame

New in version 1.0.x.

Example

>>> # Loading Libraries and File
>>> import gemgis as gg
>>> import geopandas as gpd
>>> 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)
>>> # Loading raster file
>>> dem = rasterio.open(fp='dem.tif')
>>> dem
<open DatasetReader name='dem.tif' mode='r'>
>>> # Defining the extent of the array
>>> extent = [0, 972, 0, 1069]
>>> # Extracting X, Y, and Z Coordinates from Shapely Base Geometries and array
>>> gdf_xyz = gg.vector.extract_xyz_array(gdf=gdf, dem=dem.read(1), extent=extent, 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

See also

extract_xyz_rasterio

Extracting X, Y, and Z coordinates from a GeoDataFrame and Digital Elevation Model as rasterio object

extract_xyz

Extracting X, Y, and Z coordinates from a GeoDataFrame and Digital Elevation Model