Skip to content

Quick start

Nicolas Colomer edited this page May 27, 2013 · 13 revisions

Osmosis installation is really easy and should not take you more than 5 minutes. Just follow/adapt the few shell commands below.

You might also be interested in the osmosis-chef-cookbook that automates the osmosis installation on any Chef-managed node.

1. Install Osmosis

Untar the choosen build into the /opt directory (you can download them from the Osmosis builds page), create the /etc/osmosis file and finally set the $OSMOSIS_HOME and $PATH environment variable accordingly.

5-shell-command procedure:

# Osmosis 0.43 installation
wget -P /tmp http://dev.openstreetmap.org/~bretth/osmosis-build/osmosis-0.43-RELEASE.tgz
tar -zxvf /tmp/osmosis-0.43-RELEASE.tgz -C /opt
echo "JAVACMD_OPTIONS=\\"-server -Xmx2G\\"" > /etc/osmosis # Put your JVM params there
export OSMOSIS_HOME=/opt/osmosis-0.43
export PATH=$PATH:$OSMOSIS_HOME/bin

2. Install the Plugin

Put the latest plugin jar (see the releases section) into the $OSMOSIS_HOME/lib/default directory and add the org.openstreetmap.osmosis.plugin.elasticsearch.ElasticSearchWriterPluginLoader line into the $OSMOSIS_HOME/config/osmosis-plugins.conf file (create it if necessary).

3-shell-command procedure:

# elasticsearch-osmosis-plugin 1.3.0 installation
wget -P /tmp http://sourceforge.net/projects/es-osmosis/files/releases/elasticsearch-osmosis-plugin-1.3.0.jar
cp /tmp/elasticsearch-osmosis-plugin-1.3.0.jar $OSMOSIS_HOME/lib/default/
echo "org.openstreetmap.osmosis.plugin.elasticsearch.ElasticSearchWriterPluginLoader" > $OSMOSIS_HOME/config/osmosis-plugins.conf

3. Get OSM data

You can download OSM files (planet or extracts) from various location. OpenStreetMap have some listed on their dedicated Planet.osm wiki page.

Here is an example on how to get the guyane-latest.osm.pbf extract from Geofabrik.de:

mkdir -p ~/osm/extract ~/osm/planet ~/osm/output
wget -P ~/osm/extract http://download.geofabrik.de/europe/france/guyane-latest.osm.pbf

4. Index OSM data

Prerequisites: you must have an elasticsearch cluster up and running and reachable to make the plugin runs correctly. Read this installation guide if you start from zero.

The following command will import the Guyane extract downloaded previously into elasticsearch. The plugin will connect to the cluster elasticsearch via localhost using TransportClient (see the Usage section for more settings):

osmosis --read-pbf ~/osm/extract/guyane-latest.osm.pbf \
	--write-elasticsearch cluster.hosts="localhost"

5. Start querying

Note: you can also take a look at the brand new discovery site-plugin to visualize and explore your freshly indexed OpenStreetMap data!

Say you have a sudden urge to shake your body on the dancefloor around Cayenne, here is how your newly OpenStreetMap index can help you find what you need:

curl -XPOST http://localhost:9200/osm/_search?pretty=true -d '
{
  "query": {
    "filtered": {
      "query": {"match_all": {}},
      "filter": {
        "and": [
          {
            "term": {"tags.amenity": "nightclub"}
          },
          {
            "geo_shape": {
              "shape": {
                "shape": {
                  "type": "envelope",
                  "coordinates": [[-52.3467,4.9588],[-52.2744,4.8944]]
                }
              }
            }
          }
        ]
      }
    }
  }
}'

This search request should return 4 hits (3 nodes and 1 way), so let's dance!

{
  "took" : 35,
  "timed_out" : false,
  "_shards" : {"total" : 5, "successful" : 5, "failed" : 0},
  "hits" : {
    "total" : 4, "max_score" : 1.0,
    "hits" : [ {
      "_index" : "osm", "_type" : "node", "_id" : "1769692240", "_score" : 1.0, 
      "_source" : {"centroid":[-52.334269600000006,4.9346028],"shape":{"type":"point","coordinates":[-52.334269600000006,4.9346028]},"tags":{"source":"local inspection","name":"Pirata","amenity":"nightclub"}}
    }, {
      "_index" : "osm", "_type" : "way", "_id" : "71488259", "_score" : 1.0, 
      "_source" : {"centroid":[-52.30731138347001,4.946319349983063],"lengthKm":0.09864247375666864,"areaKm2":5.766624527713531E-4,"shape":{"type":"polygon","coordinates":[[[-52.3072601,4.946472],[-52.3074707,4.9462997],[-52.307362700000006,4.946166600000001],[-52.307152,4.946339200000001],[-52.3072601,4.946472]]]},"tags":{"building":"yes","source":"cadastre-dgi-fr source : Direction Générale des Impôts - Cadastre. Mise à jour : 2010","name":"Moonlight","amenity":"nightclub"}}
    }, {
      "_index" : "osm", "_type" : "node", "_id" : "1770555802", "_score" : 1.0, 
      "_source" : {"centroid":[-52.3331316,4.9338734],"shape":{"type":"point","coordinates":[-52.3331316,4.9338734]},"tags":{"source":"local inspection","name":"La Murassa","amenity":"nightclub"}}
    }, {
      "_index" : "osm", "_type" : "node", "_id" : "1603817088", "_score" : 1.0, 
      "_source" : {"centroid":[-52.331514500000004,4.891089200000001],"shape":{"type":"point","coordinates":[-52.331514500000004,4.891089200000001]},"tags":{"name":"Polina","amenity":"nightclub"}}
    } ]
  }
}