kopia lustrzana https://github.com/anitagraser/ogd-at-lab
156 wiersze
3.6 KiB
Plaintext
156 wiersze
3.6 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Geocoding addresses\n",
|
|
"\n",
|
|
"[![Binder](http://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/anitagraser/ogd-at-lab/main?urlpath=lab/tree/notebooks/geocoding.ipynb)\n",
|
|
"\n",
|
|
"Geocoding powered by [GeoPy](https://geopy.readthedocs.io/en/stable/) and [Nominatim](https://nominatim.org/release-docs/develop/api/Overview/)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import hvplot.pandas\n",
|
|
"from geopy.geocoders import Nominatim\n",
|
|
"from utils.dataaccess import get_gdf_from_wfs\n",
|
|
"from utils.plotting import hvplot_with_buffer\n",
|
|
"from utils.converting import location_to_gdf"
|
|
]
|
|
},
|
|
{
|
|
"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=\"OGD.AT-Lab\")\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 = location_to_gdf(location, address)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"map_plot = hvplot_with_buffer(geocoded_gdf, 1000, size=400, title='Geocoded address with buffer')\n",
|
|
"map_plot"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Interactive geocoding application with Panel "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import panel as pn"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def my_plot(user_input=\"Giefinggasse 2, 1210 Wien\", buffer_meters=1000):\n",
|
|
" location = locator.geocode(user_input)\n",
|
|
" geocoded_gdf = location_to_gdf(location, user_input)\n",
|
|
" map_plot = hvplot_with_buffer(geocoded_gdf, buffer_meters, title=f'Geocoded address with {buffer_meters}m buffer')\n",
|
|
" return map_plot.opts(active_tools=['wheel_zoom']) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"kw = dict(user_input=\"Giefinggasse 2, 1210 Wien\", buffer_meters=(1,10000))\n",
|
|
"pn.interact(my_plot, **kw)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"pn.template.FastListTemplate(\n",
|
|
" site=\"Panel\", title=\"Geocoding Demo\", \n",
|
|
" main=[pn.interact(my_plot, **kw)]\n",
|
|
").servable();"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"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.15"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|