API
build_map(gdf_stats, title, bins_type, n_bins=5, clip_quantile=0.01, map_tiles_provider='OpenStreetMap', optimise_choropleth_size=True, coordinates_start=(47.39, 8.53), zoom_start=15, max_n_hectares_to_display=None, plot_boundaries=False, fill_opacity=0.6)
¶
Generate a folium map with the some statistics per hectare added as a choropleth alayer on top.
See FAQ for detailed explanation and typical use-cases of more complex attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdf_stats |
GeoDataFrame
|
input table with the hectare polygons and statistics values. |
required |
title |
str
|
the name to be displayed as the color-map title as well as the entry in the control panel. |
required |
bins_type |
str
|
The type of binning for the choropleth. Accepted values are "equidistant" and "quantiles" that would define bins either on the linear or on the quantile scale. |
required |
n_bins |
int
|
number of bins to use. Defaults to 5. |
5
|
clip_quantile |
Optional[float]
|
clip/winzorise statistics values to specific quntiles. The effect is double-sided. Set to None to avoid any clipping. Defaults to 0.01. |
0.01
|
map_tiles_provider |
str
|
Map tileset to use. The value is passed over to folium.Map. Defaults to "OpenStreetMap". |
'OpenStreetMap'
|
optimise_choropleth_size |
bool
|
Set to True to reduce precision of polygon coordinates to a pre-defined optimised value that will keep hectare boundary precision. This allows to reduce the size of the map HTML dump on disk. Defaults to True. |
True
|
coordinates_start |
Tuple[float, float]
|
starting coordinated in longiotude and latitude. Defaults to (47.39, 8.53) [Zürich]. |
(47.39, 8.53)
|
zoom_start |
int
|
starting zoom. Defaults to 15. |
15
|
max_n_hectares_to_display |
Optional[int]
|
the top-N hectares to display. Defaults to None. |
None
|
plot_boundaries |
bool
|
set to True to display boundaries between choroplet elements. This is useful if you visualise not hectares but some administrative entities. Defaults to False. |
False
|
fill_opacity |
float
|
opacity of the choropleth. Defaults to 0.6. |
0.6
|
Raises:
Type | Description |
---|---|
ValueError
|
unsupported |
Returns:
Type | Description |
---|---|
Map
|
folium.Map: the map with cholopleth layer |
Source code in src/map_with_stats/map.py
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
create_geo_df_with_hectar_polygons(df, col_value, crs_out='EPSG:4326', crs_in='EPSG:21781', grid_size=100)
¶
Generate hectare polygons.
Given a pandas dataframe with "X", "Y" coordinates of the bottom-left (south-west) corner
of the hectares and a column col_value
with values, create a geopandas geodataframe with
hectare polygons and the selected column with values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
input data. The code expects to find the following columns: "X", "Y", |
required |
col_value |
str
|
column name with some values |
required |
crs_out |
str
|
coordinate system to which output polygons are transformed. Defaults to "EPSG:4326". |
'EPSG:4326'
|
crs_in |
str
|
coordinate system of the input data. Defaults to "EPSG:21781" (=LV03). |
'EPSG:21781'
|
grid_size |
int
|
grid size in meters. Defaults to 100 ()i.e. hectar. |
100
|
Returns:
Type | Description |
---|---|
GeoDataFrame
|
gpd.GeoDataFrame: a table with hectare polygons and the values. |
Source code in src/map_with_stats/data.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
filter_xy(df, ch_x_min, ch_y_min, ch_x_max, ch_y_max)
¶
Filter input data to be within range of X and Y coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
inout data. The code expects to find the following columns: "X", "Y". |
required |
ch_x_min |
float
|
minimum value of X |
required |
ch_y_min |
float
|
minimum value of Y |
required |
ch_x_max |
float
|
maximum value of X |
required |
ch_y_max |
float
|
maximum value of Y |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: input data with the restricted "X", "Y" values |
Source code in src/map_with_stats/data.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
hectare2xy(df, col_hectare='hectare_id')
¶
Convert hectare ID into (x,y) coorsinates in the LV03 coordinate system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
input table. |
required |
col_hectare |
str
|
name of the column with hectare IDs. The common convention is that coordinates x=ABCDEF, y=ZYXWVT are represented by a hectare ID ABCDZYXW. Defaults to "hectare_id". |
'hectare_id'
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: input table with "X", "Y" columns added (or overwritten, if they existed in the input) |
Source code in src/map_with_stats/utils.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|