This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

OSM XML Polygon Code Example

0

I want to know how to write code for polygon in OSM XML, I have tried to find it on internet but have not found something useful. SO Please let me know or give me some example of OSM XML Polygon Code.

asked 02 Apr '12, 20:12

Parveen%20Arora's gravatar image

Parveen Arora
16113
accept rate: 0%

edited 25 Jun '13, 00:58

aseerel4c26's gravatar image

aseerel4c26 ♦
32.6k18248554

2

What exactly are you trying to do? There are a lot of things you can do with polygons.

(02 Apr '12, 20:26) Gnonthgol ♦

I just need a little example of polygon code to view it.

(02 Apr '12, 20:39) Parveen Arora

2 Answers:

4

Here's the simplest possible polygon, a triangle:

<way id="1" version="1" user="test" uid="1" changeset="1" timestamp="...">
  <nd ref="1" />
  <nd ref="2" />
  <nd ref="3" />
  <nd ref="1" />
  <tag k="building" v="yes" />
</way>

A polygon is just a way where first and last nodes are the same, and where the tags indicate that it is an area. (The same structure with a tag of junction=roundabout would not be interpreted as an area.)

More complex polygons - those with holes or where the outline is made up of several ways - are modeled using the multipolygon relations which is a bit of a misnomer since it is also used for polygons that are not "multi".

answered 03 Apr '12, 00:41

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

1

Usually you can click on any polygon in the map of www.openstreetmap.org while selecting the view data layer. From there it is possible to select a polygon and from the details page you can view the XML.

answered 02 Apr '12, 21:19

frabron's gravatar image

frabron
3611411
accept rate: 16%

Source code available on GitHub .