[pdal] PDAL Python working with an specific dimension (classification)

Andrew Bell andrew.bell.ia at gmail.com
Thu May 14 13:00:48 PDT 2020


filters.csf is a ground filter, so it classifies everything as either
ground or unclassified.

On Thu, May 14, 2020 at 3:41 PM Miguel Guerrero <
g.miguel.guerrero.m at gmail.com> wrote:

> Hello,
> I hope this email finds you well.
> First off, thanks for a great job implementing the PDAL for Python.
> I have a LiDAR dataset in LAS format that has been pre-classified. I want
> to apply some filters to one or multiples classes. I followed the samples
> shown on https://pdal.io/stages/filters.html and
> https://github.com/PDAL/python. I am able to get the filters to work but
> the final output only contains the classes 1 and/or 2, when in reality I
> would like to get the rest of the classes that were not used in the
> filtering process.
> Any direction or suggestion would be greatly appreciated.
>
> My best regards,
>
> Miguel
>
> Here is my code:
>
> import os
>
> # Input and validation of source directory
> while True:
>     srcDirectory = os.path.normpath(input("Enter directory containing LAS files: "))
>     if os.path.exists(srcDirectory) is True and srcDirectory != ".":
>         break
>     else:
>         print(srcDirectory, "is not a valid directory")
>
> # Input and validation of destination directory
> while True:
>     dstDirectory = os.path.normpath(input("Enter directory to store processed files: "))
>     if os.path.exists(dstDirectory) is True and dstDirectory != ".":
>         break
>     else:
>         print (dstDirectory, "is not a valid directory")
>
> print ("")
>
> # Change the working directory to the source directory
> os.chdir(srcDirectory)
> print ("Working directory is" + " " + os.getcwd())
>
> # Blank line for better visualization
> print ("")
>
> # Create list of files in source directory
> filesList = os.listdir(srcDirectory)
>
> for file in filesList:
>     if file.endswith('las'):
>         fileIn = (srcDirectory + "\\" + file).replace('\\', '/')
>         fileOut = (dstDirectory + "\\" + file).replace('\\', '/')
>
>         json = """
>             {
>               "pipeline": [
>                 {
>                     "type": "readers.las",
>                     "filename": "%s"
>                 }
>               ]
>             }"""
>
>         import pdal
>         import numpy as np
>         pipeline = pdal.Pipeline(json % fileIn)
>         count = pipeline.execute()
>
>         arr = pipeline.arrays[0]
>         print(len(arr))
>
>         lasClass26 = arr[arr['Classification'] == 26]
>         print(len(lasClass26))
>
>         clamp = u"""{
>           "pipeline":[
>             {
>                 "type":"filters.csf"
>             },
>             {
>                 "type":"filters.range",
>                 "limits":"Classification[0:30]"
>             },
>             "%s"
>           ]
>         }""" % (fileOut)
>
>         p = pdal.Pipeline(clamp, [lasClass26])
>         count = p.execute()
>         clamped = p.arrays[0]
>         print(count)
>
> _______________________________________________
> pdal mailing list
> pdal at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/pdal



-- 
Andrew Bell
andrew.bell.ia at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/pdal/attachments/20200514/7032911e/attachment.html>


More information about the pdal mailing list