ogd-at-lab/notebooks/webmapping.ipynb

131 wiersze
3.1 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Accessing Different Types of Webservices\n",
"\n",
"[![Binder](http://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/anitagraser/ogd-at-lab/main?urlpath=lab/tree/notebooks/webmapping.ipynb)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Basemap tiles (XYZ tiles)\n",
"\n",
"Documentation: http://geoviews.org/user_guide/Working_with_Bokeh.html\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import holoviews as hv\n",
"import geoviews as gv\n",
"gv.extension('bokeh')\n",
"\n",
"basemap = hv.element.tiles.OSM().opts(width=450, height=450)\n",
"basemap"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Web Map Services (WMS) \n",
"Source: https://github.com/holoviz/geoviews/issues/481"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def load_wms(server=\"http://data.wien.gv.at/daten/geo\", layer=\"ogdwien:DONAUINSPKTOGD\", extents=(1825290,6144246,1827693,6146435)):\n",
" url = f\"{server}?&service=WMS&request=GetMap&layers={layer}&styles=&format=image/png&transparent=true&version=1.3.0&width=256&height=256&crs=EPSG:3857\"\n",
" url = url + \"&bbox={XMIN},{YMIN},{XMAX},{YMAX}\"\n",
" return hv.Tiles(url, extents=extents)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"map_with_overlay = basemap * load_wms()\n",
"map_with_overlay"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"map_with_overlay * load_wms(layer=\"ogdwien:DONAUKILOMETEROGD\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3. Web Feature Services (WFS) \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import geopandas as gpd\n",
"from urllib.request import urlretrieve\n",
"import hvplot.pandas\n",
"\n",
"layer = 'RADGRAETZELOGD'\n",
"file = f'data/{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",
"urlretrieve(url, file)\n",
"gdf = gpd.read_file(file)\n",
"gdf"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gdf.hvplot(geo=True, tiles='OSM', hover_cols='all').opts(active_tools=['wheel_zoom'])"
]
}
],
"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.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}