gemgis.vector.interpolate_raster
gemgis.vector.interpolate_raster#
- gemgis.vector.interpolate_raster(gdf: geopandas.geodataframe.GeoDataFrame, value: str = 'Z', method: str = 'nearest', n: int = None, res: int = 1, extent: List[Union[int, float]] = None, seed: int = None, **kwargs) numpy.ndarray #
Interpolating a raster/digital elevation model from point or line Shape file
- Parameters
gdf (gpd.geodataframe.GeoDataFrame) – GeoDataFrame containing vector data of geom_type Point or Line containing the Z values of an area
value (str) – Value to be interpolated, e.g.
value='Z'
, default is'Z'
method (string) – Method used to interpolate the raster. Options include:
'nearest', 'linear', 'cubic', 'rbf'
res (int) – Resolution of the raster in X and Y direction, e.g.
res=50
seed (int) – Seed for the drawing of random numbers, e.g.
seed=1
n (int) – Number of samples used for the interpolation, e.g.
n=100
extent (List[Union[float, int]]) – Values for minx, maxx, miny and maxy values to define the boundaries of the raster, e.g.
extent=[0, 972, 0, 1069]
**kwargs (optional keyword arguments) – For kwargs for rbf and griddata see: https://docs.scipy.org/doc/scipy/reference/interpolate.html
- Returns
array – Array representing the interpolated raster/digital elevation model
- Return type
np.ndarray
New in version 1.0.x.
Example
>>> # Loading Libraries and File >>> import gemgis as gg >>> import geopandas as gpd >>> gdf = gpd.read_file(filename='file.shp') >>> gdf id Z geometry 0 None 400 LINESTRING (0.741 475.441, 35.629 429.247, 77.... 1 None 300 LINESTRING (645.965 0.525, 685.141 61.866, 724... 2 None 400 LINESTRING (490.292 0.525, 505.756 40.732, 519... 3 None 600 LINESTRING (911.433 1068.585, 908.856 1026.831... 4 None 700 LINESTRING (228.432 1068.585, 239.772 1017.037...
>>> # Interpolating vector data >>> raster = gg.vector.interpolate_raster(gdf=gdf, method='rbf') >>> raster[:2] array([[393.56371914, 393.50838517, 393.45386851, ..., 396.15856133, 398.11421775, 400.06334288], [393.41982945, 393.36494645, 393.31088433, ..., 396.20694282, 398.16690286, 400.12027997]])