In [1]:
%matplotlib inline
import inspect, sys
import warnings; warnings.simplefilter('ignore')
In [2]:
# check pydov path
import pydov
In [3]:
from pydov.search.boring import BoringSearch
boring = BoringSearch()
A description is provided for the 'Boring' datatype:
In [4]:
boring.get_description()
Out[4]:
The different fields that are available for objects of the 'Boring' datatype can be requested with the get_fields() method:
In [5]:
fields = boring.get_fields()
# print available fields
for f in fields.values():
print(f['name'])
You can get more information of a field by requesting it from the fields dictionary:
In [6]:
fields['diepte_boring_tot']
Out[6]:
Optionally, if the values of the field have a specific domain the possible values are listed as values:
In [7]:
fields['methode']['values']
Out[7]:
Get data for all the boreholes that are geographically located within the bounds of the specified box.
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.
In [8]:
from pydov.util.location import Within, Box
df = boring.search(location=Within(Box(153145, 206930, 153150, 206935)))
df.head()
Out[8]:
The dataframe contains one borehole where three methods ('boormethode') were applied for its construction. The available data are flattened to represent unique attributes per row of the dataframe.
Using the pkey_boring field one can request the details of this borehole in a webbrowser:
In [9]:
for pkey_boring in set(df.pkey_boring):
print(pkey_boring)
Next to querying boreholes based on their geographic location within a bounding box, we can also search for boreholes matching a specific set of properties. For this we can build a query using a combination of the 'Boring' fields and operators provided by the WFS protocol.
A list of possible operators can be found below:
In [10]:
[i for i,j in inspect.getmembers(sys.modules['owslib.fes'], inspect.isclass) if 'Property' in i]
Out[10]:
In this example we build a query using the PropertyIsEqualTo operator to find all boreholes that are within the community (gemeente) of 'Herstappe':
In [11]:
from owslib.fes import PropertyIsEqualTo
query = PropertyIsEqualTo(propertyname='gemeente',
literal='Herstappe')
df = boring.search(query=query)
df.head()
Out[11]:
Once again we can use the pkey_boring as a permanent link to the information of these boreholes:
In [12]:
for pkey_boring in set(df.pkey_boring):
print(pkey_boring)
We can combine a query on attributes with a query on geographic location to get the boreholes within a bounding box that have specific properties.
The following example requests the boreholes with a depth greater than or equal to 2000 meters within the given bounding box.
(Note that the datatype of the literal parameter should be a string, regardless of the datatype of this field in the output dataframe.)
In [13]:
from owslib.fes import PropertyIsGreaterThanOrEqualTo
query = PropertyIsGreaterThanOrEqualTo(
propertyname='diepte_boring_tot',
literal='2000')
df = boring.search(
location=Within(Box(200000, 211000, 205000, 214000)),
query=query
)
df.head()
Out[13]:
We can look at one of the boreholes in a webbrowser using its pkey_boring:
In [14]:
for pkey_boring in set(df.pkey_boring):
print(pkey_boring)
We can limit the columns in the output dataframe by specifying the return_fields parameter in our search.
In this example we query all the boreholes in the city of Ghent and return their depth:
In [15]:
query = PropertyIsEqualTo(propertyname='gemeente',
literal='Gent')
df = boring.search(query=query,
return_fields=('diepte_boring_tot',))
df.head()
Out[15]:
In [16]:
df.describe()
Out[16]:
By discarding the boreholes with a depth of 0 m, we get a different result:
In [17]:
df[df.diepte_boring_tot != 0].describe()
Out[17]:
In [19]:
ax = df[df.diepte_boring_tot != 0].boxplot()
ax.set_ylabel("Depth (m)");
ax.set_title("Distribution borehole depth Gent");
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 boreholes as illustrated below.
For example, make a selection of the boreholes in municipality the of Antwerp, for which a hydrogeological interpretation was performed:
In [52]:
from owslib.fes import And
query = And([PropertyIsEqualTo(propertyname='gemeente',
literal='Antwerpen'),
PropertyIsEqualTo(propertyname='hydrogeologische_stratigrafie',
literal='True')]
)
df = boring.search(query=query,
return_fields=('pkey_boring', 'boornummer', 'x', 'y', 'diepte_boring_tot', 'datum_aanvang'))
df.head()
Out[52]:
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:
In [53]:
query = PropertyIsGreaterThanOrEqualTo(
propertyname='diepte_boring_tot',
literal='2000')
df = boring.search(query=query,
return_fields=('pkey_boring', 'boornummer', 'diepte_boring_tot',
'informele_stratigrafie', 'formele_stratigrafie', 'lithologische_beschrijving',
'gecodeerde_lithologie', 'hydrogeologische_stratigrafie', 'quartaire_stratigrafie',
'geotechnische_codering', 'informele_hydrostratigrafie'))
df.head()
Out[53]:
The following full example return all boreholes where gemeente is 'Antwerpen' and either putnummer is not empty or doel starts with 'Grondwater' or erkenning is '2. Andere grondwaterwinningen'.
In [54]:
from owslib.fes import PropertyIsLike
from owslib.fes import PropertyIsNull
from owslib.fes import Or
from owslib.fes import Not
query = And([PropertyIsEqualTo(propertyname='gemeente',
literal='Antwerpen'),
Or([Not([PropertyIsNull(propertyname='putnummer')]),
PropertyIsLike(propertyname='doel',
literal='Grondwater%'),
PropertyIsEqualTo(propertyname='erkenning',
literal='2. Andere grondwaterwinningen')]
)]
)
df = boring.search(query=query)
df.head()
Out[54]:
Using Folium, we can display the results of our search on a map.
In [55]:
# import the necessary modules (not included in the requirements of pydov!)
import folium
from folium.plugins import MarkerCluster
from pyproj import Transformer
In [57]:
# 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()
In [58]:
# 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['boornummer'][loc]).add_to(marker_cluster)
fmap
Out[58]: