NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum


How do I extract the polygon of an administrative boundary from an OSM file?

asked 04 Oct '11, 09:32

fhedberg's gravatar image

accept rate: 0%

edited 25 Nov '13, 14:49

aseerel4c26's gravatar image

aseerel4c26 ♦

Here is an online tool to do that :

Give it the id of the administrative relation (or whatever polygon relation), it outputs result in .poly, WKT (Gis format) and a nice image to view it ;-)

It also offers geometry simplification and extended buffer. It supports pyramidal relation

permanent link

answered 06 Nov '12, 00:35

sly's gravatar image

accept rate: 25%

edited 30 Jul '14, 23:55

THANK YOU! It is a great tool!

(28 Feb '14, 09:13) exec

One more addition:;>;);out;

is even faster than the api/.../full call and preferable, because then api/full call causes significant load on the main api.

permanent link

answered 01 Nov '12, 19:02

Roland%20Olbricht's gravatar image

Roland Olbricht
accept rate: 36%


... and see about more documentation for overpassAPI

(04 Nov '12, 17:38) stephan75

You could use this Perl script:

It requires a "full" extract of the administrative boundary relation on input and has some limitations (see comments at the top of the file).

There's also a much more complex script that extracts all boundaries from a given OSM extract and can optionally write polygons:

If you intend to use the polygon for making extracts, it may be wise to simplify it before use as extracting may take very long if the polygon is too big. Simplifying the polygon might, however, clip off bits, and you might want to look for a simplification algorithm that guarantees that the simplified polygon contains the original polygon.

permanent link

answered 04 Oct '11, 09:40

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
accept rate: 23%

edited 04 Oct '11, 09:40

In addition to Frederick's suggestions above, I used to create a boundary polygon for my local district. I didn't simplify it though, and the speed comparisons mentioned at suggest polygon vs bbox is over 20 times slower in my case.

(04 Oct '11, 09:47) EdLoach ♦

How I've done it:

  1. Download the data: wget -O auvergneRel.osm
  2. open the data in JOSM
  3. delete all tags contained in the data
  4. merge the ways
  5. save your data, and run perl auvergneRel.osm > auvergne.poly

I have never tested script. I haven't found a scripted way for merging the ways (deleting the tags is possible with osmosis by using a tagtransform filter).

I've used successfully this method several times. Hope that helps…

permanent link

answered 04 Oct '11, 09:55

NicolasDumoulin's gravatar image

accept rate: 13%

There is a "poly" plugin for JOSM that lets you save your data directly as a .poly file.

(23 Jul '18, 15:23) Frederik Ramm ♦

It depends, of course, of the format you want. Convert as written above.

  • Display any part of the map in JOSM.
  • File>new layer
  • Select what you want
  • Edit>Merge Selection -> new layer

Repeat Select+Merge as many times as needed
With new layer active,

  • File>Save As... -> layer -> xxx.osm file
  • same to save xx.gpx, xxx.json or compressed OSM files.

A new layer is useful to display only the data you want to edit or save. Example with your boundary:

  • display it in the main layer.
  • in Relations window, right-click your boundary>Select relation
  • Edit>Merge Selection -> new layer

With new layer active,

  • right-click your boundary>Download incomplete members
  • -> your boundary to be a polygon

If your admin_level relations contain admin_level+x relations as subareas (a very good idea), you can download whole chunks of boundaries going from one to the parent or child.
You may save your work to an osm.file. But if you reload that file later, do:

  • Edit>Select all File>Update selection
  • to keep your data in sync, else you may get nasty conflicts to solve.


If you delete something aesthetically in a layer, DO NOT File>Update data in that layer, JOSM would actually delete that something from the real data. It is especially important to SAY NO to update suggestions when you close (Delete) a layer, or File>Exit JOSM, or reload a saved file where such condition exists. You might carelessly delete huge amounts of data that way.

!!! Always carefully check what JOSM says it's going to do when updating the server.

permanent link

answered 27 Feb '13, 22:19

GentilPapou's gravatar image

accept rate: 0%

Tried to use but it doesnt seems working properly with inner rings. Eg. try to look at relation 62657, you will see that it generates WKT with 2 polygons, where both are outer. It can be easily checked here:

So there is web scraping service with geo functionality, which has free tier so can be freely used for conversion. If you need to convert more than 5000 relations, you can compile scraper to run on your local computer / server without limitations. Below is a code for the scraper that do conversion job:

    debug: 2
    agent: Chrome
- type: csv
  name: relation
  value: "62657,62554,62378"
- geo:
    - wkt:
        relation: <%relation%>
        - find:
            path: wkt
            - object_new: item
            - parse
            - object_field_set:
                object: item
                field: wkt
            - argument_get: relation
            - object_field_set:
                object: item
                field: relation
            - object_save:
                name: item

There is nore geo functionality available, you can read documentation

permanent link

answered 23 Jul '18, 12:49

Jako2008's gravatar image

accept rate: 0%

edited 23 Jul '18, 12:50


OpenStreetMap's data is primarily released as raw data, and only secondarily in the form of web pages. Why anyone would want to scrape web sites using a third party tool instead of just using the data that is readily published, is beyond me.

(23 Jul '18, 15:22) Frederik Ramm ♦

I tried to implement on the maps on the website administrative outlines for individual towns, but without success :(

permanent link

answered 06 Jan '22, 12:33

Przymorzu's gravatar image

accept rate: 0%

edited 06 Jan '22, 12:37

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 04 Oct '11, 09:32

question was seen: 51,648 times

last updated: 06 Jan '22, 12:37

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum