Example of DOV search methods for quartaire stratigrafie

Binder

Use cases:

  • Select records in a bbox

  • Select records in a bbox with selected properties

  • Select records within a distance from a point

  • Select records in a municipality

  • Get records using info from wfs fields, not available in the standard output dataframe

[1]:
%matplotlib inline
import os, sys
import inspect
[2]:
# check pydov path
import pydov

Get information about code base

[3]:
from pydov.search.interpretaties import QuartairStratigrafieSearch
# information about the QuartairStratigrafie type (In Dutch):
ip_quart = QuartairStratigrafieSearch()
ip_quart.get_description()
[3]:
'De quartaire afzettingen in Vlaanderen, de jongste afzettingen, zijn lateraal en verticaal heterogeen en varieren erg in dikte. De afzettingen zijn vooral onder continentale omstandigheden tot stand gekomen (rivier-, duinafzettingen). Eigenlijk zijn het pakketten die zelden meer dan 30 meter en soms zelfs minder dan 1 meter dik zijn. Omwille van deze grote eigenheid en de grote mate van detail van de beschrijvingen, werd hiervoor een eigen stratigrafische codering uitgewerkt voor Vlaanderen.'
[4]:
# information about the available fields for a QuartairStratigrafie object
fields = ip_quart.get_fields()
# print available fields
for f in fields.values():
    print(f['name'])
pkey_interpretatie
Type_proef
Proefnummer
pkey_boring
x
y
start_interpretatie_mtaw
diepte_tot_m
gemeente
Auteurs
Datum
Opdrachten
betrouwbaarheid_interpretatie
Geldig_van
Geldig_tot
eerste_invoer
geom
diepte_laag_van
diepte_laag_tot
lid1
relatie_lid1_lid2
lid2
[5]:
# print information for a certain field
fields['Type_proef']
[5]:
{'name': 'Type_proef',
 'definition': "Het type van de proef waarvan de quartaire stratigrafie een interpretatie is. Bij een quartaire stratigrafie zal dit altijd 'Boring' zijn.",
 'type': 'string',
 'notnull': False,
 'query': True,
 'cost': 1,
 'values': {'Boring': 'De quartaire stratigrafie is een interpretatie van een boring.'}}

The cost is an arbitrary attribute to indicate if the information is retrieved from a wfs query (cost = 1), or from an xml (cost = 10)

Try-out of use cases

Select interpretations in a bbox

[6]:
from pydov.util.location import Within, Box

# Get all interpretations in a bounding box (llx, lly, ulx, uly)
# the pkey_boring link is not available below, but is in the df
df = ip_quart.search(location=Within(Box(132815, 191700, 133815, 192700)))
df.head()
[000/001] .
[000/003] ...
[6]:
pkey_interpretatie pkey_boring betrouwbaarheid_interpretatie x y start_interpretatie_mtaw diepte_laag_van diepte_laag_tot lid1 relatie_lid1_lid2 lid2
0 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1974... onbekend 132975.0 191969.0 2.84 0.0 4.5 K T K
1 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1974... onbekend 132975.0 191969.0 2.84 4.5 7.5 F T F
2 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1974... onbekend 132975.0 191969.0 2.84 7.5 8.0 Rf T Rf
3 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1974... onbekend 132949.0 192068.0 2.57 0.0 4.5 K T K
4 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1974... onbekend 132949.0 192068.0 2.57 4.5 9.5 F T F

Select interpretations in a bbox with selected properties

[7]:
# list available query methods
methods = [i for i,j in inspect.getmembers(sys.modules['owslib.fes2'],
                                           inspect.isclass)
           if 'Property' in i]
methods
[7]:
['PropertyIsBetween',
 'PropertyIsEqualTo',
 'PropertyIsGreaterThan',
 'PropertyIsGreaterThanOrEqualTo',
 'PropertyIsLessThan',
 'PropertyIsLessThanOrEqualTo',
 'PropertyIsLike',
 'PropertyIsNotEqualTo',
 'PropertyIsNull',
 'SortProperty']
[8]:
from owslib.fes2 import PropertyIsGreaterThanOrEqualTo

The property feature methodes listed above are available from the owslib module. These were not adapted for use in pydov.

[9]:
# Get deep boreholes in a bounding box
from owslib.fes2 import PropertyIsLike
# the propertyname can be any of the fields of the interpretations object that belong to the wfs source
# the literal is always a string, no matter what its definition is in the boring object (string, float...)
query = PropertyIsLike(
        propertyname='betrouwbaarheid_interpretatie', literal='onbekend')
df = ip_quart.search(location=Within(Box(132815, 191700, 133815, 192700)),
                     query=query
                    )
df.head()
[000/001] .
[000/003] ccc
[9]:
pkey_interpretatie pkey_boring betrouwbaarheid_interpretatie x y start_interpretatie_mtaw diepte_laag_van diepte_laag_tot lid1 relatie_lid1_lid2 lid2
0 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1974... onbekend 132975.0 191969.0 2.84 0.0 4.5 K T K
1 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1974... onbekend 132975.0 191969.0 2.84 4.5 7.5 F T F
2 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1974... onbekend 132975.0 191969.0 2.84 7.5 8.0 Rf T Rf
3 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1974... onbekend 132949.0 192068.0 2.57 0.0 4.5 K T K
4 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1974... onbekend 132949.0 192068.0 2.57 4.5 9.5 F T F

Select records within a distance from a point

[10]:
from pydov.util.location import Point, WithinDistance

# Get all interpretations within a defined distance from a point
location = WithinDistance(location=Point(133000, 192000),
                          distance=1000, distance_unit='meter')
df = ip_quart.search(location=location)
df.head()
[000/001] .
[000/015] cc.........c...
[10]:
pkey_interpretatie pkey_boring betrouwbaarheid_interpretatie x y start_interpretatie_mtaw diepte_laag_van diepte_laag_tot lid1 relatie_lid1_lid2 lid2
0 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1974... onbekend 132975.0 191969.0 2.84 0.0 4.50 K T K
1 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1974... onbekend 132975.0 191969.0 2.84 4.5 7.50 F T F
2 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1974... onbekend 132975.0 191969.0 2.84 7.5 8.00 Rf T Rf
3 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/2016... onbekend 133144.8 191408.3 5.53 0.0 4.20 D T D
4 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/2016... onbekend 133144.8 191408.3 5.53 4.2 10.41 F T F

Select interpretations in a municipality

[11]:
from owslib.fes2 import PropertyIsEqualTo
query = PropertyIsEqualTo(propertyname='gemeente',
                          literal='Hamme')
df = ip_quart.search(query=query)
df.head()
[000/001] .
[000/028] ............................
[11]:
pkey_interpretatie pkey_boring betrouwbaarheid_interpretatie x y start_interpretatie_mtaw diepte_laag_van diepte_laag_tot lid1 relatie_lid1_lid2 lid2
0 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1894... goed 128930.0 198740.0 4.0 0.0 12.2 F T F
1 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1894... goed 128930.0 198740.0 4.0 12.2 20.4 $ T $
2 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1909... onbekend 134722.6 194263.5 2.0 0.0 2.9 ! T !
3 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1909... onbekend 134722.6 194263.5 2.0 2.9 13.9 F T F
4 https://www.dov.vlaanderen.be/data/interpretat... https://www.dov.vlaanderen.be/data/boring/1909... onbekend 134722.6 194263.5 2.0 13.9 35.0 $ T $

Visualize results

Using Folium, we can display the results of our search on a map.

[12]:
# import the necessary modules (not included in the requirements of pydov!)
import folium
from folium.plugins import MarkerCluster
from pyproj import Transformer
# for windows 10 users, we could not get it working with Microsoft Edge
# change the browser to Chrome in the Notebook config file instead
[13]:
# convert the coordinates to lat/lon for folium
def convert_latlon(x1, y1):
    transformer = Transformer.from_crs("epsg:31370", "epsg:4326", always_xy=True)
    x2,y2 = transformer.transform(x1, y1)
    return x2, y2

df['lon'], df['lat'] = zip(*map(convert_latlon, df['x'], df['y']))
# convert to list
loclist = df[['lat', 'lon']].values.tolist()
[14]:
# initialize the Folium map on the centre of the selected locations, play with the zoom until ok
fmap = folium.Map(location=[df['lat'].mean(), df['lon'].mean()], zoom_start=12)
marker_cluster = MarkerCluster().add_to(fmap)
for loc in range(0, len(loclist)):
    folium.Marker(loclist[loc], popup=df['lid1'][loc]).add_to(marker_cluster)
fmap
[14]:
Make this Notebook Trusted to load map: File -> Trust Notebook