From b94b37a777e9c7b74e046e97d3d77d9c3e14b466 Mon Sep 17 00:00:00 2001 From: anitagraser Date: Sun, 10 Jan 2021 16:38:34 +0100 Subject: [PATCH] Add geopy geocoding example --- .gitignore | 2 ++ notebooks/index.ipynb | 84 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b6e4761..5b42138 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,5 @@ dmypy.json # Pyre type checker .pyre/ +notebooks/CITYBIKEOGD.json +notebooks/ELADESTELLEOGD.json diff --git a/notebooks/index.ipynb b/notebooks/index.ipynb index 93864c6..0f9e121 100644 --- a/notebooks/index.ipynb +++ b/notebooks/index.ipynb @@ -1,5 +1,12 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Welcome to the OGD.AT Lab!" + ] + }, { "cell_type": "code", "execution_count": null, @@ -8,10 +15,19 @@ "source": [ "from os.path import exists\n", "from urllib.request import urlretrieve\n", + "import pandas as pd\n", "import geopandas as gpd\n", + "from shapely.geometry import Point\n", "import hvplot.pandas" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Fetching geodata from data.wien.gv.at WFS" + ] + }, { "cell_type": "code", "execution_count": null, @@ -60,7 +76,7 @@ "outputs": [], "source": [ "def hvplot_with_buffer(gdf, buffer_size, title=''):\n", - " buffered = gdf.to_crs('epsg:31287').buffer(100)\n", + " buffered = gdf.to_crs('epsg:31287').buffer(buffer_size)\n", " buffered = gdf.copy().set_geometry(buffered).to_crs('epsg:4326')\n", " \n", " plot = ( buffered.hvplot(geo=True, title=title, tiles='OSM', width=SIZE, height=SIZE, alpha=0.5, line_width=0) * \n", @@ -97,6 +113,72 @@ "hvplot_with_buffer(gdf, 100, title='EV Charging Stations') + hvplot_with_buffer(gdf2, 100, title='Citybike Stations')" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Visualize features around an address" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import geopy\n", + "from geopy.geocoders import Nominatim" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "address = \"Giefinggasse 2, 1210 Wien\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "locator = Nominatim(user_agent=\"myGeocoder\")\n", + "location = locator.geocode(address)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(location.address)\n", + "print(\"Latitude = {}, Longitude = {}\".format(location.latitude, location.longitude))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "geocoded_gdf = gpd.GeoDataFrame(pd.DataFrame([\n", + " {'geometry': Point(location.longitude, location.latitude), 'address': address}\n", + "])).set_crs('epsg:4326')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "hvplot_with_buffer(geocoded_gdf, 1000, title='EV Charging Stations') * gdf.hvplot(geo=True).opts(active_tools=['wheel_zoom']) " + ] + }, { "cell_type": "code", "execution_count": null,