Salta el contingut

Create WMS Service (QGIS Project)

The Geoportal administrator allows creating a WMS directly from a QGIS project. To do this, follow these steps:

  1. Open QGIS v3 and load the data you want to represent in the WMS.
  2. Symbolize the data correctly according to the QGIS engine.
  3. Add as many layers as needed. Each QGIS layer will be a layer in the WMS. We can only add layers from a connection to a database and only if we have saved the password in the project file.
  4. Save the QGIS project on your computer (with extension *.qgs).
  5. From the Geoportal administrator, go to Home › QGIS Project Manager › Services.
  6. Add a new service from the top-right button.
  7. Configure the general options of the layer: Layer Properties.
  8. Load the created QGIS project from the Project File option.
  9. Create the new layer from the bottom-right button: Save.

Information

The Geoportal only supports the QGIS project format .qgs and not the compressed version .qgz.

Screenshot

Example QGIS Project

WMS GetFeatureInfo habilitat

To make the WMS service interactive, or in other words, to show a Popup with the layer information the option WMS GetFeatureInfo habilitado has to be enabled.

If you wish to highlight the selected geometry when you click it, QGis project needs to return it. In order to do so, go to the QGis Server menu of the Project > Properties, then go to the WMS tab and enable Add geometry to object response.

Screenshot

Geoportal Popup

If the service is consumed from the Mapia Geoportal, we can configure the Popup of the fields of each layer using HTML code similarly to the case of GeoJSON layers.

A QGIS project allows loading multiple layers at once, and it will be necessary to define a “code” that mixes HTML and JavaScript.

Information

HTML is written normally, the executable JavaScript part is written by delimiting it with “<%” and “%>”, and the JavaScript part that retrieves values ​​is written by delimiting it with “<%-” and “%>”.

Below is an example of how to configure the Popup:

<% layer_name.forEach(item => { %>
<div class="item">
    Id: <%- item.field1 %>
    LIC Code: <%- item.field2 %>
</div>
<% }) %>

Configuraciones específicas

  • Si deseamos que el Geoportal no muestre el popup al hacer clic o solo mostrar algunos campos determinados, es necesario configurar las opciones WMS desde las capas del propio QGIS.

Captura de pantalla

  • Los WMS de QGIS se pintan en forma de teselas (tiles) por defecto. Si algunas etiquetas aparecen cortadas, podemos modificar el tamaño del buffer por defecto activando la opción buffer activo y estableciendo el Tamaño del buffer a 128, 128 o 256, 256.
  • Podemos mejorar la calidad resultante modificando el tamaño de las teselas a 512, 512.
  • Podemos modificar los nombres de los campos que aparecerán en el popup creando un alias en la edición del formulario predeterminado en la capa de QGIS.
  • Si accedemos a las propiedades principales del proyecto de QGIS (menú Project > Properties), en la pestaña QGIS Server podemos configurar la información que se mostrará conjuntamente con el servicio WMS:
    • Información del proveedor.
    • Permisos.
    • Sistemas de coordenadas aceptados.

Captura de pantalla

Specific Configurations

  • If we want the Geoportal not to display the popup on click or only show specific fields, it is necessary to configure the WMS options from the layers in QGIS.

Screenshot

  • QGIS WMS layers are displayed as tiles by default. If some labels appear cut off, we can modify the size of the default buffer by activating the Active buffer option and setting the Buffer size to 128, 128, or 256, 256.
  • We can improve the resulting quality by modifying the tile size to 512, 512.
  • We can change the names of the fields that will appear in the popup by creating an alias in the default form edit of the QGIS layer.
  • If we access the main properties of the QGIS project (menu Project > Properties), in the QGIS Server tab, we can configure the information that will be displayed along with the WMS service:
    • Provider information.
    • Permissions.
    • Accepted coordinate systems.

Screenshot

Project Resources

If the QGIS project we want to load has external resources such as icons, layers in SHP, geopackage, etc., we can load the project compressed in a ZIP file.

The QGIS project file does not store the loaded data in the file itself. When a project is opened, QGIS looks for the linked layer, reads the data, and loads it into the application. Therefore, if our project does not get data from a database, we also need to load these external files into Mapia SERVER. To do this, it is necessary to compress the QGIS project file and the linked data into a ZIP file.

Screenshot

IMPORTANT!: The name of the QGIS project file, the name of the Mapia SERVER layer, and the name of the compressed folder ZIP must be the same (Layer name = project name.qgs = compressed folder name.zip).

Screenshot

Information

To load external resources, it is necessary to set up the QGIS project with layers using relative paths, i.e., the parent element must be the project itself, and the linked resources should be in the same folder or subfolders of the folder where we have the QGIS project.

Service URL

Once the service is created, we can obtain the URL directly from the list of services: Home › Raster Layer Manager › Services


Screenshot

Service Test

We can check that the service is running correctly from the “view map” option once in the service edit form.


Screenshot