[pdal] Run a filter (sort) for a list of LAS files in a directory

Joseph S Faraguna faraguna at mit.edu
Wed Jul 31 09:53:01 PDT 2019


Miguel,

You can embed a pdal pipeline in a Python program and execute the pipeline
on a directory of files.

The code below will sort each las file in the directory in which the Python
program is placed by its X dimension, overwrite the files with the sorted
output, and also print out a pandas DataFrame of each sorted output.

Best,

Joe



On Wed, Jul 31, 2019 at 11:52 AM Andrew Bell <andrew.bell.ia at gmail.com>
wrote:

>
> This question is very general.  Perhaps you should write a program to the
> point where you have a specific problem where someone might help you.
>
> On Wed, Jul 31, 2019 at 1:58 AM Miguel Guerrero <
> g.miguel.guerrero.m at gmail.com> wrote:
>
>> Hello,
>>
>> I hope you are doing well.
>>
>> It has been hard for me to find a good example that shows me how to run a
>> PDAL filter in batch mode (looping) using Python.
>>
>> I have a set of LAS files in a directory and I want to be able to sort
>> the points for each file by GPS time using a looping method in Python 2.7
>>
>> Could anyone in the list help please?
>>
>>
>>
>> Thanks in advance for your response.
>>
>>
>>
>> Regards,
>>
>>
>>
>> Miguel
>>
>>
>>
>> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for
>> Windows 10
>>
>>
>> _______________________________________________
>> pdal mailing list
>> pdal at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/pdal
>
>
>
> --
> Andrew Bell
> andrew.bell.ia at gmail.com
> _______________________________________________
> pdal mailing list
> pdal at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/pdal



-- 

Department of Biological Engineering | Class of 2020

Massachusetts Institute of Technology

faraguna at mit.edu| (281) 902-6908
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/pdal/attachments/20190731/78d44181/attachment-0001.html>
-------------- next part --------------
import json
import numpy as np
import pandas as pd
import pdal
from os import listdir
from os.path import isfile

#gets all files in current directory, https://stackoverflow.com/questions/11968976/list-files-only-in-the-current-directory
files = [f for f in listdir('.') if f.endswith('.las')]

#execute pipeline for each file in directory
for each in files:

    example ={"pipeline":[
                    #implicit reader
                    each,
                    {
                        "type":"filters.sort",
                        "dimension":"X",
                        "order":"ASC"
                    },
                    #implicit writer
                    each
                ]
        }

    #construct and execute pipeline
    pipeline = pdal.Pipeline(json.dumps(example))
    pipeline.validate()
    pipeline.execute()

    #load output into pandas df
    arr = pipeline.arrays[0]
    description = arr.dtype.descr
    cols = [col for col, __ in description]
    df = pd.DataFrame({col: arr[col] for col in cols})

    print(df.head)


More information about the pdal mailing list