Skip to content

Maps workarounds #6

@PyMap

Description

@PyMap

For maps section here https://github.com/PyMap/ssyt/blob/main/ssyt/charts.py#L130-L179

... we use scattermapbox to draw polygon limits. Another option to render this map would be to:

  1. Use plotly animated choroplets
  2. Use folium animated choroplet
  3. Keep the graduated points strategy but using continuous colorscales instead

For polygons we can try to optimize rendering by using topojson format instead of geojson. To go from one format to another:

  1. From terminal
# GeoJson to TopoJson
sudo npm install topojson-server -g
geo2topo das_4326.geojson > das_4326.topojson
toposimplify -p 1 -f < das_4326.topojson > das_4326_simple.topojson
topoquantize 1e5 < das_4326_simple.topojson > das_4326_quantized.topojson

reference: https://medium.com/@mbostock/command-line-cartography-part-3-1158e4c55a1e

  1. Using mapshaper https://mapshaper.org/ to go from gejson to topojson. Then, load the topojson like this:
import json

# load topojson
def get_toronto_das_topodata():
    with open('data/das_toronto.json') as f:
        das_topo = json.load(f)
    return das_topo

topodas = get_toronto_das_topodata()

folium_map = folium.Map(location=coords,
                        zoom_start=8,
                        tiles="CartoDB dark_matter")

folium.Choropleth(geo_data=topo,
             topojson='objects.das_toronto_data_4326',
             key_on='feature.properties.DAUID',
             data=das_toronto[['mean_hh_income','average_dwelling_value','DAUID']], # my dataset
             columns=['mean_hh_income','average_dwelling_value'], 
             fill_color='GnBu', 
             fill_opacity=0.7, 
             line_opacity=0.5).add_to(folium_map)

folium.TopoJson(topodas,
                object_path='objects.das_toronto').add_to(folium_map);

folium_map.add_child(folium.GeoJson(data = open("data/topo_das_toronto_data_4326.json")))

reference: https://github.com/urbansim/ggh_land_selector/blob/toronto_selector/ggh_land_selector/Toronto_focus.ipynb

geojson to topojson references
https://medium.com/tech-carnot/topojson-based-choropleth-visualization-using-folium-471113fa5964#dd2f
https://github.com/carnot-technologies/MapVisualizations

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions