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

Hi,

I have an OSM city map which I export in OSM XML data format and feed into a mobility simulator that pulls the road network out of the map. I now need however to parse the OSM map to get the coordinates of obstacles (buildings only considered)in the map, hopefully in CSV format as I need to import these into a network simulator.

Could someone please let me know if such an xml parser exists to get the coordinates of the buildings or if not could the structure of the tags please be explained so that I can write a parser.

Many thanks in advance.

asked 29 Dec '12, 13:24

kerrymaid's gravatar image

kerrymaid
1333
accept rate: 0%


The easiest would be to write it yourself. There are lots of libraries available for all kind of languages that read XML. The thing you want is quite specific, so there's no ready-made tool available.

The XML in OSM has three primitives: nodes, ways and relations. A node is just a pair of lat/lon coordinates. A way is an ordered list of nodes, and a relation is an ordered list of other types (nodes, ways and other relations). All these features have an id (in the xml denoted with the "id" attribute), these ids are used as reference (so the XML structure of an OSM way is just a list of node ids).

All primitives also have tags, these are stored as separate child XML elements of the type "tag".

So if you're interested in the buildings, you have to filter out all the ways (ways with the same start and end point are also used for surfaces) with a tag building=*, then get the nodes from those ways (via the id) and from those nodes, extract the coordinates (I don't know if you want one average coordinate per building, or if you want all nodes that represent building corners, but you can program both as you wish).

permanent link

answered 30 Dec '12, 11:16

Sanderd17's gravatar image

Sanderd17
1.1k51637
accept rate: 31%

1

... so your starting point to find some tools can be the OSM wiki about http://wiki.openstreetmap.org/wiki/Develop

(31 Dec '12, 07:49) stephan75

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:

×252
×2
×1

question asked: 29 Dec '12, 13:24

question was seen: 8,188 times

last updated: 31 Dec '12, 07:49

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