Skip to content

Commit

Permalink
rectify parameters and add crs to output
Browse files Browse the repository at this point in the history
  • Loading branch information
mdupaysign committed May 30, 2024
1 parent 48bd0b0 commit b9b046a
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions lidro/create_virtual_point/vectors/points_along_skeleton.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
# -*- coding: utf-8 -*-
""" Create severals points every 2 meters (by default) along skeleton Hydro
""" Create several points every 2 meters (by default) along skeleton Hydro
"""
import os

import geopandas as gpd
from shapely.geometry import Point
from shapely.ops import linemerge


def generate_points_along_skeleton(
input_folder: str, input_file: str, distance_meters: 2, crs: tuple
) -> gpd.GeoDataFrame:
def generate_points_along_skeleton(input_file: str, distance_meters: 2, crs: str | int) -> gpd.GeoDataFrame:
"""Create several points every 2 meters (by default) along skeleton Hydro
Args:
input_folder (str): folder which contains Skeleton Hydro (1 file ".GeoJSON")
input_file (str): input filename from Skeleton Hydro
input_file (str): Path from Skeleton Hydro
distance_meters (float): distance in meters between 2 consecutive points (default: 2 meters)
crs (tuple): a pyproj CRS object used to create the output GeoJSON file
crs (str | int): Make a CRS from an EPSG code : CRS WKT string
Returns:
gpd.GeoDataFrame: Points every 2 meters (by default) along skeleton hydro
"""
# Read the input file
lines_gdf = gpd.read_file(os.path.join(input_folder, input_file), crs=crs)
lines_gdf = gpd.read_file(input_file, crs=crs)

# Segmentize geometry
lines_merged = linemerge(lines_gdf.unary_union, directed=False)
Expand All @@ -34,6 +29,6 @@ def generate_points_along_skeleton(
for distance in range(0, int(lines_merged.length), distance_meters)
]

points_gdf = gpd.GeoDataFrame(geometry=list_points).explode(ignore_index=True)
points_gdf = gpd.GeoDataFrame(geometry=list_points, crs=crs).explode(ignore_index=True)

return points_gdf

0 comments on commit b9b046a

Please sign in to comment.