Osmosis/Writing Plugins

From OpenStreetMap Wiki
< Osmosis(Redirected from Osmosis/WritingPlugins)
Jump to navigation Jump to search

Anatomy of a plugin

A plugin for osmosis consists of

  • one zip-file containing:
  • a file plugin.xml
  • the classes of the plugin

Content of plugin.xml

(example plugin.xml)

<?xml version="1.0" ?>
<!DOCTYPE plugin PUBLIC "-//JPF//Java Plug-in Manifest 1.0" "http://jpf.sourceforge.net/plugin_1_0.dtd">
<plugin id="LibOSM" version=""

    <!--These are library-files we require including our own code. -->
           <import plugin-id="org.openstreetmap.osmosis.core.plugin.Core" plugin-version="0.32" reverse-lookup="false"/>
    <!--These are library-files we require including our own code. -->
        <library id="mycode" path="/" type="code"/>

<!--This is where our plugin plugs into.
    The extension-point 'task' with a subclass of PluginLoader named 'WriteOSMBinPlugin'
    that tells Osmosis what tasks are provided.-->
    <extension plugin-id="org.openstreetmap.osmosis.core.plugin.Core"
               point-id="Task" id="LibOSM/OsmBin-Tasks/writeOsmBin">
       <parameter id="name"
       <parameter id="class"
    <!--extension plugin-id="org.openstreetmap.osmosis.core.plugin.Core"
               point-id="Task" id="LibOSM/OsmBin-Tasks/writeOsmBin-0.6">
       <parameter id="name"
       <parameter id="class"

Where to plug into

Currently there is only one extension-point task

Adding tasks

the plugin-loader

To plug into the extension-point task you need to write one factory-class that extends com.bretth.osmosis.core.plugin.PluginLoader (example).

This class is required for historic reasons.

the TaskManagerFactory

This class contains a method loadTaskFactories() that returns a map from command-line-name to instance of TaskManagerFactory.

Obvisiously you need to write one implementation of com.bretth.osmosis.core.pipeline.common.TaskManagerFactory (example) for every task you want to add. This class is tasked with parsing the command-line arguments, instanciating your task and wrapping it in a TaskManager. For example a com.bretth.osmosis.core.pipeline.v0_5.SinkManager for a task that consumes osm-data.

the Task

Last but not least you need to implement the actual task (example).