{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Example of DOV search methods for generic WFS layers" ] }, { "attachments": {}, "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_generic_wfs.ipynb)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Use cases explained below\n", "* Get data in a bounding box\n", "* Get data with specific properties\n", "* Get data in a bounding box based on specific properties\n", "* Select data and return a subset of columns\n", "* Using sorting and limiting to find the most recent data\n", "* Combining attribute queries to limit your results" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import inspect, sys\n", "import warnings; warnings.simplefilter('ignore')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# check pydov path\n", "import pydov" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Next to the predefined datatypes from pydov, one can also query any WFS layer available in DOV using pydov. This allows for the same workflow and search methods to be used to query all vectordata we publish. To check which layers are available, consult our [metadata catalogue](https://www.dov.vlaanderen.be/geonetwork)." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Get information about the datatype" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "When instantiating a `WfsSearch` instance, one has to provide the workspace-qualified layer name of the WFS service one would like to query:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from pydov.search.generic import WfsSearch\n", "wfs_search = WfsSearch('pfas:pfas_analyseresultaten')" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Once instantiated, one can request a description of the dataset:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'PFAS analyseresultaten aangeleverd door bodemsaneringsdeskundigen en opgenomen in de OVAM bodemdatabank.'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wfs_search.get_description()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "And a list of available fields:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "id\n", "opdracht\n", "pfasdossiernr\n", "profielnaam\n", "top_in_m\n", "basis_in_m\n", "jaar\n", "datum\n", "parameter\n", "detectieconditie\n", "meetwaarde\n", "meeteenheid\n", "medium\n", "profieltype\n", "plaatsing_profiel\n", "commentaar\n", "x_ml72\n", "y_ml72\n", "geom\n" ] } ], "source": [ "fields = wfs_search.get_fields()\n", "\n", "# print available fields\n", "for f in fields.values():\n", " print(f['name'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternatively, you can list all the fields and their details by inspecting the `get_fields()` output or the search instance itself in a notebook:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", "
\n", " \n", "
\n", " pydov.search.generic.WfsSearch\n", "
\n", "

PFAS analyseresultaten aangeleverd door bodemsaneringsdeskundigen en opgenomen in de OVAM bodemdatabank.

\n", " \n", "
\n", "

id - id

  • type: integer
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

opdracht - ID van het rapport in de OVAM databank waaruit het analyseresultaat afkomstig is

  • type: integer
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

pfasdossiernr - ID van het dossier in de OVAM databank waarin het rapport (opdracht) is opgenomen

  • type: integer
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

profielnaam - Verwijzing naar het profiel waaruit staal en analyseresultaat afkomstig is

  • type: string
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

top_in_m - De diepte t.o.v het maaiveld (top) van het geanalyseerde staal

  • type: float
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

basis_in_m - De diepte t.o.v het maaiveld (basis) van het geanalyseerde staal

  • type: float
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

jaar - Jaartal analyseresultaat

  • type: integer
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

datum - Datum analyseresultaat

  • type: date
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

parameter - Geanalyseerde parameter

  • type: string
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

detectieconditie - <, >, =

  • type: string
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

meetwaarde - Meetwaarde geanalyseerde parameter

  • type: float
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

meeteenheid - Eenheid meetwaarde geanalyseerde parameter

  • type: string
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

medium - Medium waaruit de staalname afkomstig is

  • type: string
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

profieltype - Soort profiel

  • type: string
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

plaatsing_profiel - Datum plaatsing profiel

  • type: date
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

commentaar - optioneel commentaarveld

  • type: string
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

x_ml72 - X-coördinaat

  • type: float
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

y_ml72 - Y-coördinaat

  • type: float
  • notnull: False
  • query: True
  • cost: 1
  • multivalue: False
\n", "
\n", " \n", " \n", "
\n", "

geom - None

  • type: geometry
  • notnull: False
  • query: False
  • cost: 1
  • multivalue: False
\n", "
\n", "

\n", "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wfs_search" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "You can get more information of a field by requesting it from the fields dictionary:\n", "\n", "* *name*: name of the field\n", "* *definition*: definition of this field, if available\n", "* *cost*: for generic WFS searches, this will be 1 in all cases\n", "* *notnull*: whether the field is mandatory or not\n", "* *type*: datatype of the values of this field\n", "* *codelist*: optionally, a codelist that describes the possible values of this field\n", "\n", "Alternatively, you can list all the fields and their details by inspecting the `get_fields()` output or the search instance itself in a notebook:" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Example use cases" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Get data in a bounding box" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Get data for all features 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": [ { "name": "stdout", "output_type": "stream", "text": [ "[000/001] .\n" ] }, { "data": { "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", "
idopdrachtpfasdossiernrprofielnaamtop_in_mbasis_in_mjaardatumparameterdetectieconditiemeetwaardemeeteenheidmediumprofieltypeplaatsing_profielcommentaarx_ml72y_ml72
0327849761393554461823470.00.220212021-12-16HFPO-DA<1.0µg/kg dsVaste deel van de aardeBoring2021-12-10143874.97217045.51
1327849771393554461823470.00.220212021-12-16MePFOSAtotaal<0.5µg/kg dsVaste deel van de aardeBoring2021-12-10143874.97217045.51
2327849781393554461823470.00.220212021-12-16PFHpS<0.2µg/kg dsVaste deel van de aardeBoring2021-12-10143874.97217045.51
3327849791393554461823470.00.220212021-12-164:2 FTS<0.2µg/kg dsVaste deel van de aardeBoring2021-12-10143874.97217045.51
4327849801393554461823470.00.220212021-12-16PFDA<0.2µg/kg dsVaste deel van de aardeBoring2021-12-10143874.97217045.51
\n", "
" ], "text/plain": [ " id opdracht pfasdossiernr profielnaam top_in_m basis_in_m jaar \\\n", "0 32784976 13935544 61823 47 0.0 0.2 2021 \n", "1 32784977 13935544 61823 47 0.0 0.2 2021 \n", "2 32784978 13935544 61823 47 0.0 0.2 2021 \n", "3 32784979 13935544 61823 47 0.0 0.2 2021 \n", "4 32784980 13935544 61823 47 0.0 0.2 2021 \n", "\n", " datum parameter detectieconditie meetwaarde meeteenheid \\\n", "0 2021-12-16 HFPO-DA < 1.0 µg/kg ds \n", "1 2021-12-16 MePFOSAtotaal < 0.5 µg/kg ds \n", "2 2021-12-16 PFHpS < 0.2 µg/kg ds \n", "3 2021-12-16 4:2 FTS < 0.2 µg/kg ds \n", "4 2021-12-16 PFDA < 0.2 µg/kg ds \n", "\n", " medium profieltype plaatsing_profiel commentaar \\\n", "0 Vaste deel van de aarde Boring 2021-12-10 \n", "1 Vaste deel van de aarde Boring 2021-12-10 \n", "2 Vaste deel van de aarde Boring 2021-12-10 \n", "3 Vaste deel van de aarde Boring 2021-12-10 \n", "4 Vaste deel van de aarde Boring 2021-12-10 \n", "\n", " x_ml72 y_ml72 \n", "0 143874.97 217045.51 \n", "1 143874.97 217045.51 \n", "2 143874.97 217045.51 \n", "3 143874.97 217045.51 \n", "4 143874.97 217045.51 " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pydov.util.location import Within, Box\n", "\n", "df = wfs_search.search(location=Within(Box(143400, 217000, 144000, 217200, epsg=31370)))\n", "df.head()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Get data with specific properties" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Next to querying data based on its geographic location within a bounding box, we can also search for data matching a specific set of properties. For this we can build a query using a combination of the available fields and operators provided by the WFS protocol.\n", "\n", "A list of possible operators can be found below:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['PropertyIsBetween',\n", " 'PropertyIsEqualTo',\n", " 'PropertyIsGreaterThan',\n", " 'PropertyIsGreaterThanOrEqualTo',\n", " 'PropertyIsLessThan',\n", " 'PropertyIsLessThanOrEqualTo',\n", " 'PropertyIsLike',\n", " 'PropertyIsNotEqualTo',\n", " 'PropertyIsNull',\n", " 'SortProperty']" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[i for i,j in inspect.getmembers(sys.modules['owslib.fes2'], inspect.isclass) if 'Property' in i]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example we build a query using the *PropertyIsEqualTo* operator to find all data for the parameter 'PFDA':" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[000/005] .....\n" ] }, { "data": { "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", "
idopdrachtpfasdossiernrprofielnaamtop_in_mbasis_in_mjaardatumparameterdetectieconditiemeetwaardemeeteenheidmediumprofieltypeplaatsing_profielcommentaarx_ml72y_ml72
031063085130770626180PB310.22.220212021-06-16PFDA<0.02µg/lGrondwaterPeilbuisNaN237529.0204908.0
1310632051307706261801080.50.720212021-06-01PFDA<0.20µg/kg dsVaste deel van de aardeBoring2021-05-21237521.0204927.0
2310633241307706261801090.50.720212021-05-28PFDA<0.20µg/kg dsVaste deel van de aardeBoring2021-05-21237504.0204955.0
331063593130770626180PB320.52.520212021-06-16PFDA<0.02µg/lGrondwaterPeilbuisNaN237506.0204991.0
4311511901312351922248P1011.53.520212021-06-30PFDA<1.00ng/lGrondwaterPeilbuis2021-06-1197442.0170962.0
\n", "
" ], "text/plain": [ " id opdracht pfasdossiernr profielnaam top_in_m basis_in_m jaar \\\n", "0 31063085 13077062 6180 PB31 0.2 2.2 2021 \n", "1 31063205 13077062 6180 108 0.5 0.7 2021 \n", "2 31063324 13077062 6180 109 0.5 0.7 2021 \n", "3 31063593 13077062 6180 PB32 0.5 2.5 2021 \n", "4 31151190 13123519 22248 P101 1.5 3.5 2021 \n", "\n", " datum parameter detectieconditie meetwaarde meeteenheid \\\n", "0 2021-06-16 PFDA < 0.02 µg/l \n", "1 2021-06-01 PFDA < 0.20 µg/kg ds \n", "2 2021-05-28 PFDA < 0.20 µg/kg ds \n", "3 2021-06-16 PFDA < 0.02 µg/l \n", "4 2021-06-30 PFDA < 1.00 ng/l \n", "\n", " medium profieltype plaatsing_profiel commentaar x_ml72 \\\n", "0 Grondwater Peilbuis NaN 237529.0 \n", "1 Vaste deel van de aarde Boring 2021-05-21 237521.0 \n", "2 Vaste deel van de aarde Boring 2021-05-21 237504.0 \n", "3 Grondwater Peilbuis NaN 237506.0 \n", "4 Grondwater Peilbuis 2021-06-11 97442.0 \n", "\n", " y_ml72 \n", "0 204908.0 \n", "1 204927.0 \n", "2 204955.0 \n", "3 204991.0 \n", "4 170962.0 " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from owslib.fes2 import PropertyIsEqualTo\n", "\n", "query = PropertyIsEqualTo(propertyname='parameter',\n", " literal='PFDA')\n", "df = wfs_search.search(query=query)\n", "\n", "df.head()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Get data in a bounding box based on specific properties" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We can combine a query on attributes with a query on geographic location to get the data within a bounding box that have specific properties.\n", "\n", "The following example requests the data for the parameter PFDA 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": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[000/001] .\n" ] }, { "data": { "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", "
idopdrachtpfasdossiernrprofielnaamtop_in_mbasis_in_mjaardatumparameterdetectieconditiemeetwaardemeeteenheidmediumprofieltypeplaatsing_profielcommentaarx_ml72y_ml72
0327849801393554461823470.00.220212021-12-16PFDA<0.2µg/kg dsVaste deel van de aardeBoring2021-12-10143874.97217045.51
1327850411393554461823440.00.220212021-12-16PFDA<0.2µg/kg dsVaste deel van de aardeBoring2021-12-10143449.23217048.64
2327850701393554461823PB70.00.020222022-01-18PFDA<1.0ng/lGrondwaterPeilbuis2021-12-10143622.88217056.85
3327850991393554461823460.00.220212021-12-16PFDA<0.2µg/kg dsVaste deel van de aardeBoring2021-12-10143747.63217023.63
4327851311393554461823406.17.120212021-12-20PFDA<1.0ng/lGrondwaterPeilbuis2019-10-10143654.00217032.00
\n", "
" ], "text/plain": [ " id opdracht pfasdossiernr profielnaam top_in_m basis_in_m jaar \\\n", "0 32784980 13935544 61823 47 0.0 0.2 2021 \n", "1 32785041 13935544 61823 44 0.0 0.2 2021 \n", "2 32785070 13935544 61823 PB7 0.0 0.0 2022 \n", "3 32785099 13935544 61823 46 0.0 0.2 2021 \n", "4 32785131 13935544 61823 40 6.1 7.1 2021 \n", "\n", " datum parameter detectieconditie meetwaarde meeteenheid \\\n", "0 2021-12-16 PFDA < 0.2 µg/kg ds \n", "1 2021-12-16 PFDA < 0.2 µg/kg ds \n", "2 2022-01-18 PFDA < 1.0 ng/l \n", "3 2021-12-16 PFDA < 0.2 µg/kg ds \n", "4 2021-12-20 PFDA < 1.0 ng/l \n", "\n", " medium profieltype plaatsing_profiel commentaar \\\n", "0 Vaste deel van de aarde Boring 2021-12-10 \n", "1 Vaste deel van de aarde Boring 2021-12-10 \n", "2 Grondwater Peilbuis 2021-12-10 \n", "3 Vaste deel van de aarde Boring 2021-12-10 \n", "4 Grondwater Peilbuis 2019-10-10 \n", "\n", " x_ml72 y_ml72 \n", "0 143874.97 217045.51 \n", "1 143449.23 217048.64 \n", "2 143622.88 217056.85 \n", "3 143747.63 217023.63 \n", "4 143654.00 217032.00 " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pydov.util.location import Within, Box\n", "\n", "df = wfs_search.search(\n", " query=PropertyIsEqualTo(propertyname='parameter', literal='PFDA'),\n", " location=Within(Box(143400, 217000, 144000, 217200, epsg=31370))\n", ")\n", "df.head()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Select data and return a subset of columns" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We can limit the columns in the output dataframe by specifying the *return_fields* parameter in our search.\n", "\n", "In this example we query all the data in a bounding box, but only return some of the fields:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[000/001] .\n" ] }, { "data": { "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", "
datumx_ml72y_ml72parameterdetectieconditiemeetwaardemeeteenheidmedium
02021-12-16143874.97217045.51HFPO-DA<1.0µg/kg dsVaste deel van de aarde
12021-12-16143874.97217045.51MePFOSAtotaal<0.5µg/kg dsVaste deel van de aarde
22021-12-16143874.97217045.51PFHpS<0.2µg/kg dsVaste deel van de aarde
32021-12-16143874.97217045.514:2 FTS<0.2µg/kg dsVaste deel van de aarde
42021-12-16143874.97217045.51PFDA<0.2µg/kg dsVaste deel van de aarde
\n", "
" ], "text/plain": [ " datum x_ml72 y_ml72 parameter detectieconditie \\\n", "0 2021-12-16 143874.97 217045.51 HFPO-DA < \n", "1 2021-12-16 143874.97 217045.51 MePFOSAtotaal < \n", "2 2021-12-16 143874.97 217045.51 PFHpS < \n", "3 2021-12-16 143874.97 217045.51 4:2 FTS < \n", "4 2021-12-16 143874.97 217045.51 PFDA < \n", "\n", " meetwaarde meeteenheid medium \n", "0 1.0 µg/kg ds Vaste deel van de aarde \n", "1 0.5 µg/kg ds Vaste deel van de aarde \n", "2 0.2 µg/kg ds Vaste deel van de aarde \n", "3 0.2 µg/kg ds Vaste deel van de aarde \n", "4 0.2 µg/kg ds Vaste deel van de aarde " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pydov.util.location import Within, Box\n", "\n", "df = wfs_search.search(\n", " location=Within(Box(143400, 217000, 144000, 217200, epsg=31370)),\n", " return_fields=['datum', 'x_ml72', 'y_ml72', 'parameter',\n", " 'detectieconditie', 'meetwaarde', 'meeteenheid', 'medium']\n", ")\n", "df.head()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Using sorting and limiting to find the most recent data" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "You can use sorting and limiting to find the highest, deepest, oldest, newest, ... data, depending on the available fields.\n", "\n", "In this example we search for the 100 most recent records:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[000/001] .\n" ] }, { "data": { "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", "
idopdrachtpfasdossiernrprofielnaamtop_in_mbasis_in_mjaardatumparameterdetectieconditiemeetwaardemeeteenheidmediumprofieltypeplaatsing_profielcommentaarx_ml72y_ml72
04948461717945116108231PB22.082.7820262026-01-16PFDS<10.0ng/lGrondwaterPeilbuis2025-10-10106744.0193702.0
14948463617945116108231PB22.082.7820262026-01-16<50.0ng/lGrondwaterPeilbuis2025-10-10106744.0193702.0
24948464317945116108231PB22.082.7820262026-01-16PFOStotaal<10.0ng/lGrondwaterPeilbuis2025-10-10106744.0193702.0
34948462117945116108231PB22.082.7820262026-01-16PFHxDA<10.0ng/lGrondwaterPeilbuis2025-10-10106744.0193702.0
44948462017945116108231PB22.082.7820262026-01-16PFDoDA<10.0ng/lGrondwaterPeilbuis2025-10-10106744.0193702.0
\n", "
" ], "text/plain": [ " id opdracht pfasdossiernr profielnaam top_in_m basis_in_m jaar \\\n", "0 49484617 17945116 108231 PB2 2.08 2.78 2026 \n", "1 49484636 17945116 108231 PB2 2.08 2.78 2026 \n", "2 49484643 17945116 108231 PB2 2.08 2.78 2026 \n", "3 49484621 17945116 108231 PB2 2.08 2.78 2026 \n", "4 49484620 17945116 108231 PB2 2.08 2.78 2026 \n", "\n", " datum parameter detectieconditie meetwaarde meeteenheid \\\n", "0 2026-01-16 PFDS < 10.0 ng/l \n", "1 2026-01-16 < 50.0 ng/l \n", "2 2026-01-16 PFOStotaal < 10.0 ng/l \n", "3 2026-01-16 PFHxDA < 10.0 ng/l \n", "4 2026-01-16 PFDoDA < 10.0 ng/l \n", "\n", " medium profieltype plaatsing_profiel commentaar x_ml72 y_ml72 \n", "0 Grondwater Peilbuis 2025-10-10 106744.0 193702.0 \n", "1 Grondwater Peilbuis 2025-10-10 106744.0 193702.0 \n", "2 Grondwater Peilbuis 2025-10-10 106744.0 193702.0 \n", "3 Grondwater Peilbuis 2025-10-10 106744.0 193702.0 \n", "4 Grondwater Peilbuis 2025-10-10 106744.0 193702.0 " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from owslib.fes2 import SortBy, SortProperty\n", "\n", "df = wfs_search.search(\n", " sort_by=SortBy([SortProperty('datum', 'DESC')]),\n", " max_features=100\n", ")\n", "df.head()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Combining attribute queries to limit your results" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "You can combine multiple attribute queries to construct and advanced query to search for exactly what you're looking for. This will be more performant than requesting more data and doing the filtering afterwards.\n", "\n", "In this example we search for data in given bounding box, for a given year, parameter and medium which exceeds a certain value:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[000/001] .\n" ] }, { "data": { "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", "
idopdrachtpfasdossiernrprofielnaamtop_in_mbasis_in_mjaardatumparameterdetectieconditiemeetwaardemeeteenheidmediumprofieltypeplaatsing_profielcommentaarx_ml72y_ml72
0327850701393554461823PB70.00.020222022-01-18PFDA<1.0ng/lGrondwaterPeilbuis2021-12-10143622.88217056.85
\n", "
" ], "text/plain": [ " id opdracht pfasdossiernr profielnaam top_in_m basis_in_m jaar \\\n", "0 32785070 13935544 61823 PB7 0.0 0.0 2022 \n", "\n", " datum parameter detectieconditie meetwaarde meeteenheid medium \\\n", "0 2022-01-18 PFDA < 1.0 ng/l Grondwater \n", "\n", " profieltype plaatsing_profiel commentaar x_ml72 y_ml72 \n", "0 Peilbuis 2021-12-10 143622.88 217056.85 " ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pydov.util.location import Within, Box\n", "from owslib.fes2 import PropertyIsEqualTo, PropertyIsGreaterThan, And\n", "\n", "df = wfs_search.search(\n", " query=And([\n", " PropertyIsEqualTo(propertyname='jaar', literal='2022'),\n", " PropertyIsEqualTo(propertyname='parameter', literal='PFDA'),\n", " PropertyIsEqualTo(propertyname='medium', literal='Grondwater'),\n", " PropertyIsGreaterThan(propertyname='meetwaarde', literal='0.5'),\n", " ]),\n", " location=Within(Box(143400, 217000, 144000, 217200, epsg=31370))\n", ")\n", "df.head()" ] } ], "metadata": { "kernelspec": { "display_name": ".venv (3.13.5)", "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.13.5" } }, "nbformat": 4, "nbformat_minor": 4 }