---
title: "QGIS Create layers with mxMDS plugin"
canonical: "https://servicedesk.maxgeo.com/space/MDS/1466990594/QGIS%20Create%20layers%20with%20mxMDS%20plugin"
format: markdown
---
> ⚠️ This feature is current still under development and in not available at this time

QGIS

When your DataShed SQL backend is located on your own company servers and you have the appropriate permission levels, then it’s simple to connect QGIS to the SQL backend using the standard QGIS MS SQL Server connection tool.

However, when your database is in the maxgeo cloud environment, either client managed or maxgeo managed, you will need to make use of the mxMDS plugin developed by maxgeo to retrieve data and create the required vector and table layers.

You will need the following from maxgeo:

- The plugin software zip file
- The MDS API address
- API Key

# Installation

The plugin is installed from a zip file provided by maxgeo.

- Save the zip file to your local hard drive or OneDrive.
- Launch QGIS.
- On the top menu bar, select Plugins > Manage and Install Plugins.
- In the Plugins window, select **Install from ZIP** on the left menu tree.
- Click on the 3 dots next to the ZIP file box and navigate to the location where you saved the zip file.
- Select the zip file.
- Click the Install Plugin button.
- You should receive a message in green at the top of the window that the plugin has been installed successfully.

![image](media://3417d589-68df-4763-ac30-200f9bb68317)

A new button should be displayed on the Plugins toolbar at the top of your QGIS application.

![image](media://699ad0d1-8213-48f9-ab41-1bf9d9f8d896)

# Creating a vector layer

Note that if you hover your cursor over any of the white boxes on the interface, relevant help text will be displayed.

![image](media://7d50fc03-ec51-4d05-a8e9-7e23e1b1e234)

- **MDS API:** Copy and paste the API URI provided by maxgeo into this box.
- **API Key:** Copy and paste the API Key provided by maxgeo into the second box.
- These 2 steps should only be necessary the first time you use the plugin and after that, the plugin should remember the URL and the key. Note that the key will never be displayed, and you will only ever see the ***** mask.
- **Layer Name:** Type a suitable name as it will appear in the QGIS Layers panel.
- **EPSG Column:** This is used when the source table in the MDS contains data using various different coordinate reference systems (CRS) which are defined in a specific column such as the AuthorityCode column in tblVWDHCoordinates in MDS-5. Type the name of this column exactly as it appears in the MDS. If there is only a single input CRS, then you can leave this blank and the EPSG Code below will be assumed to be the input CRS as well.
- **East/Long Column:** Type the name of the column containing the Longitude or Easting value.
- **North/Lat Column:** Type the name of the column containing the Latitude or Northing value.
- **EPSG Code:** Type the EPSG code value of the destination CRS in which you want the layer to be created.
- **Save Data to:** Navigate to a folder in which the QGIS objects will be created. It is recommended that you keep the objects in the same folder as the Project file but this is not necessary.
- **SQL Query:** Define a query that will retrieve the data to be used to create the layer. It is strongly recommended that you write this query in SQL Server Management Studio (SSMS) first and ensure that the syntax is correct before copying and pasting the string into this window.

<span style="color: #ff0000">**DO NOT USE Select * syntax or include any geometry columns in this query.**</span>

- Click the **Create Layer** button. The layer will be displayed in the QGIS Layers panel and a .gpkg file with the same name will be created in the folder specified in the **Save Data to** box.
- By clicking on the **Download Data** button, the source data can be saved as a .csv file.

Example SQL query to create a collar layer using the Long/Lat coordinates:

Select DataSet, Hole_ID, Hole_Type, LL_Long, LL_Lat, LL_RL

From tblDHColl

WHERE DataSet = 'BOTSWANA'

# Creating a tabular layer

It is also necessary to import MDS tables which do not contain any coordinates columns such as Downhole Survey, Downhole Lithology and Downhole Assays data for use in third party plugins such the Geoscience tool which allows downhole visualization of drilling data.

While the first two datasets are contained in database tables, the assays are contained in a View, but both are supported by the plugin.

- tblDHSurv
- tblDHLithology
- tblVWDHAssays

In this case it is necessary to create the collar layer using Projected coordinates rather than Long/Lat coordinate because downhole visualization plugins need meter-based coordinates rather than degrees.

Example SQL query to create a collar layer using projected coordinates:

Select DataSet, Hole_ID, Max_Depth, Hole_Type, '32735' as EPSG_Code, ORIG_East, ORIG_North, ORIG_RL

From tblDHColl

WHERE DataSet = 'BOTSWANA'

In this case, the ORIG coordinates are in the **UTM WGS84 Zone 35 South** system and the corresponding EPSG code is 32735.

This will create a vector collar layer in the QGIS project.

To then add tabular data, the mxMDS plugin is launched again but much less information is required to create the layers.

![image](media://ef718e11-32f8-43e6-a2a5-094bcac2ef8a)

Only the first three boxes and Save Data to: and SQL Query boxes are required to be completed for tabular layers.

The process can be repeated to create as many tables as necessary to do the required downhole visualization.

# Refreshing a layer

The data from which a layer was created via the API plugin is not automatically refreshed once the QGIS project file is re-opened.

<span style="color: #ff0000">**NOTE:**</span> The created .gpkg files that are created when Create Layer is clicked have to be in the same location on the disc where the QGIS project that contains them is saved or else the Refresh will not work.

- Open the QGIS project file that contains the layers created via the API.
- In the Layers pane of QGIS, select the layer.
- Launch the mxMDS plugin.
- The SQL query definition and other settings that were used to create the layer will be automatically retrieved.
- Click the **Create Layer** button. You will receive an error message.
- Click the **Create Layer** button again. The data is refreshed and any new records added to the MDS source table will be displayed as new points.
- Repeat this process for each API derived layer in the project file.
- The styling of the target layer is lost when refreshed so it’s recommended that you save the styling of the layer as a .qml file which can be reapplied after the refresh. To do this you right-click on the layer name in the Layers window > Export >Save as QGIS Layer Style File. Then after refreshing you can reapply it by going to Layer Properties > Symbology > Style button (bottom left) and choose Load Style.

Note that if any de-surveyed collar or other layers have been created using third party downhole visualization plugins such as Geoscience plugin, they are not automatically refreshed and need to be re-created using the new data.