[pdal] How to invoke my custom writer?

Andrew Bell andrew.bell.ia at gmail.com
Tue Jul 11 12:17:05 PDT 2017


This might be helpful:

https://www.pdal.io/development/overview.html

More concise are the tests.  Here is an example from the LAS writer:

TEST(LasWriterTest, srs)
> {
>     Options readerOps;
>     readerOps.add("filename", Support::datapath("las/utm15.las"));
>     LasReader reader;
>     reader.setOptions(readerOps);
>     Options writerOps;
>     writerOps.add("filename", Support::temppath("out.las"));
>     LasWriter writer;
>     writer.setInput(reader);
>     writer.setOptions(writerOps);
>     PointTable table;
>     writer.prepare(table);
>     writer.execute(table);
>     LasTester tester;
>     SpatialReference srs = tester.srs(writer);
>     EXPECT_EQ(srs, SpatialReference("EPSG:26915"));
> }


This code reads data from the input file "utm15.las" and writes it to
"out.las".  Since you've written a writer, PdalVectorMapWriter, your
similar code might look like:

int main()
{

    Options readerOps;
    readerOps.add("filename", Support::datapath("las/utm15.las"));
    LasReader reader;
    reader.setOptions(readerOps);

    Options writerOps;
    writerOps.add("filename", Support::temppath("out.las"));
    PdalVectorMapWriter writer;
    writer.setInput(reader);  // This essentially creates a pipeline from
reader -> writer.
    writer.setOptions(writerOps);

    PointTable table;
    writer.prepare(table);
    writer.execute(table);  // Executing the terminal stage runs the
pipeline.

    return 0;
}

When you compile, link and run this program, points will be read from
utm15.las and made available to your writer, calling either the run() or
write() function that you've implemented.

There are lots of more complicated things you can do, but this is about the
most simple example.


On Tue, Jul 11, 2017 at 2:37 PM, Paul Schrum <paul.schrum at gmail.com> wrote:

> Andrew,
>
> We have become interested in that second option you mention, "executing
> code programmatically, you can simply add your writer to the end of a
> pipeline and call prepare() and execute()".  Are there examples of how to
> do this?
>
> We looked at PipelineManager and see
> PointTableRef pointTable() const
>
> Is that what we would consume?  If so, how do I get to the point where
> that has data in it and is ready for me to iterate over
>
> - Paul
>
>
> On Tue, Jul 11, 2017 at 11:16 AM, Andrew Bell <andrew.bell.ia at gmail.com>
> wrote:
>
>> You need to build your writer (a plugin) into a shared object that can be
>> loaded by the plugin manager.  It needs to be called
>> libpdal_plugin_writer_PdalVectorMapWriter.<your shared library
>> extension>.  The shared library needs to be located somewhere that the
>> plugin manager can find it.  By default, PDAL will look in the following
>> directories for plugins:
>>
>> ".", "./lib", "../lib", "./bin", "../bin"
>>
>> If you're using cmake, you can use the PDAL build to generate the shared
>> library for you.  Here's an example plugin:
>>
>> https://github.com/gadomski/cpd.git
>>
>> Note that you don't have to do ANY of this if you're not using the
>> pipeline/plugin manager to run your writer from a JSON pipeline.  If you're
>> executing code programmatically, you can simply add your writer to the end
>> of a pipeline and call prepare() and execute() on the pipeline that you've
>> created in code.
>>
>>
>> On Tue, Jul 11, 2017 at 10:59 AM, Paul Schrum <paul.schrum at gmail.com>
>> wrote:
>>
>>> Thank you Andrew.
>>>
>>> In the cpp file containing the class, I have the following lines:
>>>
>>>   static PluginInfo const s_info = PluginInfo(
>>>     "writers.PdalVectorMapWriter",
>>>     "Custom Writer to write a GRASS Vector Map",
>>>     "http://no/documentation/yet" );
>>>
>>>   CREATE_SHARED_PLUGIN(1, 0, PdalVectorMapWriter, Writer, s_info);
>>>
>>> So would the only other thing I need to do be to tell pdal where to find
>>> the class?  I don't have to instantiate the class and pass it the instance?
>>>
>>> The class lives in my GRASS executable, v.in.pdal.  How do I tell pdal
>>> to append PDAL_DRIVER_PATH with v.in.pdal's path, and is that sufficient?
>>>
>>> I see in https://github.com/PDAL/PDAL/tree/master/plugins that these
>>> are built using CMake.  But GRASS uses make, so I don't know how to make
>>> these work together.  Is it not possible for me simply to pass an instance
>>> of my class to some kind of pdal->registerPlugIn() function or something
>>> similar which happens at runtime?
>>>
>>> - Paul
>>>
>>>
>>> On Mon, Jul 10, 2017 at 7:56 PM, Andrew Bell <andrew.bell.ia at gmail.com>
>>> wrote:
>>>
>>>> You need to build your writer as a shared plugin and make sure that the
>>>> dll/so that you create is in a folder where the plugin manager will look
>>>> for it (or set PDAL_DRIVER_PATH).  Take a look at one of the existing
>>>> plugins in the "plutgins" subdirectory of pdal.  Let me know if you need
>>>> more help.
>>>>
>>>> On Mon, Jul 10, 2017 at 5:11 PM, Paul Schrum <paul.schrum at gmail.com>
>>>> wrote:
>>>>
>>>>> I am developing a custom PDAL writer for my GSoC project. (Link
>>>>> <https://trac.osgeo.org/grass/wiki/GSoC/2017/IntegrationOfPDALintoGRASSGIS>)
>>>>> Source Code is on github <https://github.com/PaulSchrum/v_in_pdal>.
>>>>> The module compiles, but it is an intermediate state since I am in the
>>>>> process of developing it.
>>>>>
>>>>> I have the custom writer, PdalVectorMapWriter,  inheriting from writer
>>>>> and it compiles okay.  Currently all functions just print out their own
>>>>> name and return.
>>>>>
>>>>> In main.cpp I create the pipeline json string and create a
>>>>> PipelineExecutor with it.  I then call pipeline-> validate.  This throws an
>>>>> exception stating
>>>>>
>>>>> terminate called after throwing an instance of 'pdal::pdal_error'
>>>>>   what():  Couldn't create writer stage of type
>>>>> 'writers.PdalVectorMapWriter'.
>>>>>
>>>>> So I am thinking that I need somehow to inform Pdal about an instance
>>>>> of the class.  But as I go over the Pdal documentation, I do not see how to
>>>>> do that.  Can someone help me understand what I need to do?
>>>>>
>>>>> - Paul
>>>>>
>>>>> Here is a key code snippet:
>>>>> 81    std::string pipeline_json =
>>>>> 82            pipelineJson::basicVectorMapRe
>>>>> aderWriter(inFile,outFile);
>>>>> 83
>>>>> 84    cout << pipeline_json << endl;  //diagnostic only
>>>>> 85    cout << endl;
>>>>> 86    G_important_message(_("Running the pipeline ..."));
>>>>> 87    auto pipeline = new pdal::PipelineExecutor(pipeline_json);
>>>>> 88
>>>>> 87    cout << "is valid?  " << pipeline->validate() << endl;
>>>>>
>>>>> Line 87 throws the exception.
>>>>>
>>>>>
>>>>> Here is the json string being passed to the PipelineExecutor
>>>>> constructor:
>>>>>
>>>>> { "pipeline":[
>>>>>    "/home/user/Desktop/ALL/SourceModules/cpp/grass7_trunk/vecto
>>>>> r/v.in.pdal/testFiles/100-points.las",
>>>>> {
>>>>>    "type":"writers.PdalVectorMapWriter",
>>>>>    "filename":"100-points"
>>>>> }
>>>>>  ]
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> pdal mailing list
>>>>> pdal at lists.osgeo.org
>>>>> https://lists.osgeo.org/mailman/listinfo/pdal
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Andrew Bell
>>>> andrew.bell.ia at gmail.com
>>>>
>>>
>>>
>>
>>
>> --
>> Andrew Bell
>> andrew.bell.ia at gmail.com
>>
>
>


-- 
Andrew Bell
andrew.bell.ia at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/pdal/attachments/20170711/99a85995/attachment.html>


More information about the pdal mailing list