Cambridge Geo Data

This tutorial assumes that you have snowfloat-python installed already.

Sign up

First step is to sign up for free to the API and take note of your API keys.

Add the following to snowfloat.conf in your home directory:

[snowfloat]
api_key_id = your API key ID (no quotes)
api_secret_key = your API secret key (no quotes)
# Cambridge GIS API key ID.
user_api_key_id = 3KL1XQQSP2T3PN736M5N
# Cambridge GIS API sharing key.
user_api_sharing_key = 4UXBzvSNuxAdwf4LnwZtYi/R4R2/8T6Re6ClAtJa

Make sure that your API key ID is accessible when settings is imported.

>>> import snowfloat.settings
>>> snowfloat.settings.API_KEY_ID
'your API key ID'

Get layers

Let’s create a client instance:

>>> import snowfloat.client
>>> client = snowfloat.client.Client()

We can get the name and UUID of each layer:

>>> layers = client.get_layers()
>>> ['%s: %s' % (layer.name, layer.uuid) for layer in layers]
[u'ADDRESS_AddressPoints: ecf03fb0e1f34773b53959a2c603e214',
 ...
 u'BOUNDARY_CDDNeighborhoods: dcf14c6fddb34e4da13696f96499d065',
 ...
 u'RECREATION_PublicPools: 5b7b021673444c078bcd5519b0e12420',
 u'RECREATION_Playgrounds: b246cac002104f56afbb0e3e2d9031a1',
 ...
 u'TRANS_SubwayStations: 32d771c0bc0641eb9fc5c2f04305ecb9']

Get layer’s features

We want to retrieve the list of public pools in Cambridge. The public pools layer’s UUID is “5b7b021673444c078bcd5519b0e12420”. We also ask for the centroid of each feature’s geometry.

>>> pools = client.get_features('5b7b021673444c078bcd5519b0e12420',
...                             spatial_operation='centroid')
>>> len(pools)
3

We can inspect the first pool in the list: its name and its cendroid geometry.

>>> pools[0].fields
{u'name': u'McCrehan Memorial Pool', u'owner': u'State'}
>>> pool_geometry = pools[0].spatial
>>> pool_geometry
Point(coordinates=[-71.13719699898544, 42.39477486726984])

Spatial queries

Let’s find the playgrounds in a radius of 100 meters from the pool’s centroid geometry. The playgrounds layer’s UUID is “b246cac002104f56afbb0e3e2d9031a1”.

>>> playgrounds = client.get_features('b246cac002104f56afbb0e3e2d9031a1', query='distance_lt', distance=100, geometry=pool_geometry)
>>> len(playgrounds)
1
>>> playgrounds[0].fields
{u'globalid': u'{A8D1B0C2-A020-4E6C-9540-21B42F0B6A71}',
 u'location': u'Russell Field Tot Lot'}

We want to know in which neighborood the “McCrehan Memorial” pool is located. The neighborhoods layer’s UUID is “dcf14c6fddb34e4da13696f96499d065”.

>>> neighborhoods = client.get_features('dcf14c6fddb34e4da13696f96499d065', query='contains', geometry=pool_geometry)
>>> neighborhoods[0].fields
{u'globalid': u'{93DD8D8A-FDFD-4971-A154-BACFE1FFF1DD}',
 u'n_hood': u'11',
 u'name': u'North Cambridge',
 u'webpage': u'http://www.cambridgema.gov/CDD/planud/neighplan/neighs/11.aspx'}

If you have questions or comments, please email me at SnowFloat Help.

See Tutorial for a more general tutorial on SnowFloat.

Table Of Contents

This Page