|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "markdown",
|
5 |
| - "metadata": {}, |
| 5 | + "metadata": { |
| 6 | + "slideshow": { |
| 7 | + "slide_type": "-" |
| 8 | + } |
| 9 | + }, |
6 | 10 | "source": [
|
7 | 11 | "# Building a stand-alone off-Wiki layered map using Wikidata & SPARQL\n",
|
8 | 12 | "\n",
|
9 | 13 | "This Jupyter notebook shows you step by step **how to make a Wikidata-driven layered map that can be used off-Wiki**.\n",
|
10 | 14 | "\n",
|
11 | 15 | "It is part of Module 3 of the map making workshop [From Wikidata to interactive off-Wiki maps in three steps](https://github.com/ookgezellig/WikidataMapMakingWorkshop)\n",
|
12 | 16 | "\n",
|
13 |
| - "See https://github.com/ookgezellig/WikidataMapMakingWorkshop/blob/master/OutlineAndNotes.md for the full layout of this workshop\n", |
| 17 | + "<img src=\"https://raw.githubusercontent.com/ookgezellig/WikidataMapMakingWorkshop/master/images/generic-workshop-opening.jpg\" alt=\"Generic workshop opening slide\" width=\"400\" align=\"left\"/>\n", |
| 18 | + "<br clear=\"all\"/>\n", |
| 19 | + "\n", |
| 20 | + "For more context to this workshop you can check the\n", |
| 21 | + "* [full layout](https://github.com/ookgezellig/WikidataMapMakingWorkshop/blob/master/OutlineAndNotes.md), and\n", |
| 22 | + "* [full slides (pdf)](https://github.com/ookgezellig/WikidataMapMakingWorkshop/blob/master/slides/Generic/WikidataMapMakingWorkshop_Generic.pdf) \n", |
14 | 23 | "\n",
|
15 | 24 | "This notebook is publically available at\n",
|
16 | 25 | "* https://paws-public.wmflabs.org/paws-public/User:OlafJanssen/WikidataMapMakingWorkshop.ipynb (and in [raw format](https://paws-public.wmflabs.org/paws-public/User:OlafJanssen/WikidataMapMakingWorkshop.ipynb?format=raw))\n",
|
|
22 | 31 | "metadata": {},
|
23 | 32 | "source": [
|
24 | 33 | "For questions about this notebook, contact [Olaf Janssen](https://www.wikidata.org/wiki/User:OlafJanssen) on Wikidata // olaf.janssen@kb.nl // https://twitter.com/ookgezellig\n",
|
25 |
| - " \n", |
26 |
| - "************" |
| 34 | + "***********" |
27 | 35 | ]
|
28 | 36 | },
|
29 | 37 | {
|
30 | 38 | "cell_type": "markdown",
|
31 | 39 | "metadata": {},
|
32 | 40 | "source": [
|
33 |
| - "## Start of the workshop" |
| 41 | + "## Start of the notebook" |
34 | 42 | ]
|
35 | 43 | },
|
36 | 44 | {
|
|
64 | 72 | },
|
65 | 73 | {
|
66 | 74 | "cell_type": "code",
|
67 |
| - "execution_count": null, |
68 |
| - "metadata": {}, |
69 |
| - "outputs": [], |
| 75 | + "execution_count": 1, |
| 76 | + "metadata": {}, |
| 77 | + "outputs": [ |
| 78 | + { |
| 79 | + "name": "stdout", |
| 80 | + "output_type": "stream", |
| 81 | + "text": [ |
| 82 | + "Enabling notebook extension jupyter-leaflet/extension...\n", |
| 83 | + " - Validating: \u001b[32mOK\u001b[0m\n", |
| 84 | + "Enabling notebook extension jupyter-js-widgets/extension...\n", |
| 85 | + " - Validating: \u001b[32mOK\u001b[0m\n" |
| 86 | + ] |
| 87 | + } |
| 88 | + ], |
70 | 89 | "source": [
|
71 | 90 | "#Skip this step if you are running this notebook on a local Jupyter Notebooks installation, such as Anaconda. See the cell below for the alternative instructions.\n",
|
72 | 91 | "\n",
|
|
114 | 133 | },
|
115 | 134 | {
|
116 | 135 | "cell_type": "code",
|
117 |
| - "execution_count": null, |
| 136 | + "execution_count": 1, |
118 | 137 | "metadata": {},
|
119 | 138 | "outputs": [],
|
120 | 139 | "source": [
|
|
139 | 158 | "cell_type": "markdown",
|
140 | 159 | "metadata": {},
|
141 | 160 | "source": [
|
142 |
| - "Next we want to import data that is the result of a SPARQL query in Wikidata \n", |
| 161 | + "Next we want to import a dataset containing geo coordinates (P625) that is the result of a SPARQL query in Wikidata \n", |
143 | 162 | "\n",
|
144 | 163 | "For this, we are using the query https://w.wiki/6gJ (public libraries in the Netherlands, an (as per 9-8-2019) incomplete data set)\n",
|
145 | 164 | "<img src=\"https://raw.githubusercontent.com/ookgezellig/WikidataMapMakingWorkshop/master/images/3-3-layered-dutch-public-libraries-wikidata-query.png\" alt=\"Public libraries in the Netherlands, layered by province\" align=\"left\"/>\n"
|
|
175 | 194 | },
|
176 | 195 | {
|
177 | 196 | "cell_type": "code",
|
178 |
| - "execution_count": null, |
| 197 | + "execution_count": 2, |
179 | 198 | "metadata": {},
|
180 | 199 | "outputs": [],
|
181 | 200 | "source": [
|
|
235 | 254 | },
|
236 | 255 | {
|
237 | 256 | "cell_type": "code",
|
238 |
| - "execution_count": null, |
| 257 | + "execution_count": 3, |
239 | 258 | "metadata": {},
|
240 | 259 | "outputs": [],
|
241 | 260 | "source": [
|
|
260 | 279 | },
|
261 | 280 | {
|
262 | 281 | "cell_type": "code",
|
263 |
| - "execution_count": null, |
| 282 | + "execution_count": 16, |
264 | 283 | "metadata": {},
|
265 | 284 | "outputs": [],
|
266 | 285 | "source": [
|
|
269 | 288 | },
|
270 | 289 | {
|
271 | 290 | "cell_type": "code",
|
272 |
| - "execution_count": null, |
| 291 | + "execution_count": 17, |
273 | 292 | "metadata": {},
|
274 | 293 | "outputs": [],
|
275 | 294 | "source": [
|
|
298 | 317 | },
|
299 | 318 | {
|
300 | 319 | "cell_type": "code",
|
301 |
| - "execution_count": null, |
302 |
| - "metadata": {}, |
303 |
| - "outputs": [], |
| 320 | + "execution_count": 18, |
| 321 | + "metadata": {}, |
| 322 | + "outputs": [ |
| 323 | + { |
| 324 | + "data": { |
| 325 | + "application/vnd.jupyter.widget-view+json": { |
| 326 | + "model_id": "c50a357259484776b6e5e608accf55f2", |
| 327 | + "version_major": 2, |
| 328 | + "version_minor": 0 |
| 329 | + }, |
| 330 | + "text/plain": [ |
| 331 | + "Map(basemap={'url': 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', 'max_zoom': 19, 'attribution': 'Map …" |
| 332 | + ] |
| 333 | + }, |
| 334 | + "metadata": {}, |
| 335 | + "output_type": "display_data" |
| 336 | + } |
| 337 | + ], |
304 | 338 | "source": [
|
305 | 339 | "# Now that we have the data ready & loaded, we can start building a layered map step by step\n",
|
306 | 340 | "\n",
|
|
340 | 374 | },
|
341 | 375 | {
|
342 | 376 | "cell_type": "code",
|
343 |
| - "execution_count": null, |
| 377 | + "execution_count": 20, |
344 | 378 | "metadata": {},
|
345 | 379 | "outputs": [],
|
346 | 380 | "source": [
|
|
358 | 392 | },
|
359 | 393 | {
|
360 | 394 | "cell_type": "code",
|
361 |
| - "execution_count": null, |
| 395 | + "execution_count": 21, |
362 | 396 | "metadata": {},
|
363 | 397 | "outputs": [],
|
364 | 398 | "source": [
|
|
395 | 429 | },
|
396 | 430 | {
|
397 | 431 | "cell_type": "code",
|
398 |
| - "execution_count": null, |
| 432 | + "execution_count": 9, |
399 | 433 | "metadata": {},
|
400 | 434 | "outputs": [],
|
401 | 435 | "source": [
|
|
415 | 449 | " #===================POPUP TEMPLATE=======================================\n",
|
416 | 450 | " # This template determines the text layout in the popup. \n",
|
417 | 451 | " # With the external css you can tweak the styling of the text. You might need to create this css yourself, \n",
|
418 |
| - " # or download it from https://paws-public.wmflabs.org/paws-public/User:OlafJanssen/popupstyle.css\n", |
| 452 | + " # or download it from https://raw.githubusercontent.com/ookgezellig/WikidataMapMakingWorkshop/master/module3stuff/popupstyle.css\n", |
419 | 453 | " # and upload it to your own PAWS server\n",
|
420 | 454 | " \n",
|
421 | 455 | " # The approach with rendering the HTML template was found via \n",
|
|
441 | 475 | " #https://ipyleaflet.readthedocs.io/en/latest/api_reference/popup.html\n",
|
442 | 476 | " message = HTML()\n",
|
443 | 477 | " message.value = rendered_template\n",
|
444 |
| - " #message.description = popup_image\n", |
| 478 | + " #message.description = popup_image #you could add an image in the popup here\n", |
445 | 479 | " #============================================================\n",
|
446 | 480 | " \n",
|
447 |
| - " coor=result['dplLoc']['value'] #library coordinates, eg (53.0671982, 6.4616009)\n", |
| 481 | + " coor=result['dplLoc']['value'] #library lat,long coordinates, eg (53.0671982, 6.4616009)\n", |
448 | 482 | " \n",
|
449 | 483 | " #https://ipyleaflet.readthedocs.io/en/latest/api_reference/circle.html\n",
|
450 | 484 | " circle = Circle(location=coor, radius=12, color=\"red\", fill_color=\"red\", opacity=0.005) #0.005 = hardly visible\n",
|
|
461 | 495 | "cell_type": "markdown",
|
462 | 496 | "metadata": {},
|
463 | 497 | "source": [
|
464 |
| - "Now we want to combine the three layers above \n", |
| 498 | + "Now we want to combine the three layers we created in the above cells \n", |
465 | 499 | "1. simple_heatmap layer \n",
|
466 | 500 | "2. dark background layer \n",
|
467 | 501 | "3. circles popup layer\n",
|
|
471 | 505 | },
|
472 | 506 | {
|
473 | 507 | "cell_type": "code",
|
474 |
| - "execution_count": null, |
| 508 | + "execution_count": 22, |
475 | 509 | "metadata": {},
|
476 | 510 | "outputs": [],
|
477 | 511 | "source": [
|
|
486 | 520 | "cell_type": "markdown",
|
487 | 521 | "metadata": {},
|
488 | 522 | "source": [
|
489 |
| - "The resulting map should look like this\n", |
| 523 | + "Your resulting map should look something like this\n", |
490 | 524 | "\n",
|
491 | 525 | "<img src=\"https://raw.githubusercontent.com/ookgezellig/WikidataMapMakingWorkshop/master/images/3-3-heatmap-with-popup.png\" alt=\"Heatmap Dutch public libraries with popup\" width=\"400\" align=\"left\"/>\n",
|
492 | 526 | "<br clear=\"all\"/>\n",
|
|
500 | 534 | "As a next step we want to make a layer displaying the boundaries of all municipalities in The Netherlands that have \n",
|
501 | 535 | "one or more public libraries, using GeoShapes, as [explained in Module 2](https://github.com/ookgezellig/WikidataMapMakingWorkshop/blob/master/OutlineAndNotes.md#module-26-geoshapes-using-sparql-and-osm) of the workshop.\n",
|
502 | 536 | "\n",
|
503 |
| - "To make this layer, we first need to requets GeoJson geoshapes (boundaries) from Wikidata Q-values. See\n", |
| 537 | + "To make this layer, we first need to requets GeoJson geoshapes (municipal boundaries) from Wikidata Q-values. See\n", |
504 | 538 | "* https://phabricator.wikimedia.org/T138868\n",
|
505 | 539 | "* https://maps.wikimedia.org/geoshape?getgeojson=1&ids=Q701,Q694\n",
|
506 | 540 | "* https://maps.wikimedia.org/geoshape?getgeojson=1&query=SPARQLQuery \n",
|
|
522 | 556 | },
|
523 | 557 | {
|
524 | 558 | "cell_type": "code",
|
525 |
| - "execution_count": null, |
| 559 | + "execution_count": 23, |
526 | 560 | "metadata": {},
|
527 | 561 | "outputs": [],
|
528 | 562 | "source": [
|
|
561 | 595 | },
|
562 | 596 | {
|
563 | 597 | "cell_type": "code",
|
564 |
| - "execution_count": null, |
| 598 | + "execution_count": 24, |
565 | 599 | "metadata": {},
|
566 | 600 | "outputs": [],
|
567 | 601 | "source": [
|
|
591 | 625 | "cell_type": "markdown",
|
592 | 626 | "metadata": {},
|
593 | 627 | "source": [
|
594 |
| - "We have added a number of layers to the map. We can add a control in the top right corner of the map to switch layers on and off.\n", |
| 628 | + "in the previous steps we have added a number of layers to the map. Next we can add a control in the top right corner of the map to switch layers on and off.\n", |
595 | 629 | "\n",
|
596 | 630 | "We also add a Fullscreen control\n",
|
597 | 631 | "\n",
|
|
601 | 635 | },
|
602 | 636 | {
|
603 | 637 | "cell_type": "code",
|
604 |
| - "execution_count": null, |
| 638 | + "execution_count": 14, |
605 | 639 | "metadata": {
|
606 | 640 | "scrolled": false
|
607 | 641 | },
|
|
619 | 653 | "cell_type": "markdown",
|
620 | 654 | "metadata": {},
|
621 | 655 | "source": [
|
622 |
| - "The resulting heatmap looks like this, with the red municipal geoshapes, a popup, a layers control and a fullscreen control\n", |
| 656 | + "Your resulting heatmap should look something like this, with the red municipal geoshapes, a popup, a layers control and a fullscreen control\n", |
623 | 657 | "\n",
|
624 | 658 | "<img src=\"https://raw.githubusercontent.com/ookgezellig/WikidataMapMakingWorkshop/master/images/3-3-netherlands-public-libraries-heatmap.jpg\" alt=\"Dutch public library heatmap with the red municipal geoshapes, popup, layers control and fullscreen control\" width=\"800\" align=\"left\"/>\n",
|
625 | 659 | "<br clear=\"all\"/>"
|
|
629 | 663 | "cell_type": "markdown",
|
630 | 664 | "metadata": {},
|
631 | 665 | "source": [
|
632 |
| - "As a final step for this workshop, we want to export the map to a (stand-alone, off-Wiki) HTML page that can be viewed in a browser.\n", |
| 666 | + "As the final step we want to export the map to a (stand-alone, off-Wiki) HTML page that can be viewed in a browser.\n", |
633 | 667 | "\n",
|
634 | 668 | "https://ipywidgets.readthedocs.io/en/latest/embedding.html#python-interface\n",
|
635 | 669 | "\n",
|
|
638 | 672 | },
|
639 | 673 | {
|
640 | 674 | "cell_type": "code",
|
641 |
| - "execution_count": null, |
| 675 | + "execution_count": 15, |
642 | 676 | "metadata": {},
|
643 | 677 | "outputs": [],
|
644 | 678 | "source": [
|
|
663 | 697 | "metadata": {},
|
664 | 698 | "source": [
|
665 | 699 | "## Reusing this notebook\n",
|
666 |
| - "You are free to reuse this notebook, it is available under the license [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/)\n", |
| 700 | + "You are free to reuse this notebook (and all the other [workshop materials](https://github.com/ookgezellig/WikidataMapMakingWorkshop)), as it is available under the license [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/)\n", |
667 | 701 | "\n",
|
668 | 702 | ""
|
669 | 703 | ]
|
|
845 | 879 | }
|
846 | 880 | ],
|
847 | 881 | "metadata": {
|
848 |
| - "celltoolbar": "Tags", |
849 | 882 | "kernelspec": {
|
850 | 883 | "display_name": "Python 3",
|
851 | 884 | "language": "python",
|
|
861 | 894 | "name": "python",
|
862 | 895 | "nbconvert_exporter": "python",
|
863 | 896 | "pygments_lexer": "ipython3",
|
864 |
| - "version": "3.6.7" |
| 897 | + "version": "3.7.1" |
865 | 898 | }
|
866 | 899 | },
|
867 | 900 | "nbformat": 4,
|
|
0 commit comments