Getting started

Feature Collections

The main argument required by many Geoplot functions feature_collection is a Python dictionary containing the contents of a GeoJSON FeatureCollection. You can customise which property to use as the index. The default is 'id'.

GeoJSON FeatureCollections for various UK geographies are available insherlockml_extras.opendata. To list available GeoJSONs:

In [1]:
from sherlockml_extras import opendata
opendata.ls('uk_statistical_boundaries/geojson')
Out[1]:
['/input/geojson/',
 '/input/geojson/local_authorities.json',
 '/input/geojson/lower_super_output_areas.json',
 '/input/geojson/middle_super_output_areas.json',
 '/input/geojson/output_areas.json',
 '/input/geojson/parliamentary_constituencies.json']

and to load, for example, the boundaries of th UK parliamentary constituencies:

In [2]:
pcon_geojson = opendata.load('uk_statistical_boundaries/geojson/parliamentary_constituencies.json')

Create a map

Now let’s use geoplotz to make a folium map centred on the feature collection:

In [3]:
from sherlockml_extras import geoplot
folium_map = geoplot.centred_map(pcon_geojson)

We can generate a data point for each feature in the dataset:

Generate sample data

In [4]:
import numpy as np

def lat(feature):
    coords = feature['geometry']['coordinates']
    while not isinstance(coords[0], (int, float)):
        coords = coords[0]
    return coords[1]

areas = np.array([feat['properties']['id'] for feat in pcon_geojson['features']])
data = np.array([lat(feat) for feat in pcon_geojson['features']])

Plot a single-colour map

In [5]:
geoplot.single_colour(folium_map, pcon_geojson, 'red')
folium_map
Out[5]: