From 83ccdf18cb8e5a788481f91718a9900407599a52 Mon Sep 17 00:00:00 2001 From: Jakub Nowosad <tupiszakaczki@gmail.com> Date: Fri, 20 Oct 2023 10:35:23 +0200 Subject: [PATCH] completes rev ch8 jn --- 08-mapping.qmd | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/08-mapping.qmd b/08-mapping.qmd index cf930f39..57a14b39 100644 --- a/08-mapping.qmd +++ b/08-mapping.qmd @@ -526,15 +526,15 @@ plt.savefig('output/plot_rasterio2.svg', dpi=300) ## Interactive maps {#sec-interactive-maps} -### Minimal example +<!-- jn: an intro paragraph is missing --> + +### Minimal example of interactive map An interactive map of a `GeoSeries` or `GeoDataFrame` can be created with `.explore` (@sec-vector-layers). -Here is a minimal example: ```{python} #| label: fig-explore #| fig-cap: Minimal example of an interactive vector layer plot with `.explore` - nz.explore() ``` @@ -558,7 +558,6 @@ For example, here is how we can set green fill color and 30% opaque black outlin ```{python} #| label: fig-explore-styling-polygons #| fig-cap: Styling of polygons in `.explore` - nz.explore(color='green', style_kwds={'color':'black', 'opacity':0.3}) ``` @@ -573,12 +572,11 @@ Additionally, for points, we can set the `marker_type`, to one of: - `'circle'`---A vector circle with radius specified in $m$ - `'circle_marker'`---A vector circle with radius specified in pixels (the default) -For example, the following expression draws `'circe_marker`' points with 20 pixel radius, green fill, and black outline (@fig-explore-styling-points): +For example, the following expression draws `'circe_marker`' points with 20 pixel radius, green fill, and black outline (@fig-explore-styling-points). ```{python} #| label: fig-explore-styling-points #| fig-cap: Styling of points in `.explore` (using `circle_marker`) - nz_height.explore( color='green', style_kwds={'color':'black', 'opacity':0.5, 'fillOpacity':0.1}, @@ -586,37 +584,36 @@ nz_height.explore( ) ``` -The following expression demonstrates the `'marker'` option (@fig-explore-styling-points2). -Note that the above-mentioned styling properties (other then `opacity`) are not applicable when using `marker_type='marker'`, because the markers are fixed PNG images: +@fig-explore-styling-points2 demonstrates the `'marker_type'` option. +Note that the above-mentioned styling properties (other then `opacity`) are not applicable when using `marker_type='marker'`, because the markers are fixed PNG images. ```{python} #| label: fig-explore-styling-points2 #| fig-cap: Styling of points in `.explore` (using `marker`) - nz_height.explore(marker_type='marker') ``` +<!-- jn: can we use our own png images as well? --> + ### Layers -To display multiple layers, one on top of another, with `.explore`, we use the `m` argument, which stands for the previous map (@fig-explore-layers): +To display multiple layers, one on top of another, with `.explore`, we use the `m` argument, which stands for the previous map (@fig-explore-layers). ```{python} #| label: fig-explore-layers #| fig-cap: Displaying multiple layers in an interactive map with `.explore` - -m = nz.explore() -nz_height.explore(m=m, color='red') +map1 = nz.explore() +nz_height.explore(m=map1, color='red') ``` One of the advantages of interactive maps is the ability to turn layers "on" and "off". This capability is implemented in [`folium.LayerControl`](https://python-visualization.github.io/folium/latest/user_guide/ui_elements/layer_control.html#LayerControl) from package **folium**, which the **geopandas** `.explore` method is a wrapper of. For example, this is how we can add a layer control for the `nz` and `nz_height` layers (@fig-explore-layers-controls). -Note the `name` properties, used to specify layer names in the control, and the `collapsed` property, used to specify whether the control is fully visible at all times (`False`), or on mouse hover (`True`, the default): +Note the `name` properties, used to specify layer names in the control, and the `collapsed` property, used to specify whether the control is fully visible at all times (`False`), or on mouse hover (`True`, the default). ```{python} #| label: fig-explore-layers-controls #| fig-cap: Displaying multiple layers in an interactive map with `.explore` - m = nz.explore(name='Polygons (adm. areas)') nz_height.explore(m=m, color='red', name='Points (elevation)') folium.LayerControl(collapsed=False).add_to(m) @@ -626,23 +623,21 @@ m ### Symbology {#sec-explore-symbology} Symbology can be specified in `.explore` using similar arguments as in `.plot` (@sec-plot-symbology). -For example, here is an interactive version of @fig-plot-symbology-colors (a). +For example, @fig-explore-symbology is an interactive version of @fig-plot-symbology-colors (a). ```{python} #| label: fig-explore-symbology #| fig-cap: 'Symbology in an interactive map of a vector layer, created with `.explore`' - nz.explore(column='Median_income', legend=True, cmap='Reds') ``` Fixed styling (@sec-explore-symbology) can be combined with symbology settings. -For example, polygon outline colors in @fig-explore-symbology are styled according to `'Median_income'`, however, this layer has overlapping outlines and the color is arbitrarily set according to the order of features (top-most features), which may be misleading and confusing. +For example, polygon outline colors in @fig-explore-symbology are styled according to `'Median_income'`, however, this layer has overlapping outlines and their color is arbitrarily set according to the order of features (top-most features), which may be misleading and confusing. To specify fixed outline colors (e.g., black), we can use the `color` and `weight` properties of `style_kwds` (@fig-explore-symbology2): ```{python} #| label: fig-explore-symbology2 #| fig-cap: 'Symbology combined with fixed styling in `.explore`' - nz.explore(column='Median_income', legend=True, cmap='Reds', style_kwds={'color':'black', 'weight': 0.5}) ``` @@ -658,14 +653,14 @@ Several popular built-in basemaps can be specified using a string: - `'CartoDB positron'` - `'CartoDB dark_matter'` -Other basemaps are available through the **xyzservices** package, which needs to be installed (see `xyzservices.providers` for a list), or using a custom tile server URL. +<!-- jn: please recheck the above list... there was some changes with Stamen maps recently, and I am not sure if the list is still correct... --> -For example, the following expression displays the `'CartoDB positron'` tiles in an `.explore` map (@fig-explore-basemaps): +Other basemaps are available through the **xyzservices** package, which needs to be installed (see `xyzservices.providers` for a list), or using a custom tile server URL. +For example, the following expression displays the `'CartoDB positron'` tiles in an `.explore` map (@fig-explore-basemaps). ```{python} #| label: fig-explore-basemaps #| fig-cap: Specifying the basemap in `.explore` - nz.explore(tiles='CartoDB positron') ``` @@ -673,9 +668,9 @@ nz.explore(tiles='CartoDB positron') An interactive map can be exported to an HTML file using the `.save` method of the `map` object. The HTML file can then be shared with other people, or published on a server and shared through a URL. -A good free option for publishing a web map is [GitHub Pages](https://pages.github.com/). +A good free option for publishing a web map is through [GitHub Pages](https://pages.github.com/). -For example, here is how we can export the map shown in @fig-explore-layers-controls, to a file named `map.html`: +For example, here is how we can export the map shown in @fig-explore-layers-controls, to a file named `map.html`. ```{python} #| output: false