-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctg2vpc
executable file
·64 lines (51 loc) · 1.37 KB
/
ctg2vpc
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
# Author: Daniel Rode
# Dependencies:
# python 3.12
# pdal
# Created: 02 Oct 2024
# Updated: -
import sys
import tempfile
import subprocess as sp
from sys import exit
from pathlib import Path
HELP_TEXT = """Usage: this.py LAS_DIR OUT_VPC_PATH"""
LAS_EXT = '.copc.laz'
PDAL_WRENCH_EXE = "/usr/lib64/qgis/pdal_wrench"
def print2(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def pdal_mosaic(tile_list, dst_pth):
# Virtual mosaic point cloud tiles
cmd = [
PDAL_WRENCH_EXE, 'build_vpc',
'--input-file-list', tile_list,
'--output', dst_pth,
]
sp.run(cmd, check=True)
return dst_pth
def main():
# Parse command line arguments
args = sys.argv[1:]
try:
src_dir = Path(args[0])
dst_pth = Path(args[1])
except IndexError:
print(HELP_TEXT)
exit(1)
if not src_dir.is_dir():
print2("error: Directory not found:", d)
exit(1)
# Use temp directory for intermediate files
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_dir = Path(tmp_dir)
# Create temp text file with list of source tiles
tile_paths = src_dir.glob(f"**/*{LAS_EXT}")
tile_paths = [str(p) for p in tile_paths]
tile_list = tmp_dir/"tile_list.txt"
with tile_list.open('w') as f:
f.write('\n'.join(tile_paths))
# Virtual mosaic tiles
pdal_mosaic(tile_list, dst_pth)
if __name__ == '__main__':
main()