kopia lustrzana https://github.com/anitagraser/ogd-at-lab
Restructuring
rodzic
15d8e654e3
commit
931a1f1e27
File diff suppressed because one or more lines are too long
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 13 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 5.0 KiB |
|
@ -7,185 +7,21 @@
|
|||
"# 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"
|
||||
"<a href=\"https://data.gv.at\"><img align=\"right\" src=\"./img/data-gv-at.png\"></a>\n",
|
||||
"\n",
|
||||
"This lab provides **Jupyter notebooks** for working with **Austrian open government data** and other auxilliary open data sources. \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Lab notebooks\n",
|
||||
"\n",
|
||||
"1. [Accessing geodata from data.wien.gv.at services](wien-ogd.ipynb)\n",
|
||||
"1. [Geocoding addresses](geocoding.ipynb)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"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,
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
from os.path import exists
|
||||
from urllib.request import urlretrieve
|
||||
import geopandas as gpd
|
||||
|
||||
def gdf_from_wfs(layer):
|
||||
"""
|
||||
Get GeoPandas GeoDataFrame from data.wien.gv.at WFS service based on layer name
|
||||
|
||||
Parameters
|
||||
----------
|
||||
layer : string
|
||||
WFS layer name
|
||||
"""
|
||||
file = f'{layer}.json'
|
||||
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"
|
||||
if not exists(file):
|
||||
urlretrieve(url, file)
|
||||
return gpd.read_file(file)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
def hvplot_with_buffer(gdf, buffer_size, *args, **kwargs):
|
||||
buffered = gdf.to_crs('epsg:31287').buffer(buffer_size)
|
||||
buffered = gdf.copy().set_geometry(buffered).to_crs('epsg:4326')
|
||||
|
||||
plot = ( buffered.hvplot(geo=True, tiles='OSM', alpha=0.5, line_width=0, *args, **kwargs) *
|
||||
gdf.hvplot(geo=True, hover_cols=['DESIGNATION'])
|
||||
).opts(active_tools=['wheel_zoom'])
|
||||
|
||||
return plot
|
File diff suppressed because one or more lines are too long
Ładowanie…
Reference in New Issue