-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
51 lines (39 loc) · 1.83 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
# Original Code by Jorge Gomes for VOST Portugal
# -----------------------------------------------
# LIBRARIES
# -----------------------------------------------
import geopandas as gpd
import pandas as pd
import plotly.express as px
# -----------------------------------------------
# DATA TREATMENT
# -----------------------------------------------
# Read geojson file
gdf = gpd.read_file('nelas_geo.geojson')
# Change geojson format
gdf.to_crs(epsg=4326, inplace=True)
# Set index column to BGRI2021
gdf.set_index('BGRI2021', inplace=True)
# -----------------------------------------------
# DESIGN MAP
# -----------------------------------------------
# Calculate map and stylize
fig = px.choropleth_mapbox(gdf,
geojson=gdf['geometry'], # geojson source
locations=gdf.index, # common point to get information from
color='N_INDIVIDUOS_RESIDENT', # what column to use for scale
color_continuous_scale="Blues", # what color to use for scale
mapbox_style="open-street-map", # what kind of base map
center={'lat':40.54047095284935, 'lon':-7.8506492725422055}, # where to center the map
zoom=10, # zoom applied to map
opacity=0.8, #opacity for the layers
height=900 # Map height in pixels
)
# Show Map
fig.show()
# -----------------------------------------------
# APP ENDS HERE
# -----------------------------------------------
# Thanks to R-Beginners for the explanation regarding different projection formats
# https://stackoverflow.com/questions/71923114/cant-make-px-choropleth-mapbox-to-draw-multipolygon/71925649?noredirect=1#comment127098083_71925649