Awesome
Guide connection for Apache Marmotta and QGIS
This is just a public guide that shows how to stablish a connection between Apache Marmotta and QGIS. This process can be applied for any triple store that has an SPARQL endpoint enabled.
For this process, we used the plugin SPARQLing unicorn. The description process is shown below.
Plugin installation
- Download the plugin “SPARQLing Unicorn QGIS Plugin” in ZIP form from this link.
- Open Qgis and go to the "Add-ons" tab and click on "Manage and install add-ons".
- Then a window will open containing 5 options. Click on "Install from ZIP".
- Click on the 3 dots [...] and the file explorer will open.
- We look for and select the plugin that we previously downloaded.
- Wait and the plugin will be installed in our QGis.
Setup connection
To establish connection between QGIS and Apache Marmotta we will do the following
- In QGis, look in the task bar for the “Vector” tab, place the cursor on “SPARQLing Unicorn QGIS Plugin” and click on “Adds GeoJSON layer from a Wikidata”.
- A new window will open, look for and click on “Configure TripleStores” located on the right side of the window.
- Another window will open and we will verify that the "File" option is selected in the "Choose Triple Store" section.
- In the field "Triple Store Name" we enter the name with which we will identify our triple store within Qgis. In our case it is Apache Marmotta.
- In the "Triple Store URL" field we will enter the URL of the SPARQL endpoint where we want to connect. In the case of Apache Marmotta it is the following URL http: // ip6-localhost: 8080 / marmotta / sparql / select
- We click on the option "Test Connection." If everything has gone well, we will get a dialog box that tells us that the URL entered corresponds to a valid SPARQL endpoint as shown in the following image.
- Then we will click on the option "Detect Configuration" to load the geospatial metadata of the endpoint. A message will appear that will tell us that it found valid information and that if we want to add said SPARQL endpoint to QGis. We will say yes and wait for it to finish to register the endpoint in QGis.
- We click on “Apply” and close the window
- If everything went well, we return to the first window, we click on the "Select endpoint" dropdown and our endpoint will be displayed there with the name that has been saved. In our case it was saved as "Apache Marmotta". After having selected our endpoint, we will be ready to execute our queries in the text box below the options.
Example
To know how to execute and load data to QGIS, we'll show you how to do it with an example.
Execute the SPARQL query shown below.
- We open QGIS
- Click on task bar -> Vector -> SPARQL Unicorn Wikidata Plugin -> Adds GeoJSON layer from a Wikidata.
- In the new window, click on the “Select endpoint” section and select “Apache Marmotta”.
- We insert the above query in the "Valid Query" text box. It should look something similar to the following image.
- Since the query contains 2 variables associated with the geometries,? GeoProv and? GeoPlace, as well as 2 variables with information associated with each variable,? TitleProv and? TitlePlace respectively, the plugin must be adjusted so that it reads properly each each geometry and its name since the plugin requires 2 input parameters: the name of the variable with geometry information and the variable that contains the geometry in WKT format. For each tuple it is necessary to adjust the plugin and execute the query again since each execution implies a new layer to be imported in QGIS (Layer). In this case the tuples are as follows.
# Execution | Geometry variable | Item variable |
---|---|---|
1 | GeoProv | titleProv |
2 | geoPlace | titlePlace |
- Click on "Configure TripleStore"
- Select the appropriate triple store, which in this case is Apache Marmotta.
- Modify the main SELECT by using variable aliases.
- Since the plugin does not allow changing the name of the variables that it will read, “geo” and “item”, we will change the main SELECT variable like this: “? GeoProv” by “(? GeoProv as? Geo)” and “? TitleProv "By" (? TitleProv as? Item) ". In this way we will no longer change the name of our variable in each part that appears in our query. It should look similar to the following image.
- Then we click on the "add layer" button. The query will be executed and if everything went well, a new layer will be added to QGIS.
- Subsequently, you must do the same for the second variable, “? GeoPla” for “(? GeoPlace as? Geo)” and “? TitlePlace” for “(? TitlePlace as? Item)”, and we will have the 2 layers ready added in our QGIS.
Results
The geometries of the provinces are loaded in a single layer.
The museum geometries from the 2nd SPARQL endpoint are loaded as a second layer in QGIS.