QGIS Server Installation on Windows
1. Install QGIS Server
- Download OSGeo4W
- Run OSGeo4W with Advanced Install option
- Search and choose qgis-server to install
- Install Apache as Web Server for QGIS Server: Download the XAMPP installer for Windows and install Apache
- Configure Apache to run QGIS Server:
- Edit the httpd.conf file (C:\xampp\apache\httpd.conf) and make the following changes:
From:
ScriptAlias /cgi-bin/ "C:/xampp/cgi-bin/"
To:
ScriptAlias /cgi-bin/ "c:/OSGeo4W64/apps/qgis/bin/"
From:
<Directory "C:/xampp/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
To:
<Directory "c:/OSGeo4W64/apps/qgis/bin">
SetHandler cgi-script
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
Require all granted
</Directory>
From:
AddHandler cgi-script .cgi .pl .asp
To:
AddHandler cgi-script .cgi .pl .asp .exe
Then at the bottom of httpd.conf, add:
SetEnv GDAL_DATA "C:\OSGeo4W64\share\gdal"
SetEnv QGIS_AUTH_DB_DIR_PATH "C:\OSGeo4W64\apps\qgis\resources"
SetEnv PYTHONHOME "C:\OSGeo4W64\apps\Python37"
SetEnv PATH "C:\OSGeo4W64\bin;C:\OSGeo4W64\apps\qgis\bin;C:\OSGeo4W64\apps\Qt5\bin;C:\WINDOWS\system32;C:\WINDOWS; C:\WINDOWS\System32\Wbem"
SetEnv QGIS_PREFIX_PATH "C:\OSGeo4W64\apps\qgis"
SetEnv QT_PLUGIN_PATH "C:\OSGeo4W64\apps\qgis\qtplugins;C:\OSGeo4W64\apps\Qt5\plugins"
- Restart Apache web server from the XAMPP Control Panel
- Open Web browser to testing a GetCapabilities request to QGIS Server:
http://localhost/cgi-bin/qgis_mapserv.fcgi.exe?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities
2. Publish maps to QGIS Server from a QGIS Project
- Download demo data, unzip the files in the qgis-server-tutorial-data
- Open world.qgs or (world3.qgs) and Save as Project to QGIS bin folder (C:\OSGeo4W64\apps\qgis\bin)
- There are 4 layers in the world.qgs project:
airports
places
countries
countries_shapeburst
- Configure WMS, WMTS and WFS: menu Project –> Properties –> QGIS Server:
3. Test QGIS Server:
WMS
GetCapabilities:
http://localhost/cgi-bin/qgis_mapserv.fcgi.exe?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities&map=world.qgs
GetPorjectSetting
http://localhost/cgi-bin/qgis_mapserv.fcgi.exe?MAP=world.qgs&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetProjectSettings
GetMap
http://localhost/cgi-bin/qgis_mapserv.fcgi.exe?MAP=world.qgs&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX=10208324, 949379, 13572097, 2661355&SRS=EPSG:3857&WIDTH=665&HEIGHT=551&LAYERS=countries&FORMAT=image/jpeg
Filter and Opacity
http://localhost/cgi-bin/qgis_mapserv.fcgi.exe?MAP=world.qgs&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX=-432786,4372992,3358959,7513746&SRS=EPSG:3857&WIDTH=665&HEIGHT=551&FORMAT=image/jpeg&LAYERS=countries,countries_shapeburst&STYLES=classified_by_name,blue&OPACITIES=255,30&FILTER=”countries:\”name\” IN ('Germany','Italy')”
Use Redlining
http://localhost/cgi-bin/qgis_mapserv.fcgi.exe?MAP=world.qgs&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX=-432786,4372992,3358959,7513746&SRS=EPSG:3857&WIDTH=665&HEIGHT=551&LAYERS=countries,countries_shapeburst&FORMAT=image/jpeg&HIGHLIGHT_GEOM=POLYGON((590000 6900000, 590000 7363000, 2500000 7363000, 2500000 6900000, 590000 6900000))&HIGHLIGHT_SYMBOL=<StyledLayerDescriptor><UserStyle><Name>Highlight</Name><FeatureTypeStyle><Rule><Name>Symbol</Name><LineSymbolizer><Stroke><SvgParameter ame="stroke">%233a093a</SvgParameter><SvgParameter name="stroke-opacity">1</SvgParameter><SvgParameter name="stroke-width">1.6</SvgParameter></Stroke></LineSymbolizer></Rule></FeatureTypeStyle></UserStyle></StyledLayerDescriptor>&HIGHLIGHT_LABELSTRING=QGIS Tutorial&HIGHLIGHT_LABELSIZE=30&HIGHLIGHT_LABELCOLOR=%23000000&HIGHLIGHT_LABELBUFFERCOLOR=%23FFFFFF&HIGHLIGHT_LABELBUFFERSIZE=3&SELECTION=countries:171,65
GetPrint
http://localhost/cgi-bin/qgis_mapserv.fcgi.exe?map=world.qgs&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetPrint&FORMAT=pdf&TRANSPARENT=true&SRS=EPSG:3857&DPI=300&TEMPLATE=Population distribution&map0:extent=-2786,4372992,3358959,7513746&LAYERS=countries
WFS GetFeature
http://localhost/cgi-bin/qgis_mapserv.fcgi.exe?SERVICE=WFS&VERSION=1.1.0&REQUEST=GetFeature&TYPENAME=countries&map=world.qgs
WMTS:
http://localhost/cgi-bin/qgis_mapserv.fcgi.exe?SERVICE=WMTS&REQUEST=GetTile&MAP=world.qgs&LAYER=countries&FORMAT=image/png&TILEMATRIXSET=EPSG:3857&TileMatrix=0&TILEROW=0&TILECOL=0
Add WFS in QGIS Python Console:
url = 'http://localhost/cgi-bin/qgis_mapserv.fcgi.exe?SERVICE=WFS&VERSION=1.1.0&REQUEST=GetFeature&TYPENAME=countries&map=world.qgs'
qgis.utils.iface.addVectorLayer(url,'qgisserverwfs','WFS')