We publish frequent updates to our documentation, and translation of this page may still be in progress. For the most current information, please visit the English documentation. If there's a problem with translations on this page, please let us know.

Creating a Country Polygon

В этой статье

This article needs to be reviewed

This article describes how to create a poly(gon) for a missing country in geofabrik.de and how to add this poly to the map generation server of OsmAnd

Introduction

OsmAnd comes with a lot of maps for a lot of countries. Most maps are created from "raw data" maps downloaded from geofabrik.de. Geofabrik supplies these raw data maps for free to everyone and they deliver (commercial) services and products based on these maps.

Geofabrik.de has the strategy to deliver maps for the countries that are requested by larger numbers of users or by their customers. This means that some maps never make it on geofabrik as there are simply not enough requests for (or none at all), like some exotic countries like the Seychelles or Burundi, etc.

Server process

Because of this strategic decision of geofabrik, OsmAnd has an option to generate maps for these countries and the tools OsmAndMapCreator and osmconvert are used for this. For OsmAndMapCreator this is a three step process:

  • OsmAndMapCreator needs a polygon which surrounds the outer border of the country.
  • OsmAndMapCreator needs the "raw data map" from the next higher level incorporating this country. For Burundi it means that OsmAndMapCreator needs the Africa map. For Nordrhein-Westfalen it means that OsmAndMapCreator needs the Germany map.
  • Osmconvert will create a "raw data" map from the poly extracting the map data from the "parent" map.
  • OsmAndMapCreator will create an OsmAnd obf map based on the intermediate "raw data" map generated by osmconvert.

Necessary actions

Depending on the complexity of the (generated) polygon this complete chain of actions can take from 10 minutes to 2 hours in total.

1. Get the OpenStreetMap relation from Nominatim

  • Go to nominatim.openstreetmap.org
  • Fill in your country name
  • Once found click on the link "(details)"
  • In Details scroll down to "OSM: relation " and write down or copy the relation ID number.

2. Generate the polygon

  • Go to polygons.openstreetmap.fr
  • Fill in (or paste) the "OSM: relation " ID number you retrieved from Nominatim for your desired country into the "Id of relation" field.
  • This will create a default polygon, consisting of 250 to 3500 nodes (NPoints). The poly itself can be found in the "poly" column.
  • In case of more then 350 nodes you will need to simplify the polygon. The simpler the polygon, the faster the country map can be created (of course depending on the contents)

3. Simplify the polygon

The number of Node Points (NPoints) needs to be as low as possible for the fastest possible creation of the map by OsmAndMapCreator. As mentioned: In case of more then 350 node points try to reduce them by simplifying the polygon.

  • In case of more then 350 nodes, try to reduce them by "playing" with the X variable (in my experience the others don't really matter)
  • Sometimes you get great results (90 NPoints, 200 NPoints, 270 NPoints) and then you are done with this step. Sometimes you simply can't get below 450 NPoints or so. Then you need to apply further manual steps.
  • Save your final polygon to file. Use the correct default name for it, like france.poly. Stick to lowercase characters.

4. Further modification and simplification of the polygon

  • Open JOSM (download if necessary) and open the polygon file you created (did you make a copy/backup of the original polygon that you saved?).
  • Add a background from the "Images" menu and select the default "OpenStreetMap (Mapnik)" background.
  • Manually remove node points where possible. *Note:* Keep the polygon as close as possible around the border. You do need some overlap but try to keep it below 2-5 kilometers. Overlap in countries will be generated twice for each country. Less overlap, means less rendering time and rendering errors. At coastlines and around islands try to keep more distance (20 kilometers). This is widely acepted and the sea is "empty" anyway.
  • When you have done the best you can you can save the updated, corrected poly. As said: try to get as little node points as possible, but sometimes a country border is so complicated that you simply need more node points to describe it and to keep the polygon as close as possible around the border: so be it.
  • Do not upload the polygon to OSM. JOSM will ask you to upload your work to OpenStreetMap. Don't do this for these polygons unless you know exactly what you do. Almost every country in the world is already perfectly covered in OpenStreetMap (otherwise nominatim would not be able to give you the details about the country, and polygons.openstreetmap.fr would not be able to generate the polygon based on the OSM relation id.)

5. Adding the poly(gon) to the OsmAnd server

To be able to do this you must register as a user.

To make the map generation possible there are two steps required:

  • Adding the polygon to the map data section
  • Adding the country to the data file that is used to generate the OsmAnd obf maps.

Adding the polygon to the map data section

  • Go to the web address of the OsmAnd development server at https://github.com/osmandapp/
  • Select the OsmAnd-misc section.
  • Select "fork" to create your own personal repository
  • Create a new file and copy your poly data inside. Save the file.
  • Create a pull request.

Add the map creation to the batch list

  • Go to the web address of the OsmAnd development server at github.com/osmandapp
  • Select the OsmAnd-tools section.
  • Select "fork" to create your own personal repository.
  • In your personal repository go to the folder obf-generation/regions.
  • Select the file indexes.xml and click edit.
  • Add your country at the relevant location and save the file.
  • Create a pull request.

Creating your own personal maps from a poly

You can create for example polygons from countries, counties/provinces/states, regions and cities.

Say your daughter is going to Paris for a couple of days with a friend. She is not interested in navigation, walking or cycling (unless absolutely necessary), but she wants to know where she is, where to go to and where to find the interesting places (POIs). Next to that she has a small phone (low end CPU, low on memory) and small SD-card (stuffed with music). So the map needs to be as small as possible: both for storage as well as performance. You can of course download the map for france_ile-de-france.obf containing Paris, but you can also generate a "custom made" Paris map.

  • Let your daughter download OsmAnd, or even better: let her buy OsmAnd+
  • Get the OSM relation id for Paris from Nominatim.
  • Get the (simplified) poly for the Paris id from polygons.openstreetmap.fr
  • download or compile osmconvert
  • download "raw data" map of ile-de-france from geofabrik.de
  • create raw data map of Paris from the ile-de-france map and the Paris poly like:
    $ osmconvert ile-de-france.osm.pbf -B=paris.poly --out-pbf > Paris.osm.pbf
    
  • Download the OsmAndMapCreator application from download.osmand.net/latest-night-build/
  • Create your OsmAnd obf map from the Paris.osm.pbf data map using OsmAndMapCreator.

Did this doc help you?

Privacy policy

Help us make these docs great!

All OsmAnd docs are open source. See something that's wrong or unclear? Submit a pull request.

Make a contribution

Or, learn how to contribute.

Все еще нужна помощь?

Join OsmAnd community Поддержка