gemgis.vector.unify_linestrings#

gemgis.vector.unify_linestrings(linestrings: Union[List[shapely.geometry.linestring.LineString], geopandas.geodataframe.GeoDataFrame], crs: Union[str, pyproj.crs.crs.CRS] = None, return_gdf: bool = True) Union[List[shapely.geometry.linestring.LineString], geopandas.geodataframe.GeoDataFrame]#

Unifying adjacent LineStrings to form LineStrings with multiple vertices

Parameters
  • linestrings (Union[List[shapely.geometry.linestring.LineString], gpd.geodataframe.GeoDataFrame]) – LineStrings consisting of two vertices representing extracted contour lines

  • crs (Union[str, pyproj.crs.crs.CRS]) – Name of the CRS provided to reproject coordinates of the GeoDataFrame, e.g. crs='EPSG:4647'

  • return_gdf (bool) – Variable to either return the data as GeoDataFrame or as list of LineStrings. Options include: True or False, default set to True

Returns

linestrings_merged – Merged Shapely LineStrings

Return type

Union[List[shapely.geometry.linestring.LineString], gpd.geodataframe.GeoDataFrame]

New in version 1.0.x.

Example

>>> # Loading Libraries and File
>>> import gemgis as gg
>>> import geopandas as gpd
>>> linestrings = gpd.read_file(filename='file.shp')
>>> linestrings
    geometry                                            Z
0   LINESTRING Z (32409587.930 5780538.824 -2350.0...   -2350.00
1   LINESTRING Z (32407304.336 5777048.086 -2050.0...   -2050.00
2   LINESTRING Z (32408748.977 5778005.047 -2200.0...   -2200.00
3   LINESTRING Z (32403693.547 5786613.994 -2400.0...   -2400.00
4   LINESTRING Z (32404738.664 5782672.480 -2350.0...   -2350.00
>>> # Merging linestrings
>>> polygons_linestrings = gg.vector.unify_linestrings(linestrings=linestrings)
>>> polygons_linestrings
    geometry
0   LINESTRING Z (32331825.641 5708789.973 -200.00...
1   LINESTRING Z (32334315.359 5723032.766 -250.00...
2   LINESTRING Z (32332516.312 5722028.768 -250.00...
3   LINESTRING Z (32332712.750 5721717.561 -250.00...
4   LINESTRING Z (32332516.312 5722028.768 -250.00...