Skip to content

Commit

Permalink
add function for extract bounding box with pdal
Browse files Browse the repository at this point in the history
  • Loading branch information
mdupaysign committed Jun 14, 2024
1 parent 82402f2 commit 574ca49
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lidro/create_virtual_point/pointcloud/utils_pdal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
""" Utils PDAL
"""
import pdal


def read_las_file(input_las: str):
"""Read a las file and put it in an array"""
pipeline = pdal.Pipeline() | pdal.Reader.las(filename=input_las, nosrs=True)
pipeline.execute()
return pipeline.arrays[0]


def get_info_from_las(points):
"""Get info from a las to put it in an array"""
pipeline = pdal.Filter.stats().pipeline(points)
pipeline.execute()
return pipeline.metadata


def get_bounds_from_las(in_las: str):
"""Get bounds=([minx,maxx],[miny,maxy]) from las file
Args:
in_las (str): Path to the input LAS/LAZ file
Returns:
tuple : Bounds = ([minx,maxx],[miny,maxy]) from las file
"""
metadata = get_info_from_las(read_las_file(in_las))
xmin = metadata["metadata"]["filters.stats"]["bbox"]["native"]["bbox"]["minx"]
xmax = metadata["metadata"]["filters.stats"]["bbox"]["native"]["bbox"]["maxx"]
ymin = metadata["metadata"]["filters.stats"]["bbox"]["native"]["bbox"]["miny"]
ymax = metadata["metadata"]["filters.stats"]["bbox"]["native"]["bbox"]["maxy"]
return ([xmin, xmax], [ymin, ymax])

0 comments on commit 574ca49

Please sign in to comment.