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'uk_statistical_boundaries/geojson')

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')