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

8
3

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

asked 04 Oct '11, 09:32

fhedberg's gravatar image

fhedberg
121233
accept rate: 0%

edited 25 Nov '13, 14:49

aseerel4c26's gravatar image

aseerel4c26 ♦
32.6k18248554


Here is an online tool to do that : http://polygons.openstreetmap.fr/index.py

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

sly
290129
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:

http://overpass-api.de/api/interpreter?data=(rel(8638);>;);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
6.7k36489
accept rate: 36%

1

... and see http://wiki.openstreetmap.org/wiki/Overpass_API about more documentation for overpassAPI

(04 Nov '12, 17:38) stephan75

You could use this Perl script:

http://svn.openstreetmap.org/applications/utils/osm-extract/polygons/rel2poly.pl

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:

http://svn.openstreetmap.org/applications/utils/gary68/boundaries.pl

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 ♦
82.5k927201273
accept rate: 23%

edited 04 Oct '11, 09:40

In addition to Frederick's suggestions above, I used http://osm2mp.googlecode.com/svn/trunk/getbound/getbound.pl to create a boundary polygon for my local district. I didn't simplify it though, and the speed comparisons mentioned at http://wiki.openstreetmap.org/wiki/Tendring(Essex_District)#Data_Extracts 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 http://api.openstreetmap.org/api/0.6/relation/8638/full
  2. open the data in JOSM
  3. delete all tags contained in the data
  4. merge the ways
  5. save your data, and run osm2poly.pl: perl osm2poly.pl auvergneRel.osm > auvergne.poly

I have never tested rel2poly.pl 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

NicolasDumoulin
3.3k42256
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.

BEWARE BEWARE

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

GentilPapou
160146
accept rate: 0%

Tried to use http://polygons.openstreetmap.fr/index.py 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: https://clydedacruz.github.io/openstreetmap-wkt-playground/.

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:

---
config:
    debug: 2
    agent: Chrome
iterator:
- type: csv
  name: relation
  value: "62657,62554,62378"
do:
- geo:
    do:
    - wkt:
        relation: <%relation%>
        do:
        - find:
            path: wkt
            do:
            - 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

Jako2008
111
accept rate: 0%

edited 23 Jul '18, 12:50

1

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 www.przymorzu.pl administrative outlines for individual towns, but without success :(

permanent link

answered 06 Jan '22, 12:33

Przymorzu's gravatar image

Przymorzu
11
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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×92
×92
×83
×68

question asked: 04 Oct '11, 09:32

question was seen: 52,394 times

last updated: 06 Jan '22, 12:37

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