Contents Prev: Data model Next: Iterators and readers: counting elements

Hello World

The following example downloads a sample dataset that contains the node that represents the Big Ben in London and prints out information about that node. Therefore, it opens a stream to retrieve the sample file from our server and creates an OsmXmlIterator using the InputStream as constructor argument.

We can then iterate through the elements using a for-each loop. The iterator returns EntityContainers that wrap the actual objects. We check whether the object is a node using the getType() method and then retrieve the actual object using the getEntity() method and cast it to a OsmNode.

Once we have the OsmNode, we can print its id and the coordinate. Using another for loop, we can also print each tag by retrieving the i-th tag using the getTag(i) method.

Here's the output:

id: 1802652184
latitude: 51.5006617
longitude: -0.1245829
tags:
amenity = clock
display = analog
faces = 4
historic = technical_monument
name = Big Ben
support = tower
tourism = attraction
visibility = area
wikipedia = en:Big Ben
Contents Prev: Data model Next: Iterators and readers: counting elements