{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Welcome to the OGD.AT Lab!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "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, "metadata": {}, "outputs": [], "source": [ "SIZE = 400" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def gdf_from_wfs(layer):\n", " file = f'{layer}.json'\n", " url = f\"https://data.wien.gv.at/daten/geo?service=WFS&request=GetFeature&version=1.1.0&typeName=ogdwien:{layer}&srsName=EPSG:4326&outputFormat=json\"\n", " if not exists(file):\n", " urlretrieve(url, file)\n", " return gpd.read_file(file)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gdf = gdf_from_wfs('ELADESTELLEOGD')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gdf.hvplot(geo=True, tiles='OSM', width=SIZE, height=SIZE, hover_cols=['DESIGNATION']).opts(active_tools=['wheel_zoom'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def hvplot_with_buffer(gdf, buffer_size, title=''):\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", " gdf.hvplot(geo=True, hover_cols=['DESIGNATION']) \n", " ).opts(active_tools=['wheel_zoom'])\n", " \n", " return plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hvplot_with_buffer(gdf, 100)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gdf2 = gdf_from_wfs('CITYBIKEOGD')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "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, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.8" } }, "nbformat": 4, "nbformat_minor": 4 }