Add geopy geocoding example

course
anitagraser 2021-01-10 16:38:34 +01:00
rodzic eabfe9608b
commit b94b37a777
2 zmienionych plików z 85 dodań i 1 usunięć

2
.gitignore vendored
Wyświetl plik

@ -127,3 +127,5 @@ dmypy.json
# Pyre type checker
.pyre/
notebooks/CITYBIKEOGD.json
notebooks/ELADESTELLEOGD.json

Wyświetl plik

@ -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,