[OSM-dev] How to use osmosis as a lib with direct access to the classes?
Brett Henderson
brett at bretth.com
Mon Jul 4 13:34:18 BST 2011
Hi Robert,
On Thu, Jun 30, 2011 at 12:51 AM, Robert Greil <greil at in.tum.de> wrote:
> Hi!
>
> I am currently trying to use OSMOSIS as a lib for our java project. I have
> already checked out the svn repository and downloaded the latest osmosis zip
> from the website. I included all *.jar found in the Osmosis/lib directory as
> libs for our java project because of the dependencies between the jars.
> I want to use the example command line argument 'osmosis --read-pbf
> file="data_in.osm.pbf" --bounding-box left="90" right="90" --write-xml
> file="data_out.osm"' with direct access to the corresponding classes inside
> the java project.
> I think I have identified the jars I need for that:
> osmosis-pbf-0.39.jar - command: --read-pbf file="data_in.osm.pbf"
> osmosis-areafilter-0.39.jar - command: --bounding-box left="90" right="90"
> osmosis-xml-0.39.jar - command: --write-xml file="data_out.osm"
>
> I had a look inside the source code from the svn to see how to call theses
> classes directly without using the commandline parsing and pipeline and so
> on. I am not sure which classes are the correct ones, but according to the
> TaskFactories I tried using these:
> crosby.binary.osmosis.**OsmosisReader
> org.openstreetmap.osmosis.**areafilter.v0_6.**BoundingBoxFilter
> org.openstreetmap.osmosis.xml.**v0_6.XmlWriter.
>
> But I am really struck on how to access them directly or how to create and
> connect their input and outputstreams. I also do not know how to call the
> OsmosisReader directly, because it is set to protected and therefore not
> accessable from outside the package. I spent already hours coding and
> failing and slowly I am feeling like I am doing it the completely wrong way.
>
> That is why I am asking here, if anybody has done something similiar in the
> past (and point me to an example) or if anybody can give me a hint in the
> right direction or maybe some simple code examples/snipplets.
>
Ian's XAPI code is perhaps the best example.
As for the OsmosisReader protected constructor, that seems like a mistake.
I'd certainly expect all tasks to be able to be instantiated directly. I've
modified the constructor to be public in SVN now.
I wrote Osmosis to allow it to be used as a library and you seem to be on
the right path. To start with a really simple example, use the XML
classes. You should be able to do the following steps in your code to copy
one XML file to another:
- Instantiate an XmlWriter object by either giving it a destination File
in the constructor.
- Instantiate an XmlReader object by giving it a source File in the
constructor.
- Call setSink on the XmlReader and pass it the XmlWriter instance.
- Call run on the XmlReader.
More elaborate examples may require some deeper understanding of threading
within Osmosis because you may have to call run() on multiple tasks within
your manually constructed pipeline. If you require a pipeline with the
equivalent of --tee or --merge tasks where multiple paths through the
pipeline exist, you will also need to understand how MultiSink and
MultiSource implementations work (as opposed to the more basic Sink and
Source implementations), but the basic theory is much the same.
Brett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/dev/attachments/20110704/124ba9d4/attachment.html>
More information about the dev
mailing list