PDAL / python

PDAL's Python Support
Other
116 stars 34 forks source link

Add column to array and write it #39

Closed luczeng closed 4 years ago

luczeng commented 4 years ago

Hello,

I am trying to add a column to an array read from a PLY file, and then save it back. When I try to save the resulting array, the script crashes. Funnily enough, I get two different errors depending on the run. My code is below:

import pdal
import numpy as np
import argparse

def load_ply(file_path):
    json = """

    {{
    "pipeline":[
        {{
          "type": "readers.ply",
          "filename": "{}"
        }}
    ]
    }}""".format(file_path)

    pipeline = pdal.Pipeline(json)
    pipeline.validate() # check if our JSON and options were good
    return pipeline 

def save_ply(data):
    json = """
    {
    "pipeline":[
        {
          "type":"writers.ply",
          "storage_mode":"little endian",
          "filename":"outputfile.ply"
        }
    ]
    }"""

    pipeline = pdal.Pipeline(json, arrays = data)
    pipeline.validate() # check if our JSON and options were good
    return pipeline 

if __name__ == "__main__":
    parser= argparse.ArgumentParser()
    parser.add_argument('-i','--input',type = str)
    args = parser.parse_args() 

    pc_path = args.input

    pipeline= load_ply(pc_path)
    pipeline.execute()
    arrays = pipeline.arrays
    metadata = pipeline.metadata

    from numpy.lib.recfunctions import append_fields
    L = len(arrays[0]['Z'])
    Labels = np.ones(L)
    new_array = append_fields(arrays[0], 'UserData', Labels)

    pipeline = save_ply([new_array])
    pipeline.execute()
    arrays = pipeline.arrays
    metadata = pipeline.metadata

The errors I get are the following:

My python-pdal is 2.2.0.

The script is run specifying ply input path with the -i option.

Any help welcome!

abellgithub commented 4 years ago

I believe that this was fixed in version 2.2.2. Give that a try.

On Wed, Oct 16, 2019 at 2:45 PM LucZZ notifications@github.com wrote:

Hello,

I am trying to add a column to an array read from a PLY file, and then save it back. When I try to save the resulting array, the script crashes. Funnily enough, I get two different errors depending on the run. My code is below:

import pdal import numpy as np import argparse

def load_ply(file_path): json = """

{{
"pipeline":[
    {{
      "type": "readers.ply",
      "filename": "{}"
    }}
]
}}""".format(file_path)

pipeline = pdal.Pipeline(json)
pipeline.validate() # check if our JSON and options were good
return pipeline

def save_ply(data): json = """ { "pipeline":[ { "type":"writers.ply", "storage_mode":"little endian", "filename":"outputfile.ply" } ] }"""

pipeline = pdal.Pipeline(json, arrays = data)
pipeline.validate() # check if our JSON and options were good
return pipeline

if name == "main": parser= argparse.ArgumentParser() parser.add_argument('-i','--input',type = str) args = parser.parse_args()

pc_path = args.input

pipeline= load_ply(pc_path)
pipeline.execute()
arrays = pipeline.arrays
metadata = pipeline.metadata

from numpy.lib.recfunctions import append_fields
L = len(arrays[0]['Z'])
Labels = np.ones(L)
new_array = append_fields(arrays[0], 'UserData', Labels)

pipeline = save_ply([new_array])
pipeline.execute()
arrays = pipeline.arrays
metadata = pipeline.metadata

The errors I get are the following:

  • 2898 segmentation fault (core dumped)
  • RuntimeError: readers.memoryview: Can't provide shape option when Fields contain X, Y and Z.

My python-pdal is 2.2.0.

The script is run specifying ply input path with the -i option.

Any help welcome!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PDAL/python/issues/39?email_source=notifications&email_token=AAKBMMFRMBSYTSME5P3MYVLQO5OLRA5CNFSM4JBPRIU2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HSH6AXA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKBMMH5UVYH7ILOXIX6NILQO5OLRANCNFSM4JBPRIUQ .

-- Andrew Bell andrew.bell.ia@gmail.com

luczeng commented 4 years ago

Hey, I installed pdal 2.2.2. The script still fails, but I don't have the RuntimeError: readers.memoryview: error anymore. Now the only error I receive is:

9384 segmentation fault (core dumped)

I run the script with a 52k point cloud on a 32GB machine.

hobu commented 4 years ago

Can you attach the PLY file so we can cook up a test?

luczeng commented 4 years ago

I can't upload my personal point cloud, but here is a reduce point cloud that gives an error:

test.zip

The error is the following:

MemoryError: std::bad_alloc

Thanks for the help

hobu commented 4 years ago

Please reopen this ticket if the problem described in it is not fixed in PDAL 2.1 + PDAL-Python 2.3.