API reference
map_nl.MapNL
¶
Bases: BaseMapNL
A class for creating custom PC4 maps of the Netherlands using folium.GeoJson
.
Source code in map_nl/map/map.py
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 |
|
__init__(url='https://public.opendatasoft.com/api/explore/v2.1/catalog/datasets/georef-netherlands-postcode-pc4/exports/geojson?lang=en&timezone=Europe%2FBerlin', data_dir='.map_nl', geojson_simplify_tolerance=None, **kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
URL to download the GeoJSON file. Defaults to a file from https://public.opendatasoft.com. |
'https://public.opendatasoft.com/api/explore/v2.1/catalog/datasets/georef-netherlands-postcode-pc4/exports/geojson?lang=en&timezone=Europe%2FBerlin'
|
data_dir |
str
|
Directory to save the downloaded GeoJSON file. Defaults to |
'.map_nl'
|
geojson_simplify_tolerance |
float | None
|
Tolerance level for GeoJSON simplification. If None, no simplification is performed. Lower values lead to simpler maps. Sensible values for coordinates stored in degrees are in the range of 0.0001 to 10. Defaults to None. |
None
|
**kwargs |
Additional keyword arguments to be passed to the folium.Map() function. By default, only |
{}
|
Source code in map_nl/map/base.py
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 |
|
plot(df, value_column_name, pc4_column_name, **kwargs)
¶
Creates and adds a custom map layer to the Folium map instance.
This method processes the input DataFrame and GeoJSON data to create a Folium GeoJson layer, which is then added to the map.
You can also pass any arguments to this function that are accepted by folium.GeoJson
. For example,
to add custom fill colors to the plot based on the column 'my_feature' in the DataFrame df
, do the following:
def get_color(value):
if not value:
return "grey"
if value > 500:
return "green"
else:
return "blue"
def style(feature):
return {"fillColor": get_color(feature.get("properties").get("my_feature"))}
m = MapNL(geojson_simplify_tolerance=0.0001).plot(
df, pc4_column_name="pc4", value_column_name="my_feature", style_function=style
)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
DataFrame containing the data for the map. |
required |
value_column_name |
str
|
Name of the column in df that contains the values to be visualized. |
required |
pc4_column_name |
str
|
Name of the column in df that contains the PC4 area codes. |
required |
**kwargs |
Additional keyword arguments to customize the GeoJson layer. |
{}
|
Returns:
Type | Description |
---|---|
Map
|
folium.Map: The Folium Map object with the custom layer added. |
Source code in map_nl/map/map.py
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 |
|
map_nl.map.choropleth.ChoroplethMapNL
¶
Bases: BaseMapNL
A class for creating Choropleth maps of the Netherlands using folium.Choropleth
.
Source code in map_nl/map/choropleth.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 |
|
__init__(url='https://public.opendatasoft.com/api/explore/v2.1/catalog/datasets/georef-netherlands-postcode-pc4/exports/geojson?lang=en&timezone=Europe%2FBerlin', data_dir='.map_nl', geojson_simplify_tolerance=None, **kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
URL to download the GeoJSON file. Defaults to a file from https://public.opendatasoft.com. |
'https://public.opendatasoft.com/api/explore/v2.1/catalog/datasets/georef-netherlands-postcode-pc4/exports/geojson?lang=en&timezone=Europe%2FBerlin'
|
data_dir |
str
|
Directory to save the downloaded GeoJSON file. Defaults to |
'.map_nl'
|
geojson_simplify_tolerance |
float | None
|
Tolerance level for GeoJSON simplification. If None, no simplification is performed. Lower values lead to simpler maps. Sensible values for coordinates stored in degrees are in the range of 0.0001 to 10. Defaults to None. |
None
|
**kwargs |
Additional keyword arguments to be passed to the folium.Map() function. By default, only |
{}
|
Source code in map_nl/map/base.py
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 |
|
plot(df, value_column_name, pc4_column_name, tooltip=True, **kwargs)
¶
This method takes a pandas DataFrame with PC4-data and plots a Choropleth map based on these data.
Any **kwargs are passed on to folium.Choropleth
. For example, to change the fill color, run
m = ChoroplethMapNL(...).plot(..., fill_opacity=1)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
DataFrame containing the data for the Choropleth map. |
required |
value_column_name |
str
|
Name of the column in df that contains the values to be visualized. |
required |
pc4_column_name |
str
|
Name of the column in df that contains the postal code (PC4) information. |
required |
tooltip |
bool
|
Add a simple tooltip. |
True
|
**kwargs |
Additional arguments that are passed to |
{}
|
Returns:
Type | Description |
---|---|
Map
|
folium.Map: The Folium Map object with the Choropleth layer added. |
Source code in map_nl/map/choropleth.py
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 |
|