Created
May 18, 2020 16:07
-
-
Save hobu/28778dcc0d222eecc793ee6c46559d9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
conda activate myenv | |
conda env list | |
import pdal | |
import glob | |
import numbpy as np | |
import logging | |
logger = logging.getLogger() | |
logger.setLevel(logging.DEBUG) | |
files = glob.glob('F:/PDAL/Batch_Practice/Las_Tiles/*.las') | |
pipeline = """ | |
{ | |
"pipeline": [ | |
{ | |
"type":"readers.las", | |
"filename":"%(filename)s" | |
}, | |
{ | |
"type": "filters.smrf" | |
}, | |
{ | |
"type":"filters.range", | |
"limits":"Classification[2:2]" | |
}, | |
{ | |
"gdaldriver":"GTiff", | |
"output_type":"idw", | |
"resolution" :"1.0", | |
"type": "writers.gdal" | |
} | |
] | |
} | |
""" | |
def run(args, stdin=None, return_json = False): | |
import json | |
import subprocess | |
logger.debug(args) | |
p = subprocess.Popen(' '.join(args), | |
stdin = subprocess.PIPE, | |
stdout = subprocess.PIPE, | |
stderr = subprocess.PIPE, shell=True, | |
encoding='utf8') | |
ret = p.communicate(input=stdin) | |
if p.returncode != 0: | |
error = ret[1] | |
logger.debug(error) | |
sys.exit(0) | |
return False | |
if return_json: | |
logger.debug(ret[0]) | |
return json.loads(ret[0]) | |
return True | |
for f in files: | |
# put the filename in a dictionary to allow convenient | |
# substitution without requiring order-specific string | |
# interpolation | |
d = {"filename":f} | |
# This is one way to do it, but that means all of the | |
# points are read into the python proces. If it's a huge file, that's | |
# not so great. | |
ll = pdal.Pipeline(pipeline % d) | |
ll.execute() | |
# an alternative is to kick another process off and run the | |
# pipeline using 'pdal pipeline'. The convenient thing about this | |
# is you can use the multiprocessing module to create a processing | |
# queue to attack things in parallel. | |
rargs = ['pdal', 'pipeline', '--stdin','--debug', '--metadata', 'STDOUT'] | |
results = run(rargs, pipeline % d, return_json=True) | |
# results will now contain the "pipeline metadata" that | |
# was produced by the 'pdal pipeline' call. | |
logger.debug('pipeline results', results) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment