Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maps workarounds #6

Open
PyMap opened this issue Nov 30, 2021 · 0 comments
Open

Maps workarounds #6

PyMap opened this issue Nov 30, 2021 · 0 comments
Assignees
Labels

Comments

@PyMap
Copy link
Owner

PyMap commented Nov 30, 2021

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

@PyMap PyMap added the visprev label Nov 30, 2021
@PyMap PyMap self-assigned this Nov 30, 2021
@PyMap PyMap changed the title Alternatite maps Maps workarounds Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant