[pdal] How to test if file was loaded successfully?
Andrew Bell
andrew.bell.ia at gmail.com
Wed Sep 2 18:15:33 PDT 2015
On Wed, Sep 2, 2015 at 7:36 PM, Vaclav Petras <wenzeslaus at gmail.com> wrote:
> Hi,
>
> any suggestions how should I test if a file was loaded successfully? Example
> of code is in the porting guide I'm working on [1].
>
> What was in the libLAS code I'm using is
>
> LASReaderH LAS_reader = LASReader_Create("somefile.las");
> LASHeaderH LAS_header = LASReader_GetHeader(LAS_reader);
> if (LAS_header == NULL)
> // fail with "Input file is not a LAS LiDAR point cloud"
PDAL will throw a pdal_error exception if it can't load the dataset.
> Now I'm using (now check):
>
> std::unique_ptr<LasReader> las_reader(LasReader())
>
> Somewhere in the PDAL source code I've seen:
>
> Stage *stage = factory.createStage(driver);
> if (!stage)
> // fail with "reader creation failed"
>
> Later followed by (or any other appropriate pointer handling):
>
> std::unique_ptr<Stage>(s)
>
> Is this the right approach to use in general with functions in PDAL
> returning pointers? Can I use it with the LasReader()?
You can simply do:
LasReader r;
r.prepare();
r.execute();
The stage factory is useful for plugins, but the LAS driver isn't
built as a plugin, so you can just make the stage on the stack.
> Are there any other things I should check for in this opening and reading
> phase? Some typical error states? Wrong/unknow format? Or should I just wrap
> this whole part in a big try-catch with pdal_error?
Yes. We throw this all over the place. It's the only exception we
throw (or should be soon) and it means that we couldn't complete and
there's no possible recovery.
--
Andrew Bell
andrew.bell.ia at gmail.com
More information about the pdal
mailing list