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


I'm brand new to OSM data, so please be patient with me :)

I want to extract administrative (or for that sake all named) polygons from OSM data. I have read, but it does not work for me. Here's what happens on my machine:

$ bzcat great_britain.osm.bz2 | perl 

I assume that is due to the process running out of memory (It's a VM without swap space...). However, I am not entirely sure that script does what I want. I read somewhere that it translates full relations to polygons. And AFAI understand, there are no full relations in the OSM extracts? I also don't speak pearl to check. If I was to write a python (right choice?) script to derive named polygons from OSM extracts how would I process the data? Here's my understanding of the data. Pleas correct me where I'm wrong:

  1. Nodes are points on the map having lat/lons.
  2. Ways are collections of nodes. There are closed ways (polygons) and opened ways (paths)
  3. Relations connect ways and nodes. All ways of a relation form polygons too.
  4. All of the above (nodes, ways and relations) have tags containing meta data as names, types, links, and so on.
  5. In the extract I downloaded the relations contain references to nodes and ways, but not the nodes and ways themselves.

So my script would have to

  1. load all nodes
  2. load all ways
  3. expand all ways with the referenced nodes
  4. load all relations
  5. expand all relations with the referenced ways
  6. for every relation that has a name tag, list the latlons of the nodes on the ways.

Is that right? Is that what the perl script does anyways? Is it easier/faster to load the data into postgres using one of the available tools instead of processing the data in a script?

All suggestions are appreciated! K

asked 31 Oct '12, 22:25

konstantin's gravatar image

accept rate: 0%

Just to get around the memory issue (and to see if it actually does what you want) maybe try a smaller input file, like perhaps one of the English counties from here?

(31 Oct '12, 23:01) SomeoneElse ♦

You can use the administrative boundary data only as input. This reduces the amount of data by orders of magnitude.

For example[name="United Kingdom"];>;);out;

will return exactly the boundary data of the nation "United Kingdom".

permanent link

answered 01 Nov '12, 19:17

Roland%20Olbricht's gravatar image

Roland Olbricht
accept rate: 36%

Extracting multipolygon data from OSM is hard. Don't try to write the code yourself, there are already several implementations out there that do that. I always recommend Osmium/osmjs, but I am biased. :-)

permanent link

answered 01 Nov '12, 08:36

Jochen%20Topf's gravatar image

Jochen Topf
accept rate: 31%

Ha, Jochen, now I understand how you're biased! Osmium seems like a tool that could do what I need. I will give it a shot. However, you mention several implementations, the most popular probably being Osmosis. Are there more? Could you point me there?


(01 Nov '12, 10:10) konstantin

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: 31 Oct '12, 22:25

question was seen: 8,181 times

last updated: 01 Nov '12, 19:17

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