{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example of DOV search methods for interpretations (gecodeerde lithologie)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/DOV-Vlaanderen/pydov/master?filepath=docs%2Fnotebooks%2Fsearch_gecodeerde_lithologie.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Use cases explained below\n", "* Get 'gecodeerde lithologie' in a bounding box\n", "* Get 'gecodeerde lithologie' with specific properties within a distance from a point\n", "* Get 'gecodeerde lithologie' in a bounding box with specific properties\n", "* Get 'gecodeerde lithologie' based on fields not available in the standard output dataframe\n", "* Get 'gecodeerde lithologie' data, returning fields not available in the standard output dataframe" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import inspect, sys" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# check pydov path\n", "import pydov" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get information about the datatype 'Gecodeerde lithologie'" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from pydov.search.interpretaties import GecodeerdeLithologieSearch\n", "itp = GecodeerdeLithologieSearch()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A description is provided for the 'Gecodeerde lithologie' datatype:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "'Een gecodeerde lithologie van een boring is een geologische codering van een lithologische beschrijving op basis van een vaste DOV-standaard per diepte-interval. U vindt een overzicht van de gebruikte standaarden op onze website.'" ] }, "metadata": {}, "execution_count": 4 } ], "source": [ "itp.get_description()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The different fields that are available for objects of the 'Gecodeerde lithologie' datatype can be requested with the get_fields() method:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "pkey_interpretatie\nType_proef\nProefnummer\npkey_boring\nx\ny\nstart_interpretatie_mtaw\ndiepte_tot_m\ngemeente\nAuteurs\nDatum\nOpdrachten\nbetrouwbaarheid_interpretatie\nGeldig_van\nGeldig_tot\ndiepte_laag_van\ndiepte_laag_tot\nhoofdnaam1_grondsoort\nhoofdnaam2_grondsoort\nbijmenging1_plaatselijk\nbijmenging1_hoeveelheid\nbijmenging1_grondsoort\nbijmenging2_plaatselijk\nbijmenging2_hoeveelheid\nbijmenging2_grondsoort\nbijmenging3_plaatselijk\nbijmenging3_hoeveelheid\nbijmenging3_grondsoort\n" ] } ], "source": [ "fields = itp.get_fields()\n", "\n", "# print available fields\n", "for f in fields.values():\n", " print(f['name'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can get more information of a field by requesting it from the fields dictionary:\n", "* *name*: name of the field\n", "* *definition*: definition of this field\n", "* *cost*: currently this is either 1 or 10, depending on the datasource of the field. It is an indication of the expected time it will take to retrieve this field in the output dataframe.\n", "* *notnull*: whether the field is mandatory or not\n", "* *type*: datatype of the values of this field" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "{'name': 'Datum',\n", " 'definition': 'De datum waarop de gecodeerde lithologie werd beschreven.',\n", " 'type': 'date',\n", " 'notnull': False,\n", " 'query': True,\n", " 'cost': 1}" ] }, "metadata": {}, "execution_count": 6 } ], "source": [ "fields['Datum']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example use cases" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get 'Gecodeerde lithologie' in a bounding box" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get data for all the 'Gecodeerde lithologie' interpretations that are geographically located within the bounds of the specified box.\n", "\n", "The coordinates are in the Belgian Lambert72 (EPSG:31370) coordinate system and are given in the order of lower left x, lower left y, upper right x, upper right y." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "[000/001] .\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ " pkey_interpretatie \\\n", "0 https://www.dov.vlaanderen.be/data/interpretat... \n", "1 https://www.dov.vlaanderen.be/data/interpretat... \n", "2 https://www.dov.vlaanderen.be/data/interpretat... \n", "3 https://www.dov.vlaanderen.be/data/interpretat... \n", "4 https://www.dov.vlaanderen.be/data/interpretat... \n", "\n", " pkey_boring \\\n", "0 https://www.dov.vlaanderen.be/data/boring/1974... \n", "1 https://www.dov.vlaanderen.be/data/boring/1974... \n", "2 https://www.dov.vlaanderen.be/data/boring/1974... \n", "3 https://www.dov.vlaanderen.be/data/boring/1974... \n", "4 https://www.dov.vlaanderen.be/data/boring/1974... \n", "\n", " betrouwbaarheid_interpretatie x y start_interpretatie_mtaw \\\n", "0 goed 153147.0 206931.0 14.12 \n", "1 goed 153147.0 206931.0 14.12 \n", "2 goed 153147.0 206931.0 14.12 \n", "3 goed 153147.0 206931.0 14.12 \n", "4 goed 153147.0 206931.0 14.12 \n", "\n", " diepte_laag_van diepte_laag_tot hoofdnaam1_grondsoort \\\n", "0 0.0 0.5 LE \n", "1 0.5 1.0 LE \n", "2 1.0 2.5 KL \n", "3 2.5 3.5 FZ \n", "4 3.5 7.0 FZ \n", "\n", " hoofdnaam2_grondsoort bijmenging1_plaatselijk bijmenging1_hoeveelheid \\\n", "0 NaN False N \n", "1 NaN NaN NaN \n", "2 NaN False N \n", "3 NaN False N \n", "4 NaN False N \n", "\n", " bijmenging1_grondsoort bijmenging2_plaatselijk bijmenging2_hoeveelheid \\\n", "0 XZ NaN NaN \n", "1 NaN NaN NaN \n", "2 XZ NaN NaN \n", "3 GL False N \n", "4 GL NaN NaN \n", "\n", " bijmenging2_grondsoort bijmenging3_plaatselijk bijmenging3_hoeveelheid \\\n", "0 NaN NaN NaN \n", "1 NaN NaN NaN \n", "2 NaN NaN NaN \n", "3 KL NaN NaN \n", "4 NaN NaN NaN \n", "\n", " bijmenging3_grondsoort \n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN " ], "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
pkey_interpretatiepkey_boringbetrouwbaarheid_interpretatiexystart_interpretatie_mtawdiepte_laag_vandiepte_laag_tothoofdnaam1_grondsoorthoofdnaam2_grondsoortbijmenging1_plaatselijkbijmenging1_hoeveelheidbijmenging1_grondsoortbijmenging2_plaatselijkbijmenging2_hoeveelheidbijmenging2_grondsoortbijmenging3_plaatselijkbijmenging3_hoeveelheidbijmenging3_grondsoort
0https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1974...goed153147.0206931.014.120.00.5LENaNFalseNXZNaNNaNNaNNaNNaNNaN
1https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1974...goed153147.0206931.014.120.51.0LENaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
2https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1974...goed153147.0206931.014.121.02.5KLNaNFalseNXZNaNNaNNaNNaNNaNNaN
3https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1974...goed153147.0206931.014.122.53.5FZNaNFalseNGLFalseNKLNaNNaNNaN
4https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1974...goed153147.0206931.014.123.57.0FZNaNFalseNGLNaNNaNNaNNaNNaNNaN
\n
" }, "metadata": {}, "execution_count": 7 } ], "source": [ "from pydov.util.location import Within, Box\n", "\n", "df = itp.search(location=Within(Box(153145, 206930, 153150, 206935)))\n", "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The dataframe contains one 'Gecodeerde lithologie' interpretation where five layers ('laag') were identified. The available data are flattened to represent unique attributes per row of the dataframe.\n", "\n", "Using the *pkey_interpretatie* field one can request the details of this interpretation in a webbrowser:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "https://www.dov.vlaanderen.be/data/interpretatie/2001-186544\n" ] } ], "source": [ "for pkey_interpretatie in set(df.pkey_interpretatie):\n", " print(pkey_interpretatie)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get 'Gecodeerde lithologie' with specific properties within a distance from a point" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next to querying interpretations based on their geographic location within a bounding box, we can also search for interpretations matching a specific set of properties. For this we can build a query using a combination of the 'Gecodeerde lithologie' fields and operators provided by the WFS protocol.\n", "\n", "A list of possible operators can be found below:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "['PropertyIsBetween',\n", " 'PropertyIsEqualTo',\n", " 'PropertyIsGreaterThan',\n", " 'PropertyIsGreaterThanOrEqualTo',\n", " 'PropertyIsLessThan',\n", " 'PropertyIsLessThanOrEqualTo',\n", " 'PropertyIsLike',\n", " 'PropertyIsNotEqualTo',\n", " 'PropertyIsNull',\n", " 'SortProperty']" ] }, "metadata": {}, "execution_count": 9 } ], "source": [ "[i for i,j in inspect.getmembers(sys.modules['owslib.fes'], inspect.isclass) if 'Property' in i]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example we build a query using the *PropertyIsGreaterThan* and *PropertyIsEqualTo* operators to find all interpretations that are at least 20 m deep, that are deemed appropriate for a range of 1 km from a defined point:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "[000/002] ..\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ " pkey_interpretatie \\\n", "0 https://www.dov.vlaanderen.be/data/interpretat... \n", "1 https://www.dov.vlaanderen.be/data/interpretat... \n", "2 https://www.dov.vlaanderen.be/data/interpretat... \n", "3 https://www.dov.vlaanderen.be/data/interpretat... \n", "4 https://www.dov.vlaanderen.be/data/interpretat... \n", "\n", " pkey_boring \\\n", "0 https://www.dov.vlaanderen.be/data/boring/1994... \n", "1 https://www.dov.vlaanderen.be/data/boring/1994... \n", "2 https://www.dov.vlaanderen.be/data/boring/1994... \n", "3 https://www.dov.vlaanderen.be/data/boring/1994... \n", "4 https://www.dov.vlaanderen.be/data/boring/1994... \n", "\n", " betrouwbaarheid_interpretatie x y \\\n", "0 goed 152565.03 207059.35 \n", "1 goed 152565.03 207059.35 \n", "2 goed 152565.03 207059.35 \n", "3 goed 152565.03 207059.35 \n", "4 goed 152565.03 207059.35 \n", "\n", " start_interpretatie_mtaw diepte_laag_van diepte_laag_tot \\\n", "0 18.75 0.0 1.0 \n", "1 18.75 1.0 2.0 \n", "2 18.75 2.0 4.0 \n", "3 18.75 4.0 18.0 \n", "4 18.75 18.0 19.0 \n", "\n", " hoofdnaam1_grondsoort hoofdnaam2_grondsoort bijmenging1_plaatselijk \\\n", "0 FZ NaN False \n", "1 FZ NaN False \n", "2 FZ NaN False \n", "3 FZ NaN False \n", "4 FZ NaN False \n", "\n", " bijmenging1_hoeveelheid bijmenging1_grondsoort bijmenging2_plaatselijk \\\n", "0 M KA NaN \n", "1 M SF False \n", "2 M SF False \n", "3 M GL False \n", "4 S LE NaN \n", "\n", " bijmenging2_hoeveelheid bijmenging2_grondsoort bijmenging3_plaatselijk \\\n", "0 NaN NaN NaN \n", "1 M ST NaN \n", "2 M ST NaN \n", "3 M SF False \n", "4 NaN NaN NaN \n", "\n", " bijmenging3_hoeveelheid bijmenging3_grondsoort \n", "0 NaN NaN \n", "1 NaN NaN \n", "2 NaN NaN \n", "3 M ST \n", "4 NaN NaN " ], "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
pkey_interpretatiepkey_boringbetrouwbaarheid_interpretatiexystart_interpretatie_mtawdiepte_laag_vandiepte_laag_tothoofdnaam1_grondsoorthoofdnaam2_grondsoortbijmenging1_plaatselijkbijmenging1_hoeveelheidbijmenging1_grondsoortbijmenging2_plaatselijkbijmenging2_hoeveelheidbijmenging2_grondsoortbijmenging3_plaatselijkbijmenging3_hoeveelheidbijmenging3_grondsoort
0https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1994...goed152565.03207059.3518.750.01.0FZNaNFalseMKANaNNaNNaNNaNNaNNaN
1https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1994...goed152565.03207059.3518.751.02.0FZNaNFalseMSFFalseMSTNaNNaNNaN
2https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1994...goed152565.03207059.3518.752.04.0FZNaNFalseMSFFalseMSTNaNNaNNaN
3https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1994...goed152565.03207059.3518.754.018.0FZNaNFalseMGLFalseMSFFalseMST
4https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1994...goed152565.03207059.3518.7518.019.0FZNaNFalseSLENaNNaNNaNNaNNaNNaN
\n
" }, "metadata": {}, "execution_count": 10 } ], "source": [ "from owslib.fes import And, PropertyIsGreaterThan, PropertyIsEqualTo\n", "from pydov.util.location import WithinDistance, Point\n", "\n", "query = And([PropertyIsEqualTo(propertyname='Betrouwbaarheid',\n", " literal='goed'),\n", " PropertyIsGreaterThan(propertyname='diepte_tot_m',\n", " literal='20'),\n", " ])\n", " \n", "df = itp.search(query=query, \n", " location=WithinDistance(Point(153145, 206930), 1000))\n", "\n", "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Once again we can use the *pkey_interpretatie* as a permanent link to the information of these interpretations:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "https://www.dov.vlaanderen.be/data/interpretatie/2016-294473\nhttps://www.dov.vlaanderen.be/data/interpretatie/2016-294475\n" ] } ], "source": [ "for pkey_interpretatie in set(df.pkey_interpretatie):\n", " print(pkey_interpretatie)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get 'Gecodeerde lithologie' in a bounding box based on specific properties" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can combine a query on attributes with a query on geographic location to get the interpretations within a bounding box that have specific properties.\n", "\n", "The following example requests the interpretations of boreholes only, within the given bounding box.\n", "\n", "(Note that the datatype of the *literal* parameter should be a string, regardless of the datatype of this field in the output dataframe.)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "[000/001] c\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ " pkey_interpretatie \\\n", "0 https://www.dov.vlaanderen.be/data/interpretat... \n", "1 https://www.dov.vlaanderen.be/data/interpretat... \n", "2 https://www.dov.vlaanderen.be/data/interpretat... \n", "3 https://www.dov.vlaanderen.be/data/interpretat... \n", "4 https://www.dov.vlaanderen.be/data/interpretat... \n", "\n", " pkey_boring \\\n", "0 https://www.dov.vlaanderen.be/data/boring/1974... \n", "1 https://www.dov.vlaanderen.be/data/boring/1974... \n", "2 https://www.dov.vlaanderen.be/data/boring/1974... \n", "3 https://www.dov.vlaanderen.be/data/boring/1974... \n", "4 https://www.dov.vlaanderen.be/data/boring/1974... \n", "\n", " betrouwbaarheid_interpretatie x y start_interpretatie_mtaw \\\n", "0 goed 153147.0 206931.0 14.12 \n", "1 goed 153147.0 206931.0 14.12 \n", "2 goed 153147.0 206931.0 14.12 \n", "3 goed 153147.0 206931.0 14.12 \n", "4 goed 153147.0 206931.0 14.12 \n", "\n", " diepte_laag_van diepte_laag_tot hoofdnaam1_grondsoort \\\n", "0 0.0 0.5 LE \n", "1 0.5 1.0 LE \n", "2 1.0 2.5 KL \n", "3 2.5 3.5 FZ \n", "4 3.5 7.0 FZ \n", "\n", " hoofdnaam2_grondsoort bijmenging1_plaatselijk bijmenging1_hoeveelheid \\\n", "0 NaN False N \n", "1 NaN NaN NaN \n", "2 NaN False N \n", "3 NaN False N \n", "4 NaN False N \n", "\n", " bijmenging1_grondsoort bijmenging2_plaatselijk bijmenging2_hoeveelheid \\\n", "0 XZ NaN NaN \n", "1 NaN NaN NaN \n", "2 XZ NaN NaN \n", "3 GL False N \n", "4 GL NaN NaN \n", "\n", " bijmenging2_grondsoort bijmenging3_plaatselijk bijmenging3_hoeveelheid \\\n", "0 NaN NaN NaN \n", "1 NaN NaN NaN \n", "2 NaN NaN NaN \n", "3 KL NaN NaN \n", "4 NaN NaN NaN \n", "\n", " bijmenging3_grondsoort \n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN " ], "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
pkey_interpretatiepkey_boringbetrouwbaarheid_interpretatiexystart_interpretatie_mtawdiepte_laag_vandiepte_laag_tothoofdnaam1_grondsoorthoofdnaam2_grondsoortbijmenging1_plaatselijkbijmenging1_hoeveelheidbijmenging1_grondsoortbijmenging2_plaatselijkbijmenging2_hoeveelheidbijmenging2_grondsoortbijmenging3_plaatselijkbijmenging3_hoeveelheidbijmenging3_grondsoort
0https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1974...goed153147.0206931.014.120.00.5LENaNFalseNXZNaNNaNNaNNaNNaNNaN
1https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1974...goed153147.0206931.014.120.51.0LENaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
2https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1974...goed153147.0206931.014.121.02.5KLNaNFalseNXZNaNNaNNaNNaNNaNNaN
3https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1974...goed153147.0206931.014.122.53.5FZNaNFalseNGLFalseNKLNaNNaNNaN
4https://www.dov.vlaanderen.be/data/interpretat...https://www.dov.vlaanderen.be/data/boring/1974...goed153147.0206931.014.123.57.0FZNaNFalseNGLNaNNaNNaNNaNNaNNaN
\n
" }, "metadata": {}, "execution_count": 12 } ], "source": [ "from owslib.fes import PropertyIsEqualTo\n", "\n", "query = PropertyIsEqualTo(\n", " propertyname='Type_proef',\n", " literal='Boring')\n", "\n", "df = itp.search(\n", " location=Within(Box(153145, 206930, 154145, 207930)),\n", " query=query\n", " )\n", "\n", "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can look at one of the interpretations in a webbrowser using its *pkey_interpretatie*:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "https://www.dov.vlaanderen.be/data/interpretatie/2001-186544\n" ] } ], "source": [ "for pkey_interpretatie in set(df.pkey_interpretatie):\n", " print(pkey_interpretatie)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get 'Gecodeerde lithologie' based on fields not available in the standard output dataframe" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To keep the output dataframe size acceptable, not all available WFS fields are included in the standard output. However, one can use this information to select interpretations as illustrated below.\n", "\n", "For example, make a selection of the interpretations in municipality the of Antwerp, before 1/1/1990:\n", "\n", "!*remark: mind that the municipality attribute is merely an attribute that is defined by the person entering the data. It can be ok, empty, outdated or wrong*!" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " pkey_interpretatie Datum\n", "0 https://www.dov.vlaanderen.be/data/interpretat... 2008-03-28\n", "1 https://www.dov.vlaanderen.be/data/interpretat... 2001-07-04\n", "2 https://www.dov.vlaanderen.be/data/interpretat... 2001-07-04\n", "3 https://www.dov.vlaanderen.be/data/interpretat... 2001-07-16\n", "4 https://www.dov.vlaanderen.be/data/interpretat... 2001-07-16" ], "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
pkey_interpretatieDatum
0https://www.dov.vlaanderen.be/data/interpretat...2008-03-28
1https://www.dov.vlaanderen.be/data/interpretat...2001-07-04
2https://www.dov.vlaanderen.be/data/interpretat...2001-07-04
3https://www.dov.vlaanderen.be/data/interpretat...2001-07-16
4https://www.dov.vlaanderen.be/data/interpretat...2001-07-16
\n
" }, "metadata": {}, "execution_count": 14 } ], "source": [ "from owslib.fes import And, PropertyIsEqualTo, PropertyIsLessThan\n", "\n", "query = And([PropertyIsEqualTo(propertyname='gemeente',\n", " literal='Antwerpen'),\n", " PropertyIsLessThan(propertyname='Datum', \n", " literal='2010-01-01')]\n", " )\n", "df = itp.search(query=query,\n", " return_fields=('pkey_interpretatie', 'Datum'))\n", "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get 'Gecodeerde lithologie' data, returning fields not available in the standard output dataframe" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As denoted in the previous example, not all available fields are available in the default output frame to keep its size limited. However, you can request any available field by including it in the *return_fields* parameter of the search:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "output_type": "error", "ename": "InvalidFieldError", "evalue": "Unknown return field: 'Z_mTAW'. Did you mean 'start_interpretatie_mtaw'?", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mInvalidFieldError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m literal='Leuven')\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m df = itp.search(query=query,\n\u001b[0m\u001b[1;32m 6\u001b[0m return_fields=('pkey_interpretatie', 'pkey_boring',\n\u001b[1;32m 7\u001b[0m 'x', 'y', 'Z_mTAW', 'gemeente', 'Auteurs', 'Proefnummer'))\n", "\u001b[0;32m~/Sideprojects/pydov/pydov_git/pydov/search/abstract.py\u001b[0m in \u001b[0;36msearch\u001b[0;34m(self, location, query, sort_by, return_fields, max_features)\u001b[0m\n\u001b[1;32m 838\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 839\u001b[0m \"\"\"\n\u001b[0;32m--> 840\u001b[0;31m fts = self._search(location=location, query=query, sort_by=sort_by,\n\u001b[0m\u001b[1;32m 841\u001b[0m \u001b[0mreturn_fields\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mreturn_fields\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 842\u001b[0m max_features=max_features)\n", "\u001b[0;32m~/Sideprojects/pydov/pydov_git/pydov/search/abstract.py\u001b[0m in \u001b[0;36m_search\u001b[0;34m(self, location, query, return_fields, sort_by, max_features, extra_wfs_fields)\u001b[0m\n\u001b[1;32m 659\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 660\u001b[0m \"\"\"\n\u001b[0;32m--> 661\u001b[0;31m self._pre_search_validation(location, query, sort_by, return_fields,\n\u001b[0m\u001b[1;32m 662\u001b[0m max_features)\n\u001b[1;32m 663\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_init_namespace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Sideprojects/pydov/pydov_git/pydov/search/abstract.py\u001b[0m in \u001b[0;36m_pre_search_validation\u001b[0;34m(self, location, query, sort_by, return_fields, max_features)\u001b[0m\n\u001b[1;32m 540\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mrf\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_fields\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 541\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mrf\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_map_wfs_source_df\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 542\u001b[0;31m raise InvalidFieldError(\n\u001b[0m\u001b[1;32m 543\u001b[0m \u001b[0;34m\"Unknown return field: \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 544\u001b[0m \"'{}'. Did you mean '{}'?\".format(\n", "\u001b[0;31mInvalidFieldError\u001b[0m: Unknown return field: 'Z_mTAW'. Did you mean 'start_interpretatie_mtaw'?" ] } ], "source": [ "query = PropertyIsEqualTo(\n", " propertyname='gemeente',\n", " literal='Leuven')\n", "\n", "df = itp.search(query=query,\n", " return_fields=('pkey_interpretatie', 'pkey_boring',\n", " 'x', 'y', 'Z_mTAW', 'gemeente', 'Auteurs', 'Proefnummer'))\n", "\n", "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualize results" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using Folium, we can display the results of our search on a map." ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "# import the necessary modules (not included in the requirements of pydov!)\n", "import folium\n", "from folium.plugins import MarkerCluster\n", "from pyproj import Transformer" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "# convert the coordinates to lat/lon for folium\n", "def convert_latlon(x1, y1):\n", " transformer = Transformer.from_crs(\"epsg:31370\", \"epsg:4326\", always_xy=True)\n", " x2,y2 = transformer.transform(x1, y1)\n", " return x2, y2\n", "\n", "df['lon'], df['lat'] = zip(*map(convert_latlon, df['x'], df['y'])) \n", "# convert to list\n", "loclist = df[['lat', 'lon']].values.tolist()" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# initialize the Folium map on the centre of the selected locations, play with the zoom until ok\n", "fmap = folium.Map(location=[df['lat'].mean(), df['lon'].mean()], zoom_start=12)\n", "marker_cluster = MarkerCluster().add_to(fmap)\n", "for loc in range(0, len(loclist)):\n", " folium.Marker(loclist[loc], popup=df['Proefnummer'][loc]).add_to(marker_cluster)\n", "fmap\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.7.5 64-bit ('venv': venv)", "language": "python", "name": "python37564bitvenvvenv7153db2e85324c8ea2b6eb355f534b21" }, "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.8.5-final" } }, "nbformat": 4, "nbformat_minor": 4 }