-
Notifications
You must be signed in to change notification settings - Fork 0
/
point-in-las
executable file
·64 lines (47 loc) · 1.35 KB
/
point-in-las
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Daniel Rode
# Dependencies:
# Python 3.11+
# PDAL
# shapely
# Created: 28 May 2024
# Updated: -
# Version: 0
# Description: Given a set of coordinates, determine whether the point falls
# within a given las/laz file point cloud boundary.
import sys
from sys import exit
import subprocess as sp
import json
import shapely.wkt
from shapely.geometry import Point
# Constants
exe_name = sys.argv[0].split('/')[-1] # This script's filename
help_text = f"Usage: python3 {exe_name} X_COORD Y_COORD LAS_PATH..."
# Functions
def get_las_bound(las_path):
cmd = ['pdal', 'info', '--boundary', las_path]
p = sp.run(cmd, check=True, capture_output=True, text=True)
return json.loads(p.stdout)['boundary']['boundary']
# Main
def main():
# Parse command line arguments
args = sys.argv[1:]
try:
x_coord = args[0]
y_coord = args[1]
except IndexError:
print(help_text)
exit(1)
# Check which las/laz file contains the given coordinate pair
count = 0
for las_path in args[2:]:
bound = shapely.wkt.loads(get_las_bound(las_path))
point = Point(x_coord, y_coord)
if bound.contains(point):
print(las)
exit()
print(f"checked {count}")
if __name__ == '__main__':
main()