Using Geonames.org webservice from .Net

Tags: , , ,
Add comments

Lately I was looking for a way to translate geo coordinates (latitude and longitude form my gps device) to some sort of text or names. As you know I’m trying to geotag my photos using a gps logger and PhotoTagStudio. This data can be used to visualize the place a photo was taken on a map (e.g. Google Maps or flickr!). The next step can be to use this data to describe the photo as well.

I think one should be able to translate a geo coordinate into at least the name of the county, the state and the city; maybe to the district or a street name, too. To achieve this I found the geonames.org webpage. This page collects exactly the data I need and allows searching via the website and a webservice.

The webservice itself consists of approximate 30 REST methods one can call by querying an URL. Most of these calls return a XML document (or optional a JSON document). Unfortunately  there is no SOAP / WSDL version of this webservice. For a .net and C# developer a SOAP webservice is very easy to consume but for such a REST / XML webservice you have to create the URLs yourself and parse the resulting XML document.

I started to create a library to query the webservice. This library provides a few static methods mapped to the most useable webservice-methods and returns good shaped .Net objects. These objects carry all the data coming from the webservice. At the moment this library is in an early beta status but you can use it in your own projects. It can be found on Codeplex: GeonamesDotOrgDotNet, there you will find a small example and a demo application. When using this library you should take a look at the documentation of the geonames.org webservices since the interfaces are nearly the same.

I hope this is useful for someone. I will extend the library in the next weeks. Feature requests are welcome, so is help on the coding side.

Currently the following webservice calls are supported:

  • findNearby
  • findNearbyPlaceName
  • findNearByWeather
  • findNearbyWikipedia
  • get
  • hierarchy
  • children
  • gtopo30
  • srtm3

At the end a few random screenshots and a code snippet. For more information please take a look at the Codeplex project page.

// finding some place in Berlin, Germany
// (using prefix m for decimal literals)
Geoname Place =
GeoNamesOrgWebservice.FindNearbyPlaceName(52.51m, 13.4m);

// getting all parents
IEnumerable ParentPlaces = Place.Hierarchy();

// display the partents
// (will print out something like:
//  “Globe > Europe > Germany > Land Berlin > Berlin >”)
foreach (Geoname x in ParentPlaces)
Console.Write(x.Name + ” > “);

The Classes of the Library:

classes

A screenshot of the demo application to test the library:

testapp

One Response to “Using Geonames.org webservice from .Net”

  1. tanvir Says:

    hi,

    its very usefull

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in