Skip to content

Commit 817452d

Browse files
committed
add function get_epsg_from_las in function las_info.py
1 parent c942d7f commit 817452d

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

pdaltools/las_info.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
from typing import Dict, Tuple
55

6+
import laspy
67
import osgeo.osr as osr
78
import pdal
89

@@ -211,3 +212,20 @@ def get_writer_parameters_from_reader_metadata(metadata: Dict, a_srs=None) -> Di
211212
"a_srs": a_srs if a_srs else reader_metadata["comp_spatialreference"],
212213
}
213214
return params
215+
216+
217+
def get_epsg_from_las(filename: str) -> str:
218+
"""Extract EPSG code from LAS file metadata and return as 'EPSG:XXXX' format.
219+
220+
Args:
221+
filename (str): full path of file for which to get the bounding box
222+
223+
Returns:
224+
str : CRS's value of the data in 'EPSG:XXXX' format, or None if not found.
225+
"""
226+
with laspy.open(filename) as las:
227+
crs = las.header.parse_crs()
228+
if crs is None:
229+
return None # Return None if CRS is not defined
230+
epsg_code = crs.to_epsg()
231+
return f"EPSG:{epsg_code}" if epsg_code else None
Binary file not shown.

test/test_las_info.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,17 @@ def test_get_writer_parameters_from_reader_metadata():
136136
out_expected_metadata.pop(key)
137137

138138
assert out_metadata == out_expected_metadata
139+
140+
141+
def test_get_epsg_from_las_no_epsg():
142+
input_file = os.path.join(DATA_PATH, "test_noepsg_043500_629205_IGN69.laz")
143+
144+
crs = las_info.get_epsg_from_las(input_file)
145+
assert crs is None
146+
147+
148+
def test_get_epsg_from_las_with_epsg():
149+
input_file = os.path.join(DATA_PATH, "test_data_77050_627755_LA93_IGN69.laz")
150+
151+
crs = las_info.get_epsg_from_las(input_file)
152+
assert crs == "EPSG:2154"

0 commit comments

Comments
 (0)