Skip to main content

Interactive map with a choropleth displaying some statistics as color per hectare

Project description

Map with statistics

release @ PYPI python version platform CI status Docs status linter testing typing docs versioning code style: black documentation

The package allows to display an interactive map with a choropleth displaying some statistics as color per hectare (100x100 meter square).

The package is created and tested to work for the Switzerland coordinates, however, one could try to use it for any other map with hectare statistics.

Example map

Installation

pip install map_with_stats

Quick guide

For visualisation you will need some statistics per hectare. Individual hectares are defined by the X,Y coordinates in the LV03 coordinate system of the bottom-left (=south-west) corner.

  1. Such data could be for example downloaded from the BFS website.
    • For example, one can get population data per hectare for year 2021 from here.
  2. Download and extract STATPOP2021.csv from the archive.
  3. Generate the HTML with the map:
    import pandas as pd
    
    import map_with_stats as mws
    
    
    data_raw = pd.read_csv("STATPOP2021.csv", sep=";")
    data = data_raw[["RELI", "B21BTOT"]]
    # `hectare2xy` is a helper function that extracts X,Y coordinates from the hectare ID
    data = mws.hectare2xy(data, "RELI")
    # `create_geo_df_with_hectar_polygons` is a helper function that creates GeoDataFrame with a polygon for each hectare
    gdf_stats = mws.create_geo_df_with_hectar_polygons(data, "B21BTOT", crs_out="EPSG:4326")
    
    # restrict data to the Zürich neighbourhood - this step is optional
    mask_x = data["X"].between(6700_00, 7000_00)
    mask_y = data["Y"].between(2330_00, 2630_00)
    gdf = gdf_stats[mask_x & mask_y]
    
    # `build_map` is the main helper function that will create a map with a coropleth layer
    title = "Dummy data"  # the to be used as data description in the tooltip and colormap
    map = mws.build_map(gdf, title, "equidistant", n_bins=5)
    map.save("map.html")
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

map_with_stats-0.0.5.tar.gz (5.4 MB view hashes)

Uploaded Source

Built Distribution

map_with_stats-0.0.5-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page