Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add new dimensions to already existing data #153

Closed
SjoerdBraaksma opened this issue Oct 9, 2023 · 5 comments
Closed

How to add new dimensions to already existing data #153

SjoerdBraaksma opened this issue Oct 9, 2023 · 5 comments

Comments

@SjoerdBraaksma
Copy link

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
Copy link
Author

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
Copy link
Member

hobu commented Nov 13, 2023

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
Copy link
Author

SjoerdBraaksma commented Nov 13, 2023

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
Copy link
Author

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
Copy link
Member

hobu commented Nov 13, 2023

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

@hobu hobu closed this as completed Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants