GeoJSON Where are You?

I was looking around the web to try and find some services that returned GeoJSON to try out Shapely. It was surprisingly hard to find servers or web services given the amount of tools that have already been built to use GeoJSON.

Eventually I found the CloudMade’s geocoding developer samples. CloudMade is a company that builds tools and services on top of OpenStreetMap. Even though many of the people involved in both CloudMade and OSM are the same, using the two brands interchangeably has not been without controversy.

imageOnce you’ve signed up for a free account, you can then register for an API key that allows you to call their web services. See here for differences between free and paid accounts. The service I was interested in testing was the geocoding service that returns GeoJSON.

Depending on the type of feature you are looking for you can get different geometry types – the standard point, lines, and polygons, all as GeoJSON objects.

The API uses URLs and GET requests to return data. Calls can be made to either a find.html page which returns the GeoJSON object displayed on a map, as shown in the query for “england” on the left. Alternatively the query can be made to find.geojs to return just the GeoJSON itself. There is also a find.js which can be used to return geometry as JSON, although this seems a little confusing – even more so as the coordinate order is reversed from the standard GeoJSON [lon,lat].

The API can be used in several languages (Ruby, Perl, PHP etc.), my current choice is Python, and the CloudMade Python API documentation is available online here. Retreiving GeoJSON however is easy enough even without this API. For example in Python use:

import urllib2

root = 'http://geocoding.cloudmade.com'
apikey = '85453debd0fc4ad18c5855c3d8eef780'
query = 'england'
url = '%s/%s/geocoding/v2/find.geojs?query=%s&return_geometry=true' \
      % (root,apikey,query)

json = urllib2.urlopen(url).read()

print json

Now that I have a source GeoJSON I can start to use some of the more interesting tools to analyse and manipulate these features.



5 views shared on this article. Join in...

  1. Jim says:

    Thanks for the tip! I’ve been using GeoJSON with OpenLayers, and have just been generating the GeoJSON using Excel, I’ve been meaning to write a PHP script to do the conversion, but it looks like this will work even better!

  2. geographika says:

    @Jim
    Please note that the code has been updated to call the find.geojs page rather than find.js which returns JSON rather than GeoJSON.



Pings to this post

  1. […] exactly the same steps), and some additional Python packages. This example uses GeoJSON data from a CloudMade geocoding service. England took a swing to the right after the General […]

  2. […] “cloud service”, I believe the real power of the Internet will come more from manipulating and combining data services than putting desktop applications in a browser. Especially if these applications can’t easily […]

  3. […] maps. But sadly, I couldn’t find a data source that gives me GeoJSON data. People have been lamenting about this unavailability for quiet sometime it seems. My search turned out to be vain. So its time […]


Leave a Reply

Your email address will not be published. Required fields are marked *

Comment

You may use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>