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

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Miguel Guerrero
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
[hidden email]
https://lists.osgeo.org/mailman/listinfo/pdal
Reply | Threaded
Open this post in threaded view
|

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

andrew.bell.ia@gmail.com
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 <[hidden email]> 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
[hidden email]
https://lists.osgeo.org/mailman/listinfo/pdal


--
Andrew Bell
[hidden email]

_______________________________________________
pdal mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/pdal
Reply | Threaded
Open this post in threaded view
|

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

Miguel Guerrero
Thanks for the prompt reply!
I understand. Here is another question: I stored the Coplanarity values (0 and 1) in the UserData dimension. Is there any way to "assign"/"reclassify" the UserData dimension to the Classification dimension?
Example:
UserData = 0 => Classification = class 16
UserData = 1 => Classification = class 17

Thanks in advance for your help

Miguel

On Thu, May 14, 2020 at 1:01 PM Andrew Bell <[hidden email]> wrote:
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 <[hidden email]> 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
[hidden email]
https://lists.osgeo.org/mailman/listinfo/pdal


--
Andrew Bell
[hidden email]

_______________________________________________
pdal mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/pdal
Reply | Threaded
Open this post in threaded view
|

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

andrew.bell.ia@gmail.com

On Thu, May 14, 2020 at 6:50 PM Miguel Guerrero <[hidden email]> wrote:
Thanks for the prompt reply!
I understand. Here is another question: I stored the Coplanarity values (0 and 1) in the UserData dimension. Is there any way to "assign"/"reclassify" the UserData dimension to the Classification dimension?
Example:
UserData = 0 => Classification = class 16
UserData = 1 => Classification = class 17

You can do this with the assign filter:

{
  "type" : "filters.assign",
  "assignment": "Classification[:]=16",
  "condition":"UserData[0:0]"
},
{
  "type" : "filters.assign",
  "assignment": "Classification[:]=17",
  "condition":"UserData[1:1]"
},
 

Thanks in advance for your help

Miguel

On Thu, May 14, 2020 at 1:01 PM Andrew Bell <[hidden email]> wrote:
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 <[hidden email]> 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
[hidden email]
https://lists.osgeo.org/mailman/listinfo/pdal


--
Andrew Bell
[hidden email]


--
Andrew Bell
[hidden email]

_______________________________________________
pdal mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/pdal