.

QGIS ca și Server de Date OGC

QGIS Server is an open source WMS 1.3, WFS 1.0.0 and WCS 1 1.1.1 implementation that, in addition, implements advanced cartographic features for thematic mapping. The QGIS Server is a FastCGI/CGI (Common Gateway Interface) application written in C++ that works together with a web server (e.g., Apache, Lighttpd). It has Python plugin support allowing for fast and efficient development and deployment of new features. It is funded by the EU projects Orchestra, Sany and the city of Uster in Switzerland.

QGIS Server uses QGIS as back end for the GIS logic and for map rendering. Furthermore, the Qt library is used for graphics and for platform-independent C++ programming. In contrast to other WMS software, the QGIS Server uses cartographic rules as a configuration language, both for the server configuration and for the user-defined cartographic rules.

Atât timp cât QGIS desktop și QGIS Server folosesc aceleași biblioteci de vizualizare, hărțile care sunt publicate pe web arătând la fel ca și în GIS desktop.

In one of the following manuals, we will provide a sample configuration to set up a QGIS Server. For now, we recommend to read one of the following URLs to get more information:

Exemplu de instalare pe Debian Squeeze

At this point, we will give a short and simple sample installation how-to for a minimal working configuration using Apache2 on Debian Squeeze. Many other OSs provide packages for QGIS Server, too. If you have to build it all from source, please refer to the URLs above.

În primul rând, se adaugă următorul depozit GIS pentru debian astfel:

$ cat /etc/apt/sources.list.d/debian-gis.list
deb http://qgis.org/debian trusty main
deb-src http://qgis.org/debian trusty main

$ # Add keys
$ sudo gpg --recv-key DD45F6C3
$ sudo gpg --export --armor DD45F6C3 | sudo apt-key add -

$ # Update package list
$ sudo apt-get update && sudo apt-get upgrade

Acum, instalați QGIS-Server:

$ sudo apt-get install qgis-server python-qgis

Installation of a HelloWorld example plugin for testing the servers. You create a directory to hold server plugins. This will be specified in the virtual host configuration and passed on to the server through an environment variable:

$ sudo mkdir -p /opt/qgis-server/plugins
$ cd /opt/qgis-server/plugins
$ sudo wget https://github.com/elpaso/qgis-helloserver/archive/master.zip
$ # In case unzip was not installed before:
$ sudo apt-get install unzip
$ sudo unzip master.zip
$ sudo mv qgis-helloserver-master HelloServer

Instalați serverul Apache într-o gazdă virtuală separată, care monitorizează portul 80. Activați modulul de rescriere pentru a permite autentificarea antetelor HTTP BASIC:

$ sudo a2enmod rewrite
$ cat /etc/apache2/conf-available/qgis-server-port.conf
Listen 80
$ sudo a2enconf qgis-server-port

Aceasta este configurația gazdei virtuale, stocate în /etc/apache2/sites-available/001-qgis-server.conf :

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/html

  ErrorLog ${APACHE_LOG_DIR}/qgis-server-error.log
  CustomLog ${APACHE_LOG_DIR}/qgis-server-access.log combined

  # Longer timeout for WPS... default = 40
  FcgidIOTimeout 120
  FcgidInitialEnv LC_ALL "en_US.UTF-8"
  FcgidInitialEnv PYTHONIOENCODING UTF-8
  FcgidInitialEnv LANG "en_US.UTF-8"
  FcgidInitialEnv QGIS_DEBUG 1
  FcgidInitialEnv QGIS_SERVER_LOG_FILE /tmp/qgis-000.log
  FcgidInitialEnv QGIS_SERVER_LOG_LEVEL 0
  FcgidInitialEnv QGIS_PLUGINPATH "/opt/qgis-server/plugins"

  # ABP: needed for QGIS HelloServer plugin HTTP BASIC auth
  <IfModule mod_fcgid.c>
      RewriteEngine on
      RewriteCond %{HTTP:Authorization} .
      RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  </IfModule>

  ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  <Directory "/usr/lib/cgi-bin">
      AllowOverride All
      Options +ExecCGI -MultiViews +FollowSymLinks
      # for apache2 > 2.4
      Require all granted
      #Allow from all
  </Directory>
 </VirtualHost>

Acum activați gazda virtuală și reporniți Apache:

$ sudo a2ensite 001-qgis-server
$ sudo service apache2 restart

Testați serverul cu plugin-ul HelloWorld:

$ wget -q -O - "http://localhost/cgi-bin/qgis_mapserv.fcgi?SERVICE=HELLO"
HelloServer!

Puteți arunca o privire la comanda GetCpabilities a serverului QGIS la: http://localhost/cgi-bin/qgis_mapserv.fcgi?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities

Tip

Dacă lucrați cu o funcție care are multe noduri, atunci modificarea și adăugarea unui nou element va eșua. În acest caz, este posibil să se introducă următorul cod în fișierul 001-qgis-server.conf:

<IfModule mod_fcgid.c>
FcgidMaxRequestLen 26214400
FcgidConnectTimeout 60
</IfModule>

Crearea unui WMS/WFS/WCS dintr-un proiect QGIS

Pentru a crea un nou Server WMS, WFS or sau WCS QGIS, trebuie să creăm un fișier de proiect QGIS, în care să existe câteva date. În continuare, vom folosi fișierul shape ‘Alaska’, al setului de date eșantion din QGIS. În QGIS definiți culorile și stilurile straturilor, precum și CRS-ul proiectului, dacă nu ați făcut deja acest lucru.

Figure Server 2:

../../../_images/ows_server_definition.png

Definițiile unui proiect de Server WMS/WFS/WCS QGIS (KDE)

Then, go to the OWS Server menu of the Project ‣ Project Properties dialog and provide some information about the OWS in the fields under Service Capabilities. This will appear in the GetCapabilities response of the WMS, WFS or WCS. If you don’t check checkbox Service capabilities, QGIS Server will use the information given in the wms_metadata.xml file located in the cgi-bin folder.

Capabilităţi WMS

In the WMS capabilities section, you can define the extent advertised in the WMS GetCapabilities response by entering the minimum and maximum X and Y values in the fields under Advertised extent. Clicking Use Current Canvas Extent sets these values to the extent currently displayed in the QGIS map canvas. By checking checkbox CRS restrictions, you can restrict in which coordinate reference systems (CRS) QGIS Server will offer to render maps. Use the mActionSignPlus button below to select those CRS from the Coordinate Reference System Selector, or click Used to add the CRS used in the QGIS project to the list.

If you have print composers defined in your project, they will be listed in the GetCapabilities response, and they can be used by the GetPrint request to create prints, using one of the print composer layouts as a template. This is a QGIS-specific extension to the WMS 1.3.0 specification. If you want to exclude any print composer from being published by the WMS, check checkbox Exclude composers and click the mActionSignPlus button below. Then, select a print composer from the Select print composer dialog in order to add it to the excluded composers list.

If you want to exclude any layer or layer group from being published by the WMS, check checkbox Exclude Layers and click the mActionSignPlus button below. This opens the Select restricted layers and groups dialog, which allows you to choose the layers and groups that you don’t want to be published. Use the Shift or Ctrl key if you want to select multiple entries at once.

Puteți primi rezultatul solicitării GetFeatureInfo sub formă de text simplu, XML și GML. XML este implicit, textul sau formatul GML depinzând de formatul de ieșire ales pentru cererea GetFeatureInfo.

If you wish, you can check checkbox Add geometry to feature response. This will include in the GetFeatureInfo response the geometries of the features in a text format. If you want QGIS Server to advertise specific request URLs in the WMS GetCapabilities response, enter the corresponding URL in the Advertised URL field. Furthermore, you can restrict the maximum size of the maps returned by the GetMap request by entering the maximum width and height into the respective fields under Maximums for GetMap request.

If one of your layers uses the Map Tip display (i.e. to show text using expressions) this will be listed inside the GetFeatureInfo output. If the layer uses a Value Map for one of his attributes, also this information will be shown in the GetFeatureInfo output.

QGIS support the following request for WMS service:

  • GetCapabilities
  • GetMap
  • GetFeatureInfo
  • GetLegendGraphic (profilul SLD)

  • DescribeLayer (profilul SLD)

  • GetStyles (profilul QGIS personalizat)

Capabilități WFS

In the WFS capabilities area, you can select the layers that you want to publish as WFS, and specify if they will allow the update, insert and delete operations. If you enter a URL in the Advertised URL field of the WFS capabilities section, QGIS Server will advertise this specific URL in the WFS GetCapabilities response.

QGIS support the following request for WFS service:

  • GetCapabilities
  • DescribeFeatureType
  • GetFeature
  • Transaction

Capabilități WCS

In the WCS capabilities area, you can select the layers that you want to publish as WCS. If you enter a URL in the Advertised URL field of the WCS capabilities section, QGIS Server will advertise this specific URL in the WCS GetCapabilities response.

Now, save the session in a project file alaska.qgs. To provide the project as a WMS/WFS, we create a new folder /usr/lib/cgi-bin/project with admin privileges and add the project file alaska.qgs and a copy of the qgis_mapserv.fcgi file - that’s all.

Acum vom testa proiectul nostru WMS, WFS și WCS. Adăugați în QGIS WMS, WFS și WCS așa cum este descris în Încărcarea Straturilor WMS/WMTS, Client WFS și WFS-T și Client WCS, apoi încărcați datele. URL-ul este:

http://localhost/cgi-bin/project/qgis_mapserv.fcgi

QGIS support the following request for WCS service:

  • GetCapabilities
  • DescribeCoverage
  • GetCoverage

Reglarea fină a OWS-ului dvs.

For vector layers, the Fields menu of the Layer ‣ Properties dialog allows you to define for each attribute if it will be published or not. By default, all the attributes are published by your WMS and WFS. If you want a specific attribute not to be published, uncheck the corresponding checkbox in the WMS or WFS column.

You can overlay watermarks over the maps produced by your WMS by adding text annotations or SVG annotations to the project file. See section Annotation Tools in Instrumente generale for instructions on creating annotations. For annotations to be displayed as watermarks on the WMS output, the Fixed map position check box in the Annotation text dialog must be unchecked. This can be accessed by double clicking the annotation while one of the annotation tools is active. For SVG annotations, you will need either to set the project to save absolute paths (in the General menu of the Project ‣ Project Properties dialog) or to manually modify the path to the SVG image in a way that it represents a valid relative path.

Parametri suplimentari acceptați de cererea WMS GetMap

În cererea WMS GetMap, Serverul QGIS acceptă un cuplu de parametri suplimentari, în plus față de parametrii standard, în conformitate cu specificațiile OCG WMS 1.3.0:

  • MAP parameter: Similar to MapServer, the MAP parameter can be used to specify the path to the QGIS project file. You can specify an absolute path or a path relative to the location of the server executable (qgis_mapserv.fcgi). If not specified, QGIS Server searches for .qgs files in the directory where the server executable is located.

    Exemplu:

    http://localhost/cgi-bin/qgis_mapserv.fcgi?\
      REQUEST=GetMap&MAP=/home/qgis/mymap.qgs&...
  • Parametrul DPI: parametrul DPI poate fi folosit pentru a specifica rezoluția de ieșire solicitată.

    Exemplu:

    http://localhost/cgi-bin/qgis_mapserv.fcgi?REQUEST=GetMap&DPI=300&...
  • OPACITIES parameter: Opacity can be set on layer or group level. Allowed values range from 0 (fully transparent) to 255 (fully opaque).

    Exemplu:

    http://localhost/cgi-bin/qgis_mapserv.fcgi?\
      REQUEST=GetMap&LAYERS=mylayer1,mylayer2&OPACITIES=125,200&...

Jurnalizare Server QGIS

Pentru a jurnaliza cererile transmise serverului, setați următoarele variabile de mediu:

  • QGIS_SERVER_LOG_FILE: Specificați calea și numele fișierului. Asigurați-vă că serverul are permisiuni adecvate pentru a scrie în fișier. Fișierul ar trebui să fie creat automat, doar trimiteți niște cereri la server. Dacă nu se află acolo, atunci verificați permisiunile.

  • QGIS_SERVER_LOG_LEVEL: Precizați nivelul de jurnalizare dorit. Valorile disponibile sunt:

    • 0 INFO (se jurnalizează toate cererile),

    • 1 AVERTISMENT,

    • 2 CRITIC (se jurnalizează doar erorile critice, adecvat în scop de producție).

    Exemplu:

    SetEnv QGIS_SERVER_LOG_FILE /var/tmp/qgislog.txt
    SetEnv QGIS_SERVER_LOG_LEVEL 0

Notă

  • Când utilizați modulul Fcgid, folosiți FcgidInitialEnv în loc de SetEnv!

  • Jurnalizarea Serverului este activată, de asemenea, în cazul în care executabilul este compilat în modul de lansare ca versiune nouă.

Variabile de mediu

  • QGIS_OPTIONS_PATH: The variable specifies path to directory with settings. It works the same ways as QGIS application –optionspath option. It is looking for settings file in <QGIS_OPTIONS_PATH>/QGIS/QGIS2.ini. For exaple, to set QGIS server on Apache to use /path/to/config/QGIS/QGIS2.ini settings file, add to Apache config:

    SetEnv QGIS_OPTIONS_PATH "/path/to/config/"