-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlas2dtm
executable file
·71 lines (60 loc) · 1.39 KB
/
las2dtm
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
65
66
67
68
69
70
71
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Daniel Rode
# Dependencies:
# python 3.12.6
# pdal 2.6.3
# gdal
# Created: 11 Oct 2024
# Updated: -
import sys
import json
import subprocess as sp
from sys import exit
from pathlib import Path
from datetime import datetime
HELP_TEXT = """Usage: this.py IN_LAS_PATH OUT_TIFF_PATH"""
def get_pdal_pipeline(in_path, out_path):
return json.dumps([
str(in_path),
# Drop non-ground points
{
"type": "filters.expression",
"expression": "Classification == 2",
},
# Generate DTM
{
"resolution": 0.5,
"binmode": False,
"dimension": "Z",
"output_type": ["mean"],
"gdaldriver": "GTiff",
"filename": str(out_path),
},
])
def pdal(pipeline_json):
cmd = [
"pdal",
"pipeline",
"--stdin",
"--nostream",
]
sp.run(cmd, text=True, check=True, input=pipeline_json)
def gdal_fill_nodata(in_path, out_path):
cmd = [
"gdal_fillnodata.py", "-md", "99", in_path, out_path
]
sp.run(cmd, check=True)
# Parse command line arguments
args = sys.argv[1:]
try:
in_path = Path(args[0])
out_path = Path(args[1])
except IndexError:
print(HELP_TEXT)
exit(1)
# Generate DTM raster
print(f"Starting {datetime.now()}")
pdal(get_pdal_pipeline(in_path, "./tmp-dtm-partial.tif"))
gdal_fill_nodata("./tmp-dtm-partial.tif", out_path)
print(f"Finished {datetime.now()}")