import geopandas as gpd import geojsonio import pandas as pd # Set up the simple style spec mapping of highway to color and width highway = ['motorway', 'trunk', 'primary', 'secondary', 'tertiary', 'residential'] # Colors pasted from colorbrewer2.org, qualitative, 7-class Set1 (removing the yellow color) colors = """ #e41a1c #377eb8 #4daf4a #984ea3 #ff7f00 #a65628 """.split() widths = range(len(highway), 0, -1) # Countdown so smallest is width 1 # 'stroke' and 'stroke-width' are the defined properties for line color/width: # http://github.com/mapbox/simplestyle-spec style = pd.DataFrame({'stroke': colors, 'stroke-width': widths, 'highway': highway}) style # Load up the OSM data df = gpd.read_file('cambridge_raw_osm.geojson') df_styled = gpd.GeoDataFrame(df.merge(style, on='highway')) geojsonio.embed(df_styled.to_json(na='drop'))