Skip to content

Tutorial

Josef K edited this page Apr 14, 2022 · 47 revisions

About this document

Please notice! This tutorial is written for a previous version of QGIS (and Midvatten plugin). There might be a few discrepancies but the tutorial is still very useful.

This page is setup as a tutorial and you may follow the instructions from the beginning to the end of this page. In fact, if you are new to Midvatten plugin for QGIS, then you are strongly recommended to read and follow the steps in this tutorial.

Only some basic tools and common usage situations are included in the tutorial. Additonal tools (mostly more advanced) are described under "Usage" on this wiki.

The sample data used for this tutorial may be downloaded from the following links (no login required). But please notice, the tutorial is outdated and so are the sample files:

Getting started

Start QGIS and create a database

  1. Start QGIS, download and activate Midvatten plugin
  2. Create a new and empty database of predefined design: When prompted, select CRS 4326 (WGS84)

Load default database layers to your qgis project

  1. Get yourself a background map layer, I highly recommend any of the layers you can get by using OpenLayers plugin:
    img

  2. Verify that the database is selected in Midvatten Settings (you may also click the Midvatten settings button in the Midvatten toolbar, or use function key F6):
    img

  3. Load default layers from the database, select Midvatten-Load default db-layers to qgis (or use function key F7):
    img

Afterwards you will see that all default layers from the database is loaded into a layer group called Midvatten_OBS_DB:
img

The database design is shown below and as you can see, many but not all tables from the database are loaded by default:
img

On the other hand, the database also contains some spatial views that are loaded as default layers, we will get back to those later:

  • obs_p_w_qual_field - all obs_points with data in table w_qual_field
  • obs_p_w_qual_lab - all obs_points with data in table w_qual_lab
  • obs_p_w_strat - all obs_points with data in table stratigraphy
  • obs_p_w_lvl - all obs_points with data in table w_levels
  • w_lvls_last_geom - all the latest measurements in table w_levels

Point observations (Wells and drilings)

Import point observations

  1. Import some observation points to the database from the file obs_points_4326.csv with encoding 'utf-8' using the General csv import. Make sure to select the file column "WKT" for the geometry column during import. Afterwards you may open the attribute table to see what data has been imported.
    img

  2. For plugin version <1.4Activate layer obs_points and create geometries for the observation points by selecting Midvatten-Edit data in database – Update map position from coordinates: img
    Select “All” when prompted to perform the update for all objects in the layer

  3. Right-click layer obs_points and select “zoom to layer” to see positions for the imported objects:
    img
    (Tips: Use OpenLayers plugin or some OpenStreetMap WMS layer to get a background map for you data. As you may see, the tutorial data is randomly placed in a non-relevant location.)

Add single point observations

  1. Activate layer obs_points and start editing (click the pen).

  2. Select Edit – Add Feature or select Add Feature tool from editor toolbar:
    img

  3. Place an observation point on the map and a custom edit form will show up:
    img

  4. Fill in all known information (for the tutorial it is enough with just an obsid). It is absolutely necessary to select an obsid which do not already exist in the database. Note: you should try to define and use an obsid that applies and is unchanged throughout the project since gets a little awkward to change it after you have added related information in any of the tables w_levels, stratigraphy, w_qual_lab etc. obsid is the primary link in tables obs_points and obs_lines, the other tables relates to the first two by the field obsid (see database design).

  5. Select xyz-tab and notice that no coordinates are shown although you marked a position for the point. The coordinates will be automatically added to the table based on current position when the changes are saved for the editing session.

  6. After you have given all known information (for the tutorial it is enough with just an obsid), close the edit form by clicking ”ok”.

  7. Open attribute table for obs_points, then activate the ’feature list’ by selecting the left of the two small icons in the lower right corner: img

  8. This will switch to another attribute table view where you can select different filters in the left panel, set filter to field obsid: img

  9. And select your recently digitized observation point. Notice how the custom edit form now is embedded in the attribute table. This is an easy access to all main information about all observation points. Select an observation point in the list to the left and get attribute information presented in the custom edit form.

  10. When ready, click the pen to stop editing.

Stratigraphy information

Import stratigraphy data

  1. Import stratigraphy information for observation points from the file stratigraphy.csv with encoding 'utf-8' using the General csv import Afterwards you may open the attribute table to see what data has been imported.

  2. Notice how the message bar will tell you how many stratigraphy layers were imported: img

  3. Redraw the map by the refresh button, or simply pan or zoom the map, and then you will see that you suddenly have data in the obs_p_w_strat layer: img obs_p_w_strat is a database view that shows all observation points with some stratigraphy info.

  4. Notice how the map layer obs_p_w_strat indicates that no stratigraphy information exists for PW1101 and PW1002. Select layer *stratigraphy *and open attribute table to verify this and get familiar with the imported data.

Plot Stratigraphy data

  1. Now it is time to get quick-access to stratigraphy info by the plotting function. Open the Midvatten Settings dialog (MidvattenMidvatten Settings, or F6) and select table stratigraphy in the Stratigraphy tab. Then select a few observation points in obs_p_w_strat and plot stratigraphy (Midvatten – View plot – Plot stratigraphy, or press F10: img Try to change color coding from Geo to Hydro. Also change the text. Open the attribute table for stratigraphy and compare to the plot.

  2. Try to activate obs_points layer and select a obs_point without stratigraphy and press F10 again. What happened? Why? Why is obs_p_w_strat useful?

Add single stratigraphy layer information

  1. Select layer stratigraphy

  2. Begin editing the layer (click on the pen)

  3. Open the attribute table

  4. Click the Add feature button which can be found at the top of the attribute table to add an editable row at the bottom of the attribute table: img

  5. Add information about your stratigraphy layer. Some constraints:

  • obsid must exist in table obs_points
  • stratid (integer) must not be empty or null
  • depth under gs... ...from and ...to (floating point numbers, database fields depthtop and depthbot) must not be empty or null.
  • depthbot must be greater than depthtop
  1. When ready, click OK and then save to database by clicking the save icon in the upper left corner (floppy icon second from the left) of attribute table window.

  2. Repeat steps 4-5 for each stratigraphy layer info to be added. Please note that saving to database between each layer makes this process safer since it will prevent duplicate layers for one observation point.

  3. Finish editing by clicking the pen symbol.

Water level measurements (manual)

Import Water level measurements

  1. Import some water level measurements to the database from the file w_levels.csv with encoding 'utf-8' using the General csv import Afterwards you may open the attribute table to see what data has been imported.

  2. Open attribute table for layer w_levels to see the imported data. Please note that the column level_masl and h_toc (i.e. measurement reference point, “top of casing”) is empty: img

Calculate Water level in meter above sea level

  1. Close attribute table, activate obs_points layer and activate the “Identify features tool” and click on any observation point. A pop-up dialog will show information about the observation point, e.g. TopOfCasing: img Thus there is information about the measurement reference point and we can use it to calculate the water level corresponding to our imported measurements.

  2. Activate the obs_points layer and select any of the observation points. Then select Midvatten – Edit data in database – Calculate w level from manual measurements: img When prompted, accept the full (default) date intervall and select to update the table w_levels for ALL objects. Open attribute table w_levels again to see the result of this operation. img

  3. Force a redraw of the map (use pan tool or zoom in and out once) and then you can see that two additional layers will be shown on map, w_lvls_last_geom and obs_p_w_lvl. Both are spatial views of data in the database. The first layer shows the latest water level measurement for each observation point. Use the info tool and point-and-click on any object in this layer to see date and result for the latest measurement.

  4. The layer obs_p_w_lvl will show all observation points for which there are any water level measurements, this is very useful if the database contains a lot of points but water level is only measured in a few of them.

Plot Water level

  1. To plot some water level measurements, start with selecting *Midvatten – Midvatten Settings *(or use toolbar button or function key F6) and select *Time series *tab. Select table *w_levels *and column level_masl. Activate “Dot markers on line”.

  2. Then activate layer obs_p_w_lvl and select one or a few objects. Then select Midvatten – View plot – Time Series plot or click the time series button in the Midvatten toolbar (or use function key F8) to get a zoomable and panable time series plot of water level measurements for the selected objects:
    img
    img

Add single water level measurement

  1. Select layer w_levels

  2. Begin editing the layer (click on the pen)

  3. Open the attribute table

  4. Click the plus sign (+) which can be found at the bottom of the attribute table to open an edit form: img

  5. Add information about your water level measurement. . There are some constraints:obsid must exist in table obs_pointsdate_time must be an acceptable format (yyyy-mm-dd, yyyy-mm-dd HH:MM or yyyy-mm-dd HH:MM:SS)also, each combination of obsid and date_time must be uniquelevel_masl must be a floating point number

  6. When ready, save to database by clicking the save icon in the upper left corner (floppy icon second from the left) of attribute table window.

  7. Repeat steps until ready and then stop editing by clicking the pen symbol.

Water level readings from logger

Import water level readings from logger

  1. Now activate layer *obs_points *and select PW1001. Then import automatic water level measurements from the file w_levels_logger.csv with encoding 'utf-8' using the General csv import.

  2. Now try to watch these data by plotting them in a time series, go to *Midvatten – Midvatten Settings *and select *Time Series *tab. Select w_levels_logger as the table (that is where your data was imported to) and head_cm as column. Also DESELECT “Dot markers on line” if that option was selected since earlier. Finally click OK to close settings and press “F8” (with *obs_points *activated and *PW1001 *selected) to invoke a time series plot of head_cm from the imported data: img

  3. Clearly you imported some data from the csv file. Try to go back to Midvatten Settings and change plot column to temp_degc and create new time series plots. Then do the same with column level_masl. (Function keys F6 and F8 very useful here!): img

  4. This plot does not make very much sense, it only shows default levels as -999 meters above sea level. We need to transform pressure above pressure sensor (recorded as head_cm) to level in meters above sea level. We are going to do this by a simple comparison to the manual measurements.

Calibrate water level readings from logger

(Not updated yet for version 1.4)

  1. Midvatten – Edit Data – Calibrate w level from logger and a calibration dialog will be shown. Choose PW1001 from the drop down list, then click "Update plot". The manual measurements now appear as blue dots: img

  2. Enter "0" in "Logger position, masl" and click calibrate. The calibrated values will appear as a green line but there will be >1000 m difference between the two lines.

  3. Fill in "Circle nodes for logger line" and then click "Calibrate by best fit" and the logger values will be adjusted to the manual measurements with the least difference between the two lines: img

Please note: You have now altered the database! Whenever you give a value for logger position and press calibrate, then the column level_masl will be recalculated in table w_levels_logger for the given date and time interval.

  1. The match is decent but could be adjusted for a better match. It seems to be a discontinuous data series and also that the logger position ha changed a couple of times. Zoom to the green dot representing 2011-06-13 17:00:00 and click on the button "Select to" and then click on the dot to change date. (Now that we already knew the date, we could have entered it manually also!). Click on "Calibrate by best fit" again. img

  2. The fit until 2011-06-15 00:00:00 is new good, but the rest of the fit is still not good. Zoom in and set "Select from" to 2011-08-30 08:20:00 and "Select to" to 2011-08-30 14:30:00. Click the button "Change to offset". This will make the calculations beging based on the calibrated logger line (green line) instead of the head_cm column and is very useful if a long period of discontinuous data has to be adjusted up or down. img

  3. Click on "Calibrate by selection in plot". Then click on the green node representing the date 2011-08-30 14:30:00. Then click on the button "Calibrate by selection in plot" again and click on the blue line below the selected dot to choose a y-position (clicking on the line is not necessary. It's the y-position of the click thats needed). Click on the button "Calibrate by selection in plot" again. Now the values inside the chosen time interval will be adjusted based on the difference between the chosen green node and the chosen y-position. img

  4. The rest of the logger values can be calibrated in the same way using the different tools available (Calibrate, Calibrate by best fit and Calibrate using selection in plot). (see "Usage - 4. Edit data - Calibrate water level measurements from data logger" for more information)

  5. Now it is time to have a look at the actual w_levels_logger table. This can be done in a number of ways, I highly recommend Spatialite-GUI, but for this tutorial we stick to qgis. Select Layer – Add Spatialite layer. Then connect to your database and (this is absolutely necessary) select “Also list tables with no geometry” and mark the table w_levels_logger and click “add”.

  6. Notice how w_levels_logger is added as a layer to your layer panel. Right-click this layer and open the attribute table. There you can examine the result of your calibration. The values in column level_masl are calculated from your given logger positions and the measured pressure in head_cm. When ready, remove this layer from qgis to save some memory.

Plot water level readings from logger

  1. Now, finally time to watch a plot of your calibrated water level readings, go to* Midvatten – Midvatten Settings* (or ”F6”) and select Time Series tab:Make sure you DEactivate ”Dot markers on line”.

  2. Activate layer obs_points and select the feature with logger data (in our case PW1001). Press “F8” (with *obs_points *activated and *PW1001 *selected) to invoke a time series plot of your calibrated water levels from logger readings: img

Water Quality

Import water quality data

  1. Next step is to import water quality data from w_qual_lab.csv and w_qual_field.csv with encoding 'utf-8' using the General csv import Notice how the layers (the spatial views) obs_p_w_qual_lab and obs_p_w_qual_field shows which observation points that has water quality data.

  2. You may open the two water quality tables to examine data (activate layer and open attribute table). As you can see, those data includes a date_time column and can therefore be plotted as Time series.

Plot time series of water quality - Custom plots

  1. To make time series plots for water quality, the tool "Custom plots" should be used. Choose Midvatten - View plot - Custom plot. Select w_qual_field in the Table drop-down list, date_time as x-axis and reading_num as y-axis. Choose parameter from Filter #1 drop-down list and select temp. Choose obsid from Filter #2 drop-down list and choose PW1001 and PW1002. Change Plot type drop-down list to line and marker Click "Plot chart": img

Generate water quality reports

  1. For examining water quality data there is also an option of generating simple html reports. First adjust Midvatten Settings W quality report tab according to screen dump below: img

  2. Then select any object (only one at a time) in obs_p_w_qual_lab and select *Midvatten – View Report – Water Quality Report (or ”F12”) *to generate the simple html report which opens in your default web browser: img Similar report may be generated for data in table w_qual_fr_field.

Water flow

Import water flow readings

  1. The last data import under point observations is water flow. First, have a quick look at the database design diagram shown under step "Load default database layers to your qgis project" above. Notice how there is a constraint on flowtype, any flowtype in table w_flow must exist in table zz_flowtype. Therefore, add the table zz_flowtype as a layer to qgis (see "Calibrate water level readings from logger" step 8. above) and look at the different default flow types. Now, use General csv import to import the file w_flow.csv with encoding 'utf-8'. Notice how any new flowtypes will be added to the zz_flowtype table but be aware, only default flow types correspondes to predefined views, see below.

  2. Open layer w_flow to examine the imported data. Notice how the three different flow types are used.

  3. In the database there are three predefined spatial views that shows subsets of the table w_flow, namely w_flow_momflow for Momentary water flow readings, w_flow_aveflow for average water flow and w_flow_accvol for accumulated water volume*.* Add these to qgis using the method described in "Calibrate water level readings from logger" step 8. above and have a look.

  4. Average flow (aveflow) can be calculated from accumulated volume (see "Usage - 4. Edit data - Calculate average flow from accumulated volume"). Calculate aveflow for the whole period.

Plot water flow data

  1. The predefined w_flow_... views are very useful when plotting time series of water flow data. As an example, activate obs_points layer and select PW1001. Open *Midvatten Settings *– *Time Series tab and try each one of the following settings and create a time series plots (F8): table: w_flow_aveflow, column: reading table: w_flow_momflow, column: reading table: w_flow_accvol, column: reading Even though these tutorial data are fictive it will hopefully illustrate how flowtypes can be used to visualise pumping rates and accumulated water volumes.

Add single water flow reading

  1. Select layer w_flow, begin editing (click on the pen) and open the attribute table.

  2. Click the "Switch to form view" button which can be found at the bottom of the attribute table to open an edit form: img Click the "Add feature" button to add a new row and select it (appears at the bottom of the table).

  3. Add information about your water flow reading. The tooltip shows additional information about the fields. The color coding indicates some of the constraints: obsid must exist in table obs_points instrumentid must not be null nor empty flowtype must be found in databse table zz_flowtype (for most cases it should be enough to use the standard values as shown by the tool tip) date_time must be an acceptable format (yyyy-mm-dd, yyyy-mm-dd HH:MM or yyyy-mm-dd HH:MM:SS)

  • reading* (floating point number) must not be empty or null unit must not be empty or null finally, each combination of obsid, instrumen id, flowtype and date_time must be unique.
  1. When ready, click OK and then save to database by clicking the save icon in the upper left corner (floppy icon second from the left) of attribute table window.

  2. Repeat steps 3, 4 until ready and then stop editing by clicking the pen symbol.

Generate a general obs point report

  1. Activate the layer obs_points and select one obs_point

  2. Select *Midvatten - View report - General Report *(or click the button on the toolbar or press ”F11”)

  3. The result is displayed in your default internet browser. The table can be highlighted, copied and pasted into Excel or Word: img

Metorological data (Point observation data)

Adding a meteorological station

  1. Just add an obs_point as in chapter "Add single point observations".

Import meteorological data

  1. Import some meteorological measurements to the database from the file meteo.csv with encoding 'utf-8' using the General csv import Afterwards you may open the attribute table to see what data has been imported. At the moment, the meteorological data is related to obs_points PW1102 and PW1002. In your case you probably have specific meteorological stations. But the import routine is the same of course.

Plotting of meteorological data

  1. Use the tool "Custom plot", see chapter "Plot time series of water quality - Custom plots"

  2. Select table ”meteo”, date_time as x-axis, reading_num as y-axis, parameter -> temp as Filter #1 and obsid as Filter #2. to obtain your plot: img

Line observations – (VLF and Seismics)

Import/add line observations

NOTE! Currenly, the tutorial file contains "" around the WKT-column. These must be removed.

  1. Now it is time to work with observations that are best represented along lines on a map. To begin with, import two observation lines from obs_lines_4326.csv with encoding 'utf-8' using General csv import. Afterwards you may open the attribute table to see what data has been imported. Pan or zoom the map to force a redraw and thus you will see the imported lines. NOTE 1! This example text file includes WKT geometries of type LINESTRING with SRID corresponding to the database (EPSG 4326). Any attempt to import observation lines from a text file without valid WKT geometries will fail. img

  2. Also try to create three (3) arbitrary observation lines (obs_lines) by yourself. Activate the layer obs_lines and then start editing (click the pen)

  3. Digitize three arbitrary lines and give them obsid S1, S2 and S3 in pop-up edit form (stop the current feature by right clicking the map):

  4. If you open attribute table and select the ”feature list” view then you will notice that the obsid fields for your new obsevation lines will be red until you save edits to database.

VLF Raw data

Import VLF data

  1. As you can see, the imported lines are named vlf01 and vlf02 indicating they correspond to some vlf measurements along profiles. Now it is time to import raw data from thes measurements. Import file vlf_data.csv with encoding 'utf-8' using the General csv import

Plot VLF data

  1. To plot VLF Data, go to *Midvatten – Midvatten Settings *(or use toolbar button or function key F6) and select *XYplot *tab. Select table vlf_data and columns length, real_comp and imag_comp according to the picture below: img

  2. Activate layer obs_lines and select any of the lines corresponding to vlf-profiles. Then select Midvatten – View plot – Scatter plot or click the scatter plot button in the Midvatten toolbar (or use function key F9) to get a zoomable and panable plot of raw data from vlf field measurements for the selected vlf profile: img

Interpretations from seismic investigations

Import interpreted data from seismic investigations

  1. Import file seismic_data_v102.csv with encoding 'utf-8' using the General csv import.

Plot seismic data

  1. To plot interpreted data from seismic investigations, go to *Midvatten – Midvatten Settings *(or use toolbar button or function key F6) and select *XYplot *tab. Select table seismic_data and columns length, ground and bedrock.

  2. Activate layer obs_lines and select any of the lines corresponding to vlf-profiles (the user created S1, S2 or S3). Then select Midvatten – View plot – Scatter plot or click the scatter plot button in the Midvatten toolbar (or use function key F9) to get a zoomable and panable plot of interpreted seismic data: img

Settings and database maintenance

Reset Settings

The plugin stores information about database, tables and columns in the QGIS project file.

This may cause the plugin to crash if e.g. the database has been moved.

Therefore an option to reset the settings is included in the plugin.

The reset settings is found under the plugin meny (no toolbar icon).

Common tasks associated to Function Keys

A few common tasks are associated to function keys F6-F12, namely:

F6 - Midvatten Settings

F7 - Load Default Layers

F8 - Plot Time Series

F9 - Plot XY Scatter

F10 - Plot Stratigraphy

F11 - Show General Report

F12 - Show Water Quality Report

Make a backup of the database

It is highly recommended that you backup your database file regularly. A compressed backup of the database can be done using Midvatten - Database management - Backup the database. This can also be done using file explorer and creating (compressed) copies of the database file, name them with date and time, place in subfolder archive.

Vacuuming the database

If you for some reason have deleted big amounts of data from the database it is recommended to perform av vacuum of the database to reduce size on disk. Vacuuming can be done using Midvatten - Database management - Backup the database. (or use spatialite-gui or other sqlite manager to vacuum the database. Vacuuming is also silently performed after each one of the import functions described above since these import functions keeps temporary data in the database which is deleted afterwards - hence causing a possible need for vacuuming.)

Create professional time series plots

If you want to create professional time series plots directly from the data in your Midvatten database and the Custom plot-tool is not enough, then please try the tool “plotsqlite”. Download from here : plotsqlite.googlecode.com

References

https://sites.google.com/site/midvattenpluginforqgis/

https://code.google.com/p/midvatten-plugin-for-qgis/

http://plugins.qgis.org/plugins/midvatten/

http://plotsqlite.googlecode.com/

http://hydrogeotools.blogspot.com/

http://www.qgis.org/

http://www.gaia-gis.it/gaia-sins/

Clone this wiki locally