Maps (datascience.maps)

Draw maps using folium.

class datascience.maps.Map(features=(), ids=(), width=960, height=500, **kwargs)[source]

A map from IDs to features. Keyword args are forwarded to folium.

color(values, ids=(), key_on='feature.id', palette='YlOrBr', **kwargs)[source]

Color map features by binning values.

values – a sequence of values or a table of keys and values ids – an ID for each value; if none are provided, indices are used key_on – attribute of each feature to match to ids palette – one of the following color brewer palettes:

‘BuGn’, ‘BuPu’, ‘GnBu’, ‘OrRd’, ‘PuBu’, ‘PuBuGn’, ‘PuRd’, ‘RdPu’, ‘YlGn’, ‘YlGnBu’, ‘YlOrBr’, and ‘YlOrRd’.

Defaults from Folium:

threshold_scale: list, default None
Data range for D3 threshold scale. Defaults to the following range of quantiles: [0, 0.5, 0.75, 0.85, 0.9], rounded to the nearest order-of-magnitude integer. Ex: 270 rounds to 200, 5600 to 6000.
fill_opacity: float, default 0.6
Area fill opacity, range 0-1.
line_color: string, default ‘black’
GeoJSON geopath line color.
line_weight: int, default 1
GeoJSON geopath line weight.
line_opacity: float, default 1
GeoJSON geopath line opacity, range 0-1.
legend_name: string, default None
Title for data legend. If not passed, defaults to columns[1].
copy()[source]

Copies the current Map into a new one and returns it.

features
format(**kwargs)[source]

Apply formatting.

geojson()[source]

Render features as a FeatureCollection.

overlay(feature, color='Blue', opacity=0.6)[source]

Overlays feature on the map. Returns a new Map.

Args:
feature: a Table of map features, a list of map features,
a Map, a Region, or a circle marker map table. The features will be overlayed on the Map with specified color.

color (str): Color of feature. Defaults to ‘Blue’

opacity (float): Opacity of overlain feature. Defaults to
0.6.
Returns:
A new Map with the overlain feature.
classmethod read_geojson(path_or_json_or_string)[source]

Read a geoJSON string, object, or file. Return a dict of features keyed by ID.

class datascience.maps.Marker(lat, lon, popup='', color='blue', **kwargs)[source]

A marker displayed with Folium’s simple_marker method.

popup – text that pops up when marker is clicked color – fill color

Defaults from Folium:

marker_icon: string, default ‘info-sign’
icon from (http://getbootstrap.com/components/) you want on the marker
clustered_marker: boolean, default False
boolean of whether or not you want the marker clustered with other markers
icon_angle: int, default 0
angle of icon
popup_width: int, default 300
width of popup
copy()[source]

Return a deep copy

format(**kwargs)[source]

Apply formatting.

geojson(feature_id)[source]

GeoJSON representation of the marker as a point.

lat_lons
classmethod map(latitudes, longitudes, labels=None, colors=None, areas=None, **kwargs)[source]

Return markers from columns of coordinates, labels, & colors.

The areas column is not applicable to markers, but sets circle areas.

classmethod map_table(table, **kwargs)[source]

Return markers from the colums of a table.

class datascience.maps.Circle(lat, lon, popup='', color='blue', radius=10, **kwargs)[source]

A marker displayed with Folium’s circle_marker method.

popup – text that pops up when marker is clicked color – fill color radius – pixel radius of the circle

Defaults from Folium:

fill_opacity: float, default 0.6
Circle fill opacity

For example, to draw three circles:

t = Table().with_columns([
‘lat’, [37.8, 38, 37.9], ‘lon’, [-122, -122.1, -121.9], ‘label’, [‘one’, ‘two’, ‘three’], ‘color’, [‘red’, ‘green’, ‘blue’], ‘radius’, [3000, 4000, 5000],

])

Circle.map_table(t)

class datascience.maps.Region(geojson, **kwargs)[source]

A GeoJSON feature displayed with Folium’s geo_json method.

copy()[source]

Return a deep copy

format(**kwargs)[source]

Apply formatting.

geojson(feature_id)[source]

Return GeoJSON with ID substituted.

lat_lons

A flat list of (lat, lon) pairs.

polygons

Return a list of polygons describing the region.

  • Each polygon is a list of linear rings, where the first describes the exterior and the rest describe interior holes.
  • Each linear ring is a list of positions where the last is a repeat of the first.
  • Each position is a (lat, lon) pair.
properties
type

The GEOJSON type of the regions: Polygon or MultiPolygon.