Osmosis/Polygon Filter File Format
The Osmosis polygon filter file format is supported by Osmium, mapsplit, osmconvert, osmchange and Osmosis as a way of defining extraction polygons.
- For OSM Polygons, see Multipolygon relation.
Example
australia_v first_area 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 END second_area 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 END END
- 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.
- Several of these files may be combined to one multi-sectioned file. In this case each section must be separated from its preceding section by an empty line (combined files are used by the programs osmrelpoly and osmassignpoly).
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 mapsplit:
mapsplit europe.osm.pbf /tmp/output -p=country.poly
If using osmconvert:
osmconvert europe.osm.pbf -B=country.poly -o=switzerland.o5m
Example command to extract all border polygons from a pre-filtered file using osmrelpoly:
osmrelpoly borders.o5m --simplify=10 --add-admin-levels=";admin_level=" -o=borders.poly
In the osmosis code see https://svn.openstreetmap.org/applications/utils/osmosis/trunk/areafilter/src/org/openstreetmap/osmosis/areafilter/common/PolygonFileReader.java
Premade polygon files
https://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:
- osm2poly.pl and poly2osm.pl to convert to/from OSM XML
- gpx2poly.pl to convert GPX files to OSM XML
- ogr2poly.py to convert OGR supported files (including GPX and Shapefile) to multiple POLY files named by an attribute
- polyconvert.pl combines the prior scripts to allow converting to/from OSM XML, GPX, and WKT
- fast_complete_poly_filter.pl to more quickly filter (extract) OSM data with a POLY via Osmosis
Other software programs, libraries and services to convert from/to POLY files are:
- poly2geojson is a lightweight and fast tool to convert a Polygon file to a GeoJSON
- polygon2geojson.py converts a Polygon file to a GeoJSON
- Python function parse_poly() to convert textual POLY file to a Shapely geometry.
- Python function parse_poly() to convert textual POLY file to a GeoDjango MultiPolygon geometry.
- getbound.pl will convert a boundary relation into a POLY file [1].
- 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)
- Osmosis-Polygonhull-Creator calculate a custom bounding polygon (.polyfile) around a given .gpx file
- osmosis2geojson from POLY to GeoJSON
- GeoDesk - The
gol query
command outputs.poly
files based on OSM features (use option-f=poly
). The GeoDesk Java library also contains classes for reading/writing polygon files.
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: [2]. For the buffering PostGIS is being used. Requirements:
The instructions can be read by typing "./polybuffer -h" on the command prompt.