PDAL / python

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

How to add new dimensions to already existing data #153

Closed SjoerdBraaksma closed 9 months ago

SjoerdBraaksma commented 10 months ago

Hi Hobu! So laspy has a function add_extra_dim() to add new dimensions and data to already existing las files in python. I found this in the pdal documentation: https://pdal.io/en/latest/dimensions.html which would assume we can at least create new Dimensions taken form that list, if it's not yet in use.

However, I couldn't find any documentation on how to add dimensions using pdal-python, the way laspy does it.

Thanks in advance!

SjoerdBraaksma commented 9 months ago

Hi Hobu!

I found the ferry method, but cannot seem to get it to work:

    pipeline = pdal.Reader(load_laz)
    pipeline |= pdal.Filter.csf()
    pipeline |= pdal.Filter.range(limits="Classification[2:2]")
    pipeline |= pdal.Filter.ferry(dimensions="=>bgt_classification")
    pipeline |= pdal.Filter.overlay(
        dimension="bgt_classification",
        datasource=asprs_bgt_path,
        column="asprs_classification",
         layer="wegen",
    )
    pipeline |= pdal.Writer.las(
        filename=os.path.join(chunk_folder, f"{args.output_filename}_{args.chunk_id}.laz")
    )
    print(f"Pipeline executed resulting in {pipeline.execute()} points")

All stages of the pipeline work except for the ferry part. Additionally, no warning is given and the pipeline.execute() just doesn't produce any output, making debugging difficult.

hobu commented 9 months ago

Another option is to copy Classification into bgt_classification and then wipe it out with a filters.assign

  pipeline |= pdal.Filter.ferry(dimensions="Classification=>bgt_classification")
  pipeline |= pdal.Filter.assign(value="bgt_classification =0")
  pipeline |= pdal.Filter.overlay ....

Also make sure to set writers.las.extra_dims="all" if you want bgt_classification actually written out.

SjoerdBraaksma commented 9 months ago

Hey Hobu!

Thanks for the info, some further testing resulted in:

pipeline = pdal.Reader(load_laz)
pipeline |= pdal.Filter.ferry(dimensions="=>bgt_classification")

pipeline.execute()
output= pipeline.arrays[0]

If I do anyting more, like:

    pipeline = pdal.Reader(load_laz)
    pipeline |= pdal.Filter.ferry(dimensions="=>bgt_classification")
    pipeline |= pdal.Filter.csf()
    pipeline |= pdal.Filter.range(limits="Classification[2:2]")
    pipeline |= pdal.Filter.overlay(
        dimension="bgt_classification",
        datasource=asprs_bgt_path,
        column="asprs_classification",
        layer="wegen",
    )

i get these errors when trying to execute:

pipeline.execute()
output= pipeline.arrays[0]
[Errno 104] Connection reset by peer
[Errno 104] Connection reset by peer
output
Server[pid=196577] disconnected unexpectedly

working, so it could be that there is an issue between later steps. I'll try and test a few things so I can actually provide some useful info to you why it doesn't work ;)

In the meantime, I'll try your suggestions! thanks!

Edit: some further testing showed that the entire pipeline runs, until the overlay. (both the normal ferry as well ass your suggestion). On the overlay step however, the pipeline fails no matter what you enter as a dimension without providing any message.

SjoerdBraaksma commented 9 months ago

Just to close this off: The extra_dims=all worked, and the bug was caused by an invalid geometry in the geopackage used for the overlay.

Could it be usefull to add a warning for this to the overlay function?

hobu commented 9 months ago

If you set CPL_DEBUG=ON in your environment, the --debug log of pdal pipeline should emit GDAL/OGR complaints.