Yak Shaving

just me

SimpleGeo

without comments

While pottering about I found SimpleGeo.

I’m still struggling a little for a use case for this. It’s cool and that’s enough for me, yes I am that fickle.

Its a simple enough idea and well implemented. You sign up for free. The free account gives you a single “layer”. A layer is a collection of data points that you wish to map. Paid for accounts allow more layers but as I’m only playing I’m not about to find out. Python is well supported but not very well documented.

http://help.simplegeo.com/faqs/api-documentation/clients-and-example-code contains what you need to get the libs downloaded and running. From here on I’m going to assume you have got it installed and running.

Creating a record:

from simplegeo import Record
r = Record('layername', '1', '53.762282', '-0.355662')
r

client.add_record(r)
b = client.add_record(r)
print client.get_record('layername', '1')
{'created': 1270653503, 'geometry':
{'type': 'Point', 'coordinates': [-0.35566199999999998, 53.762281999999999]},
'properties': {'layer': 'layername', 'type': 'object'},
'layerLink': {'href': 'http://api.simplegeo.com/0.1/layer/layername.json'},
'type': 'Feature', 'id': '1', 'selfLink':
{'href': 'http://api.simplegeo.com/0.1/records/layername/1.json'}}

The code above creates and saves a record on Simple Geo’s servers and fetches the same record. Its all pretty simple stuff. Where it gets cool is using get_nearby. This allows you to send a location and get back all data points near that location.

print client.get_nearby(layer='layername',arg='53.762281,-0.3456')
{'type': 'FeatureCollection', 'features': [
{'distance': 355.3372151292516, 'created': 1270659182, 'geometry':
{'type': 'Point', 'coordinates': [-0.35099999999999998, 53.762281999999999]},
'properties': {'layer': 'layername', 'type': 'place'}, 'layerLink':
{'href': 'http://api.simplegeo.com/0.1/layer/layername.json'},
'type': 'Feature', 'id': '1', 'selfLink':
{'href': 'http://api.simplegeo.com/0.1/records/layername/1.json'}},
{'distance': 960.75183289629251, 'created': 1271073482, 'geometry':
{'type': 'Point', 'coordinates': [-0.33100000000000002, 53.762281999999999]},
'properties': {'layer': 'layername', 'type': 'place'},
'layerLink': {'href': 'http://api.simplegeo.com/0.1/layer/layername.json'},
'type': 'Feature', 'id': 'TheAdelphi', 'selfLink':
{'href': 'http://api.simplegeo.com/0.1/records/layername/TheAdelphi.json'}}]}

Pushing the coolness a bit further is get_density. This takes a location and using Sky Hooks’ Spot Rank will predict the density of people in the supplied location.

print client.get_density('51.5019', '-0.1189', 'tue')

Also worth a mention is the method get_history. This will return the last 20 locations of the record with the supplied id.

print client.get_history('layername', '1')
{'type': 'GeometryCollection', 'geometries': [
{'type': 'Point', 'coordinates': [-0.35099999999999998, 53.762281999999999],
'created': 1270659182},
{'type': 'Point', 'coordinates': [-0.35099999999999998, 53.762281999999999],
'created': 1270659072},
{'type': 'Point', 'coordinates': [-0.35566199999999998, 53.762281999999999],
'created': 1270653503}]}

While this is all very cool the only gotcha I have found is that longitude and latitude can be the wrong way round. So if you are getting no hits check the long and lat from get_record are the right way round. This is mentioned in the documentation on the Simple Geo’s site.

Another super cool feature is the dashboard offered when you login to Simple Geo’s site. There is a Google maps instance which you can use to find you data on. Handy for debugging.

Due to the almost total lack of documentation I worked out most of the above using source http://github.com/simplegeo/python-simplegeo/blob/master/simplegeo/__init__.py. Its simple enough to read.

Once I find a use for this I will write up some stuff. In the mean time if you get stuck give me a shout, chances you will be stuck at the same point I was…

Written by channam

April 24th, 2010 at 7:56 pm

Posted in python

Tagged with

Leave a Reply