{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" }, "colab": { "name": "04 - Geocoding #bigdive.ipynb", "provenance": [], "collapsed_sections": [] } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "p24fk3F7SGfJ", "colab_type": "text" }, "source": [ "# Geocoding with geopandas\n", "\n", "## goals of the tutorial\n", "- from string to lat/long\n", "- from lat/lon to string\n", "\n", "\n", "### requirements\n", "- python knowledge\n", "- geopandas\n", "\n", "### status \n", "*\"I'm a geo-soothsayer\"*\n", "\n", "---" ] }, { "cell_type": "code", "metadata": { "id": "YrJzTOLISGfN", "colab_type": "code", "colab": {} }, "source": [ "try:\n", " import geopandas as gpd\n", "except ModuleNotFoundError as e:\n", " !pip install geopandas\n", " import geopandas as gpd" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "xKBsyPdo5CUO", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 340 }, "outputId": "a259e259-e971-4fc4-8af2-65d57484b4d2" }, "source": [ "!pip install git+https://github.com/python-visualization/folium\n", "import folium" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "Collecting git+https://github.com/python-visualization/folium\n", " Cloning https://github.com/python-visualization/folium to /tmp/pip-req-build-jwagvgm7\n", " Running command git clone -q https://github.com/python-visualization/folium /tmp/pip-req-build-jwagvgm7\n", "Requirement already satisfied (use --upgrade to upgrade): folium==0.11.0+20.gb70efc6 from git+https://github.com/python-visualization/folium in /usr/local/lib/python3.6/dist-packages\n", "Requirement already satisfied: branca>=0.3.0 in /usr/local/lib/python3.6/dist-packages (from folium==0.11.0+20.gb70efc6) (0.4.1)\n", "Requirement already satisfied: jinja2>=2.9 in /usr/local/lib/python3.6/dist-packages (from folium==0.11.0+20.gb70efc6) (2.11.2)\n", "Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from folium==0.11.0+20.gb70efc6) (1.18.5)\n", "Requirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages (from folium==0.11.0+20.gb70efc6) (2.23.0)\n", "Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.6/dist-packages (from jinja2>=2.9->folium==0.11.0+20.gb70efc6) (1.1.1)\n", "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests->folium==0.11.0+20.gb70efc6) (3.0.4)\n", "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests->folium==0.11.0+20.gb70efc6) (2.10)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests->folium==0.11.0+20.gb70efc6) (2020.6.20)\n", "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests->folium==0.11.0+20.gb70efc6) (1.24.3)\n", "Building wheels for collected packages: folium\n", " Building wheel for folium (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Created wheel for folium: filename=folium-0.11.0+20.gb70efc6-py2.py3-none-any.whl size=97529 sha256=6f92b85f41620b5721db32cdcfcb8a59bfdbc4cf3fab6510ebc7e5a3f9020530\n", " Stored in directory: /tmp/pip-ephem-wheel-cache-vyhp9fqs/wheels/1e/e1/75/ecbc91fd5dd5d90befb0b533bf7492d38acffa033310731862\n", "Successfully built folium\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "V8HYNqzgSGfq", "colab_type": "text" }, "source": [ "\n", "
\n", "GEOCODING service\n", "\n", "the geopandas module is based on geopy\n", "" ] }, { "cell_type": "markdown", "metadata": { "id": "78FUcOZ6SGft", "colab_type": "text" }, "source": [ "## choose the right service\n", "![](https://raw.githubusercontent.com/napo/geospatial_bigdive/13bd7078c11c3102b44888efaf04471e80a03e14/img/getlonlat.png)" ] }, { "cell_type": "markdown", "metadata": { "id": "S7KI4pL4SGfw", "colab_type": "text" }, "source": [ "# geocoding" ] }, { "cell_type": "code", "metadata": { "id": "ptEXZ6feSGfz", "colab_type": "code", "colab": {} }, "source": [ "cols = ['city']\n", "names = [('Roma'),('Palermo'),('Trento'),('Genova'),('Bari'),('Trieste'),('Napoli'),('Cagliari'),('Messina'),('Lecce')]\n", "cities = gpd.GeoDataFrame(names,columns=cols)" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "RuqaVw9yhCmT", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 363 }, "outputId": "7ef11e60-9a48-4d84-a69c-7044120b56b7" }, "source": [ "cities" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
city
0Roma
1Palermo
2Trento
3Genova
4Bari
5Trieste
6Napoli
7Cagliari
8Messina
9Lecce
\n", "
" ], "text/plain": [ " city\n", "0 Roma\n", "1 Palermo\n", "2 Trento\n", "3 Genova\n", "4 Bari\n", "5 Trieste\n", "6 Napoli\n", "7 Cagliari\n", "8 Messina\n", "9 Lecce" ] }, "metadata": { "tags": [] }, "execution_count": 4 } ] }, { "cell_type": "code", "metadata": { "id": "sKQbMkTOSGf5", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 53 }, "outputId": "1f4d7cfc-2ad3-447a-cbd8-a07a4e6e78b1" }, "source": [ "%%time\n", "geo_cities = gpd.tools.geocode(cities.city, provider=\"arcgis\")" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "CPU times: user 64.2 ms, sys: 9.1 ms, total: 73.3 ms\n", "Wall time: 6.12 s\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "CShwLo-7SGgA", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 363 }, "outputId": "5759a6d0-d7ed-41a7-be57-770f2d33fd08" }, "source": [ "geo_cities" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
geometryaddress
0POINT (12.49565 41.90322)Roma
1POINT (13.36112 38.12207)Palermo
2POINT (11.11926 46.07005)Trento
3POINT (8.93898 44.41039)Genova
4POINT (16.86666 41.12587)Bari
5POINT (13.77269 45.65757)Trieste
6POINT (14.25226 40.84014)Napoli
7POINT (9.11049 39.21454)Cagliari
8POINT (15.55308 38.17837)Messina
9POINT (18.16802 40.35796)Lecce
\n", "
" ], "text/plain": [ " geometry address\n", "0 POINT (12.49565 41.90322) Roma\n", "1 POINT (13.36112 38.12207) Palermo\n", "2 POINT (11.11926 46.07005) Trento\n", "3 POINT (8.93898 44.41039) Genova\n", "4 POINT (16.86666 41.12587) Bari\n", "5 POINT (13.77269 45.65757) Trieste\n", "6 POINT (14.25226 40.84014) Napoli\n", "7 POINT (9.11049 39.21454) Cagliari\n", "8 POINT (15.55308 38.17837) Messina\n", "9 POINT (18.16802 40.35796) Lecce" ] }, "metadata": { "tags": [] }, "execution_count": 6 } ] }, { "cell_type": "code", "metadata": { "id": "rbyDNVsoSGgF", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 283 }, "outputId": "ae0f8b05-5650-47e5-b238-02824eabf696" }, "source": [ "geo_cities.plot()" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "" ] }, "metadata": { "tags": [] }, "execution_count": 7 }, { "output_type": "display_data", "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAN0AAAD4CAYAAABopeOfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAOLklEQVR4nO3df4wcd33G8feD4ySHWnMJvoT4HPcQBkcCk7gcVgSNaNwfTlOUWCkVVARBIbUaCWhDdaRuKyqQUICrlDZVS+SSgCW75UdwDoSK3BRK01Zg6xz/jBI7VmtDzkltVE5pxDV17E//mDn77N755nZnvzM7+7ykk3dnf3102SczOzv3jCICM0vnFVUPYNZrHDqzxBw6s8QcOrPEHDqzxC5J+WJLly6NoaGhlC9pVondu3f/OCIGZrstaeiGhoYYHx9P+ZJmlZB0bK7bvHlplphDZ5aYQ2eWmENnlphDZ5ZY0r2X3WxszwSjOw5xfHKKZf19jKxfxYY1g1WPZV3IoStgbM8Em7YfYOrUaQAmJqfYtP0AgINnC1Z481LSIkl7JH0rvy5Jn5Z0WNJTkj7auTGrNbrj0NnATZs6dZrRHYcqmsi62ULWdL8HPAUsya9/ALgWuC4izki6quTZauP45NSClptdTKE1naTlwK8DX5ix+G7gUxFxBiAiTpQ/Xj0s6+9b0HKziym6efnnwMeBMzOWvQ54t6RxSd+W9PrZHihpY36f8ZMnT7Y5bjVG1q+ib/Gi85b1LV7EyPpVFU1k3Wze0El6J3AiInZfcNNlwP9ExDDwN8DDsz0+IjZHxHBEDA8MzHr8Z+1tWDPIfXesZrC/DwGD/X3cd8dq70SxlhT5TPd24DZJtwKXA0skbQWeBbbn93kU+GJn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2UbLPd2a2AD4ixSyxBe29bPvFpJNkZ21NZSnw44SvV4RnKqbbZ/q5iJj13HBJQ5eapPG5dttWxTMV0+SZvHlplphDZ5ZY00O3ueoBZuGZimnsTI3+TGdWR01f05nVjkNnllhjQifpYUknJB2csexKSY9Jeib/94oazDQq6WlJ+yU9On1ca5UzzbjtDySFpKVVzyPpI/nv6UlJn0s1z1wzSbpB0g/ypoRxSWtbff7GhA74EnDLBcv+EPhORLwe+E5+veqZHgPeFBFvBg4Dm2owE5KuBX4V+GHV80i6Gbid7C9Z3gj8WdUzAZ8DPpk3JXwiv96SxoQuIh4H/uuCxbcDW/LLW4ANVc8UEf8QES/nV38ALK96ptz9wMfJGgGqnudu4DMR8VJ+nxM1mKm0poTGhG4OV0fEc/nl54GrqxxmFh8Evl31EJJuByYiYl/Vs+TeANwkaaekf5b01qoHAn4fGJX0I7I1b8tbKE0P3VmRfTdSm+9HJP0x8DKwreI5Xgn8EdkmU11cAlwJ3AiMAF+VpGpH4m7gnoi4FrgHeKjVJ2p66P5T0jUA+b9JN1PmIukDwDvJ2tSq/h/B64DXAvskHSXb3H1C0msqnOlZYHteirULOEN2sHGV3g9szy9/DfCOlDl8k+yXRf7vNyqcBQBJt5B9drotIn5a9TwRcSAiroqIoYgYInvD/3xEPF/hWGPAzQB5O8GlVP8XB8eBd+SX1wHPtPxMEdGIH+DvgOeAU2RvnA8Brybba/kM8I/AlTWY6QjwI2Bv/vNg1TNdcPtRYGnFv6NLga3AQeAJst7Vqv+7/QJZI94+YCfwllaf34eBmSXW9M1Ls9px6MwSc+jMEnPozBJz6MwSc+jMEnPozBL7P+pZz8XWpRkPAAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": { "tags": [], "needs_background": "light" } } ] }, { "cell_type": "markdown", "metadata": { "id": "EYtr52QoSGgM", "colab_type": "text" }, "source": [ "# reverse geocoding" ] }, { "cell_type": "code", "metadata": { "id": "vBhB_vR6SGgP", "colab_type": "code", "colab": {} }, "source": [ "from geopy.geocoders import Nominatim" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "0NsPRxTQh29_", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 363 }, "outputId": "f22d68e5-4066-462d-ddc9-7e8996be82d1" }, "source": [ "geo_cities" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
geometryaddress
0POINT (12.49565 41.90322)Roma
1POINT (13.36112 38.12207)Palermo
2POINT (11.11926 46.07005)Trento
3POINT (8.93898 44.41039)Genova
4POINT (16.86666 41.12587)Bari
5POINT (13.77269 45.65757)Trieste
6POINT (14.25226 40.84014)Napoli
7POINT (9.11049 39.21454)Cagliari
8POINT (15.55308 38.17837)Messina
9POINT (18.16802 40.35796)Lecce
\n", "
" ], "text/plain": [ " geometry address\n", "0 POINT (12.49565 41.90322) Roma\n", "1 POINT (13.36112 38.12207) Palermo\n", "2 POINT (11.11926 46.07005) Trento\n", "3 POINT (8.93898 44.41039) Genova\n", "4 POINT (16.86666 41.12587) Bari\n", "5 POINT (13.77269 45.65757) Trieste\n", "6 POINT (14.25226 40.84014) Napoli\n", "7 POINT (9.11049 39.21454) Cagliari\n", "8 POINT (15.55308 38.17837) Messina\n", "9 POINT (18.16802 40.35796) Lecce" ] }, "metadata": { "tags": [] }, "execution_count": 9 } ] }, { "cell_type": "code", "metadata": { "id": "2Vd5I5sNSGgU", "colab_type": "code", "colab": {} }, "source": [ "point = geo_cities.geometry[2]" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "ZnBmcJKRhxaP", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 36 }, "outputId": "f03dd128-a4af-4381-b237-8fdc07d32e94" }, "source": [ "point.wkt" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" }, "text/plain": [ "'POINT (11.11926000000005 46.07005000000004)'" ] }, "metadata": { "tags": [] }, "execution_count": 11 } ] }, { "cell_type": "code", "metadata": { "id": "BOw4or3xiBbK", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 36 }, "outputId": "eb271d16-028a-4b80-a42f-5e59e044974d" }, "source": [ "point.wkt" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" }, "text/plain": [ "'POINT (11.11926000000005 46.07005000000004)'" ] }, "metadata": { "tags": [] }, "execution_count": 12 } ] }, { "cell_type": "code", "metadata": { "id": "t4T0F7w0isOQ", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "b2bdddf8-a8a1-4edc-85c8-2bd16ce79ce4" }, "source": [ "type(point.x)" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "float" ] }, "metadata": { "tags": [] }, "execution_count": 13 } ] }, { "cell_type": "code", "metadata": { "id": "ozqlAKXnSGga", "colab_type": "code", "colab": {} }, "source": [ "latlon = str(point.y) + \",\" + str(point.x)" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "3VhAUuH6SGgh", "colab_type": "code", "colab": {} }, "source": [ "geolocator = Nominatim(user_agent=\"Mozilla Firefox\")" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "A1cqwIGRSGgm", "colab_type": "code", "colab": {} }, "source": [ "location = geolocator.reverse(latlon)" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "bly9G38kSGgs", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 357 }, "outputId": "d0bbef12-d77c-41fd-dfe9-4f18fcbcd47d" }, "source": [ "location.raw" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "{'address': {'city': 'Trento',\n", " 'country': 'Italia',\n", " 'country_code': 'it',\n", " 'county': 'Provincia di Trento',\n", " 'house_number': '15',\n", " 'municipality': \"Territorio Val d'Adige\",\n", " 'postcode': '38122',\n", " 'road': 'Via Torre Vanga',\n", " 'state': 'Trentino-Alto Adige/Südtirol',\n", " 'suburb': 'Centro storico Trento',\n", " 'tourism': 'Giovane Europa'},\n", " 'boundingbox': ['46.0700951', '46.0703188', '11.119026', '11.1194422'],\n", " 'display_name': \"Giovane Europa, 15, Via Torre Vanga, Centro storico Trento, Trento, Territorio Val d'Adige, Provincia di Trento, Trentino-Alto Adige/Südtirol, 38122, Italia\",\n", " 'lat': '46.070178',\n", " 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',\n", " 'lon': '11.119240793834841',\n", " 'osm_id': 73293763,\n", " 'osm_type': 'way',\n", " 'place_id': 104813655}" ] }, "metadata": { "tags": [] }, "execution_count": 17 } ] }, { "cell_type": "markdown", "metadata": { "id": "iBrpkQHDSGgy", "colab_type": "text" }, "source": [ "# suggestion for a good geocoding\n", "more details you add and more fortune you have to obtain a good result" ] }, { "cell_type": "code", "metadata": { "id": "z3oNqpdoSGgz", "colab_type": "code", "colab": {} }, "source": [ "q=\"Via Verdi, 26\"" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "ALQFl814SGg4", "colab_type": "code", "colab": {} }, "source": [ "point = gpd.tools.geocode(q, provider=\"arcgis\")" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "z0VcL2t1SGg8", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 81 }, "outputId": "735afbc4-482d-4e01-99fe-bb65b7b934cc" }, "source": [ "point" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
geometryaddress
0POINT (-80.18468 25.83911)Via Verdi
\n", "
" ], "text/plain": [ " geometry address\n", "0 POINT (-80.18468 25.83911) Via Verdi" ] }, "metadata": { "tags": [] }, "execution_count": 20 } ] }, { "cell_type": "code", "metadata": { "id": "5-idsvUGSGhF", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "outputId": "65af2ca4-dc20-498c-d6fc-5464383dcd5e" }, "source": [ "map_point = folium.Map([point.geometry.y,point.geometry.x], zoom_start=18)\n", "folium.GeoJson(point.to_json()).add_to(map_point)\n", "map_point" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "metadata": { "tags": [] }, "execution_count": 21 } ] }, { "cell_type": "markdown", "metadata": { "id": "54w8rP-6SGhJ", "colab_type": "text" }, "source": [ "add details like city and State" ] }, { "cell_type": "code", "metadata": { "id": "Whv7LCOzSGhL", "colab_type": "code", "colab": {} }, "source": [ "q=\"Via Verdi, 26, Trento, Italia\"" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "jcb3ZjTmSGhR", "colab_type": "code", "colab": {} }, "source": [ "point = gpd.tools.geocode(q, provider=\"arcgis\")" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "Pg435Zb_SGhY", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 81 }, "outputId": "deac022b-2db2-4fe4-d4ad-0957b1b81219" }, "source": [ "point" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
geometryaddress
0POINT (11.11966 46.06665)Via Giuseppe Verdi 26, 38122, Trento
\n", "
" ], "text/plain": [ " geometry address\n", "0 POINT (11.11966 46.06665) Via Giuseppe Verdi 26, 38122, Trento" ] }, "metadata": { "tags": [] }, "execution_count": 24 } ] }, { "cell_type": "code", "metadata": { "id": "Rug8CPjwSGhe", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "outputId": "314723dd-44c0-441e-e34f-153877b5861c" }, "source": [ "map_point = folium.Map([point.geometry.y,point.geometry.x], zoom_start=18)\n", "folium.GeoJson(point.to_json()).add_to(map_point)\n", "map_point" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "metadata": { "tags": [] }, "execution_count": 25 } ] }, { "cell_type": "markdown", "metadata": { "id": "v7VOMDVOSGhm", "colab_type": "text" }, "source": [ "Try a different geocoder" ] }, { "cell_type": "code", "metadata": { "id": "0yB68wm0SGho", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 73 }, "outputId": "ca205de6-e629-42b5-e440-29d8482c159d" }, "source": [ "point_nominatim = gpd.tools.geocode(q, provider=\"Nominatim\")" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "/usr/local/lib/python3.6/dist-packages/geopy/geocoders/osm.py:143: UserWarning: Using Nominatim with the default \"geopy/1.17.0\" `user_agent` is strongly discouraged, as it violates Nominatim's ToS https://operations.osmfoundation.org/policies/nominatim/ and may possibly cause 403 and 429 HTTP errors. Please specify a custom `user_agent` with `Nominatim(user_agent=\"my-application\")` or by overriding the default `user_agent`: `geopy.geocoders.options.default_user_agent = \"my-application\"`. In geopy 2.0 this will become an exception.\n", " UserWarning\n" ], "name": "stderr" } ] }, { "cell_type": "code", "metadata": { "id": "37g8nInySGhs", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 81 }, "outputId": "e4cbc78f-b2c5-4558-8ce4-70559dc6f67c" }, "source": [ "point_nominatim" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
geometryaddress
0POINT (10.76813 46.31650)Via Verdi, Ognano, Stavel, Pellizzano, Comunit...
\n", "
" ], "text/plain": [ " geometry address\n", "0 POINT (10.76813 46.31650) Via Verdi, Ognano, Stavel, Pellizzano, Comunit..." ] }, "metadata": { "tags": [] }, "execution_count": 27 } ] }, { "cell_type": "code", "metadata": { "id": "BBOh8TtDTXlv", "colab_type": "code", "colab": {} }, "source": [ "q=\"Via Giuseppe Verdi, 26, Trento, Italia\"" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "moSu98cwTaQM", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 73 }, "outputId": "db620c35-804b-4744-9c03-2c642c2c1926" }, "source": [ "point_nominatim = gpd.tools.geocode(q, provider=\"Nominatim\")" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "/usr/local/lib/python3.6/dist-packages/geopy/geocoders/osm.py:143: UserWarning: Using Nominatim with the default \"geopy/1.17.0\" `user_agent` is strongly discouraged, as it violates Nominatim's ToS https://operations.osmfoundation.org/policies/nominatim/ and may possibly cause 403 and 429 HTTP errors. Please specify a custom `user_agent` with `Nominatim(user_agent=\"my-application\")` or by overriding the default `user_agent`: `geopy.geocoders.options.default_user_agent = \"my-application\"`. In geopy 2.0 this will become an exception.\n", " UserWarning\n" ], "name": "stderr" } ] }, { "cell_type": "code", "metadata": { "id": "vHnzNSgHTb9D", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 81 }, "outputId": "5688d8bb-59ab-46d6-a359-eb6acd4edfdd" }, "source": [ "point_nominatim" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
geometryaddress
0POINT (11.11971 46.06641)Dipartimento di Sociologia e Ricerca Sociale, ...
\n", "
" ], "text/plain": [ " geometry address\n", "0 POINT (11.11971 46.06641) Dipartimento di Sociologia e Ricerca Sociale, ..." ] }, "metadata": { "tags": [] }, "execution_count": 30 } ] }, { "cell_type": "code", "metadata": { "id": "gv0HmvwLSGhw", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "outputId": "3dcf5838-88b7-40d1-b87c-1a3e0ec57265" }, "source": [ "map_point = folium.Map([point_nominatim.geometry.y,point.geometry.x], zoom_start=18)\n", "folium.GeoJson(point_nominatim.to_json()).add_to(map_point)\n", "map_point" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "metadata": { "tags": [] }, "execution_count": 31 } ] }, { "cell_type": "markdown", "metadata": { "id": "VdL8RQfHSGh2", "colab_type": "text" }, "source": [ "calculate the difference between the two points" ] }, { "cell_type": "code", "metadata": { "id": "avrum-VdSGh4", "colab_type": "code", "colab": {} }, "source": [ "distance = point.to_crs('epsg:32632').geometry.distance(point_nominatim.geometry.to_crs('epsg:32632')).values[0]" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "jFZA8JZ2AnaP", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "14a31c04-d5e3-483a-ae6f-3b98d4e5cc83" }, "source": [ "distance" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "26.522713658370346" ] }, "metadata": { "tags": [] }, "execution_count": 33 } ] } ] }