kopia lustrzana https://github.com/anitagraser/ogd-at-lab
Add geopy geocoding example
rodzic
eabfe9608b
commit
b94b37a777
|
@ -127,3 +127,5 @@ dmypy.json
|
|||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
notebooks/CITYBIKEOGD.json
|
||||
notebooks/ELADESTELLEOGD.json
|
||||
|
|
|
@ -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,
|
||||
|
|
Ładowanie…
Reference in New Issue