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.1.0.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

map_with_stats-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file map_with_stats-0.1.0.tar.gz.

File metadata

  • Download URL: map_with_stats-0.1.0.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for map_with_stats-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f4d618ea10cdba8dc8accfb4d759a504a8bf62adcbd8b1027da1821978329ec1
MD5 c4ad95eea4efad6c2ddf14b1cca650e0
BLAKE2b-256 e5e9003df478ff1564c7e5eecc0ce8af0ae32adab70f6384ab5989599820c50d

See more details on using hashes here.

File details

Details for the file map_with_stats-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for map_with_stats-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7654b54b948da9d1660689cceaba98aa1d571d50a83e0da17f4a2f010f27c22e
MD5 a1fd924293450fd3087956153898f238
BLAKE2b-256 99e1befc36612baebc2319b7588ef443fa152b82328ee7c903bfaed7533ca063

See more details on using hashes here.

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