[OSM-dev] Using osmosis as a lib?

Brett Henderson brett at bretth.com
Tue Feb 1 10:01:05 GMT 2011


Hi Franz,

On Tue, Jan 25, 2011 at 1:40 AM, Franz <graff at cip.ifi.lmu.de> wrote:

> Hi,
>
> is it possible to use osmosis as a library in order to use it in an own,
> separate java program? I wanted to transform pbf to xml and extract
> subregions from larger osm/pbf files.
>

Yes, definitely.  It has been done a number of times already.  The
Travelling Salesman routing software uses it internally (at least it did at
one point, probably still does), as does Ian Dees new XAPI implementation.


>
> I already downloaded osmosis-0.38 bins and the sources from SVN and
> checked the docs which explains everything great if I'd wanted to do the
> above in the command line.
> Could someone please give me a hint, how I could use osmosis directly
> (not via cli) to transform pbf to xml and possibly also how to cut
> regions from large xml/pbf files?
>

The command line and pipeline control code is a small part of the overall
distribution.  All tasks can be instantiated and invoked independently if
you wish.  Every task available on the command line such as --read-xml,
--read-pbf, etc is implemented by a class that can be used within your own
code.

Osmosis is made up of a number of jar files, each containing tasks of a
particular type.  To use XML as an example, it is contained in the xml
project which builds to osmosis-xml.jar.  To find the task implementation
classes, open the osmosis-plugins.conf file in that project, then open the
class it refers to.  In the XML case it refers to class
org.openstreetmap.osmosis.xml.XmlPluginLoader which defines the mappings
between command line task names and class names.  For example, "read-xml"
maps to XmlReaderFactory.  If you open XmlReaderFactory you'll see that it
instantiates an instance of XmlReader in its createTaskManagerImpl method.
The XmlReader class can be used directly in your code.  You can use a number
of task implementations directly allowing you to avoid dealing with the
Osmosis pipeline.

Cheers,
Brett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/dev/attachments/20110201/55ea5225/attachment.html>


More information about the dev mailing list