Osmosis/Polygon Filter File Format

From OpenStreetMap Wiki
Jump to: navigation, search
Available languages — Osmosis/Polygon Filter File Format
· Deutsch · English

The Osmosis polygon filter file format is supported by Osmosis, mapsplit, osmconvert, osmchange and pbftoosm as a way of defining extraction polygons.

For OSM Polygons, see Multipolygon relation.


     0.1446763E+03    -0.3825659E+02
     0.1446693E+03    -0.3826255E+02
     0.1446627E+03    -0.3825661E+02
     0.1446763E+03    -0.3824465E+02
     0.1446813E+03    -0.3824343E+02
     0.1446824E+03    -0.3824484E+02
     0.1446826E+03    -0.3825356E+02
     0.1446876E+03    -0.3825210E+02
     0.1446919E+03    -0.3824719E+02
     0.1447006E+03    -0.3824723E+02
     0.1447042E+03    -0.3825078E+02
     0.1446758E+03    -0.3826229E+02
     0.1446693E+03    -0.3826255E+02
     0.1422483E+03    -0.3839481E+02
     0.1422436E+03    -0.3839315E+02
     0.1422496E+03    -0.3839070E+02
     0.1422543E+03    -0.3839025E+02
     0.1422574E+03    -0.3839155E+02
     0.1422467E+03    -0.3840065E+02
     0.1422433E+03    -0.3840048E+02
     0.1422420E+03    -0.3839857E+02
     0.1422436E+03    -0.3839315E+02
  • The first line contains the name of the file.
  • The second line contains a name which begins a section defining an individual polygon.
  • The third and subsequent lines in the section contain the coordinates of the polygon points in the order longitude, latitude, separated by whitespace. By convention, the coordinates are represented in scientific notation, but Osmosis and osmconvert are flexible about the actual numeric representation.
  • The last line of the polygon section may repeat the starting point to close the circuit. If it is omitted a closing line will be drawn to the start point. If your polygon contains a centroid as the first point, the last line of your polygon section should complete the path to the actual polygon starting point.
  • The polygon section is closed by the text "END" on a line by itself.
  • The polygon section name may optionally be prefixed with "!" to subtract the polygon. The section(s) containing the larger area from which to subtract should be listed first. All the polygon sections are combined together to create the final filter area.
  • If you want to create a filter area which spans the antimeridian (+/-180 degrees), split the polygon at the antimeridian and create additional polygon sections which continue the desired area on the other side.
  • The file is closed by another "END" on a line by itself.

Bounding-polygon task

Example command to extract a polygon using such a file (if was named country.poly, for Osmosis):

osmosis --read-xml file="planet-latest.osm" --bounding-polygon file="country.poly" --write-xml file="australia.osm"

If using osmchange (program):

cat planet-latest.osm | osmchange -B=country.poly >australia.osm

If using mapsplit:

mapsplit europe.osm.pbf /tmp/output -p=country.poly

If using osmconvert:

osmconvert europe.osm.pbf -B=country.poly -o=switzerland.o5m

In the osmosis code see http://svn.openstreetmap.org/applications/utils/osmosis/trunk/areafilter/src/org/openstreetmap/osmosis/areafilter/common/PolygonFileReader.java

Premade polygon files

http://download.geofabrik.de the Geofabrik downloads server gives the .poly files they use to generate their country/region extracts.

Some files for Germany and Austria are in SVN (via TRAC or via SVN).

Files for Russia, Russia's first level administrative regions (buffered and not) and some surrounding countries are here (also includes the description for QGIS extension to generate such files): http://gis-lab.info/qa/osm-poly.html (RU)

A slowly-growing collection of exact-border poly files that are created from cities with an OSM Relation ID is available in this git repository on github: https://github.com/jameschevalier/cities

Converting to/from POLY format

SVN (via TRAC or via SVN) contains a number of scripts to convert to/from POLY files. These include:

  • getbound.pl will convert a boundary relation into a POLY file [2].
  • GPX-to-POLY from geocaching-dresden.de is a web tool to convert an uploaded GPX file to a POLY file.
  • python-osm: the multipolygon.py script/module can read multipolygons and create poly files.
  • JOSM can read and save POLY files with "poly" plugin enabled.
  • polygons.openstreetmap.fr Online tool for extraction, buffering and conversion.
  • OSMPoly_export QGIS plugin for generating Poly from any vector feature(s)

Buffering the Polygon file

Using Quantum GIS

This tutorial shows how to create buffered POLY files using Quantum GIS and the OSM Poly Export plugin. The example uses a country border shape file, but the technique can be applied to any feature you can load into Quantum GIS.

Command line

In case you would like to use a Polygon file of an area with a certain buffer distance, it is possible to use the tool 'polybuffer.py', which can be found here: [3]. For the buffering PostGIS is being used. Requirements:

The instructions can be read by typing "./polybuffer -h" on the command prompt.