Hi!

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 https://help.openstreetmap.org/questions/8273/how-do-i-extract-the-polygon-of-an-administrative-boundary, but it does not work for me. Here's what happens on my machine:

$ bzcat great_britain.osm.bz2 | perl rel2poly.pl 
Killed

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

konstantin
61446
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

http://overpass-api.de/api/interpreter?data=(rel[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
6.3k35885
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
4.4k54564
accept rate: 34%

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?

Thanks!

(01 Nov '12, 10:10) konstantin
Your answer
toggle preview

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:

×74
×71
×1

question asked: 31 Oct '12, 22:25

question was seen: 5,927 times

last updated: 01 Nov '12, 19:17

powered by OSQA