ogd-at-lab/notebooks/index.ipynb

219 wiersze
4.8 KiB
Plaintext
Czysty Zwykły widok Historia

2021-01-09 08:42:03 +00:00
{
"cells": [
2021-01-10 15:38:34 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Welcome to the OGD.AT Lab!"
]
},
2021-01-09 08:42:03 +00:00
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from os.path import exists\n",
"from urllib.request import urlretrieve\n",
2021-01-10 15:38:34 +00:00
"import pandas as pd\n",
2021-01-09 08:42:03 +00:00
"import geopandas as gpd\n",
2021-01-10 15:38:34 +00:00
"from shapely.geometry import Point\n",
2021-01-09 08:42:03 +00:00
"import hvplot.pandas"
]
},
2021-01-10 15:38:34 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Fetching geodata from data.wien.gv.at WFS"
]
},
2021-01-09 08:42:03 +00:00
{
"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",
2021-01-10 15:38:34 +00:00
" buffered = gdf.to_crs('epsg:31287').buffer(buffer_size)\n",
2021-01-09 08:42:03 +00:00
" 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')"
]
},
2021-01-10 15:38:34 +00:00
{
"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']) "
]
},
2021-01-09 08:42:03 +00:00
{
"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
}