-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fucntion: clip points with bounding box
- Loading branch information
1 parent
930d731
commit d1a0cfa
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
lidro/create_virtual_point/vectors/clip_points_with_bounding_box.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
""" Clip Skeleton points by tile (pointcloud) | ||
""" | ||
from typing import List | ||
|
||
import geopandas as gpd | ||
from shapely.geometry import Point, box | ||
|
||
|
||
def clip_points_with_box(points: List, bbox: tuple) -> gpd.GeoDataFrame: | ||
"""Clip skeleton points by tile (bounding box) | ||
Args: | ||
points (List): Points every 2 meters (by default) along skeleton hydro | ||
bbox (tuple): bounding box from tile (pointcloud) | ||
Returns: | ||
gpd.GeoDataframe : Points every 2 meters (by default) along skeleton hydro by tile | ||
""" | ||
# Extract the bounding box limits | ||
xmin = bbox[0][0] | ||
xmax = bbox[0][1] | ||
ymin = bbox[1][0] | ||
ymax = bbox[1][1] | ||
|
||
# Create a GeoDataFrame from the points | ||
gdf_points = gpd.GeoDataFrame(geometry=[Point(point) for point in points]) | ||
# Create a polygon representing the bounding box | ||
bounding_box = box(xmin, ymin, xmax, ymax) | ||
|
||
# Clip points using the bounding box | ||
clipped_points = gdf_points[gdf_points.within(bounding_box)] | ||
|
||
return clipped_points |