From b9b046ae899ce98bfc0a7cac397a5854b0f7d25e Mon Sep 17 00:00:00 2001 From: mdupays Date: Thu, 30 May 2024 10:58:33 +0200 Subject: [PATCH] rectify parameters and add crs to output --- .../vectors/points_along_skeleton.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lidro/create_virtual_point/vectors/points_along_skeleton.py b/lidro/create_virtual_point/vectors/points_along_skeleton.py index ee11b559..671736d9 100644 --- a/lidro/create_virtual_point/vectors/points_along_skeleton.py +++ b/lidro/create_virtual_point/vectors/points_along_skeleton.py @@ -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) @@ -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