diff --git a/logo/ogdatlab.svg b/logo/ogdatlab.svg new file mode 100644 index 0000000..9ea7e23 --- /dev/null +++ b/logo/ogdatlab.svg @@ -0,0 +1,85 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + OGD.AT Lab + + diff --git a/notebooks/elevation.ipynb b/notebooks/elevation.ipynb index 584b1f1..6fa7e41 100644 --- a/notebooks/elevation.ipynb +++ b/notebooks/elevation.ipynb @@ -23,8 +23,7 @@ "source": [ "import hvplot.pandas\n", "from geopy.geocoders import Nominatim\n", - "from utils.ogc_io import gdf_from_wfs\n", - "from utils.plotting import hvplot_with_buffer\n", + "from utils.dataaccess import get_elevation\n", "from utils.converting import location_to_gdf" ] }, @@ -35,7 +34,7 @@ "outputs": [], "source": [ "address = \"Stephansdom, Wien\"\n", - "locator = Nominatim(user_agent=\"myGeocoder\")\n", + "locator = Nominatim(user_agent=\"OGD.AT-Lab\")\n", "location = locator.geocode(address)\n", "print(location.address)\n", "print(\"Latitude = {}, Longitude = {}\".format(location.latitude, location.longitude))\n", @@ -59,51 +58,6 @@ "gdf" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "jupyter": { - "source_hidden": true - } - }, - "outputs": [], - "source": [ - "from os.path import exists\n", - "from urllib.request import urlretrieve\n", - "\n", - "def get_elevation(point):\n", - " \"\"\"\n", - " Retrieve elevation info from the Austrian Elevation Service\n", - " \n", - " Implementation based on https://github.com/maegger/AustrianElevation/blob/6e0f468b6094caace6cd35f00704e4087e851cec/tree/AustrianElevation/AustrianElevation.py#L97\n", - " \n", - " Parameters\n", - " ----------\n", - " point : Shapely Point\n", - " Point in EPSG:3857 \n", - " \"\"\"\n", - " x = point.x\n", - " y = point.y\n", - " mod_x_path = x % 20000;\n", - " path_x = x - mod_x_path;\n", - " database = int(path_x );\n", - " mod_y = y % 10;\n", - " raster_y = y - mod_y;\n", - " mod_x = x % 10;\n", - " raster_x = int(x - mod_x);\n", - " file = f'{int(raster_y)}.txt'\n", - " url = f\"https://raw.githubusercontent.com/maegger/{database}/master/{int(raster_y)}.txt\"\n", - " if not exists(file):\n", - " urlretrieve(url, file)\n", - " data = open(file, 'r')\n", - " for line in data:\n", - " x_wert = int(line.split(' ', 1 )[0])\n", - " if x_wert == raster_x:\n", - " elevationall = line.split(' ', 1 )[1]\n", - " return int(elevationall)" - ] - }, { "cell_type": "code", "execution_count": null, @@ -111,7 +65,7 @@ "outputs": [], "source": [ "gdf.loc[0, 'elevation'] = get_elevation(gdf.iloc[0].geometry)\n", - "gdf" + "gdf.to_crs('epsg:4326')" ] }, { diff --git a/notebooks/geocoding.ipynb b/notebooks/geocoding.ipynb index 607df65..0811f4d 100644 --- a/notebooks/geocoding.ipynb +++ b/notebooks/geocoding.ipynb @@ -19,7 +19,7 @@ "source": [ "import hvplot.pandas\n", "from geopy.geocoders import Nominatim\n", - "from utils.ogc_io import gdf_from_wfs\n", + "from utils.dataaccess import gdf_from_wfs\n", "from utils.plotting import hvplot_with_buffer\n", "from utils.converting import location_to_gdf" ] @@ -39,7 +39,7 @@ "metadata": {}, "outputs": [], "source": [ - "locator = Nominatim(user_agent=\"myGeocoder\")\n", + "locator = Nominatim(user_agent=\"OGD.AT-Lab\")\n", "location = locator.geocode(address)" ] }, diff --git a/notebooks/utils/dataaccess.py b/notebooks/utils/dataaccess.py new file mode 100644 index 0000000..1962d11 --- /dev/null +++ b/notebooks/utils/dataaccess.py @@ -0,0 +1,50 @@ +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) + +def get_elevation(point): + """ + Retrieve elevation info from the Austrian Elevation Service + + Implementation based on https://github.com/maegger/AustrianElevation/blob/6e0f468b6094caace6cd35f00704e4087e851cec/tree/AustrianElevation/AustrianElevation.py#L97 + + Parameters + ---------- + point : Shapely Point + Point in EPSG:3857 + """ + x = point.x + y = point.y + mod_x_path = x % 20000; + path_x = x - mod_x_path; + database = int(path_x ); + mod_y = y % 10; + raster_y = y - mod_y; + mod_x = x % 10; + raster_x = int(x - mod_x); + file = f'{int(raster_y)}.txt' + url = f"https://raw.githubusercontent.com/maegger/{database}/master/{int(raster_y)}.txt" + if not exists(file): + urlretrieve(url, file) + data = open(file, 'r') + for line in data: + x_wert = int(line.split(' ', 1 )[0]) + if x_wert == raster_x: + elevationall = line.split(' ', 1 )[1] + return int(elevationall) + \ No newline at end of file diff --git a/notebooks/utils/ogc_io.py b/notebooks/utils/ogc_io.py deleted file mode 100644 index cd809d3..0000000 --- a/notebooks/utils/ogc_io.py +++ /dev/null @@ -1,19 +0,0 @@ -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) - diff --git a/notebooks/wien-ogd.ipynb b/notebooks/wien-ogd.ipynb index 85059a1..3606b64 100644 --- a/notebooks/wien-ogd.ipynb +++ b/notebooks/wien-ogd.ipynb @@ -25,7 +25,7 @@ "outputs": [], "source": [ "import hvplot.pandas\n", - "from utils.ogc_io import gdf_from_wfs\n", + "from utils.dataaccess import gdf_from_wfs\n", "from utils.plotting import hvplot_with_buffer" ] },