Qgis-server...Bringing a map image into the browser on Ubuntu 16.04 LTS
NO?...here are some issues to check back in the QGIS project file before we move on.
- Check the 'Project Properties' under the 'Project' menu, go to the 'OWS server' tab. Below is an example of of how I've set up mine.
and here is the bottom bit you cannot see in the above image...
|Ensure under 'Save Paths' in the 'General' Tab it is set to 'relative'. Note that the layers you are going to select for the WMS service are ticked under 'Published' in the WFS capabilities table.|
Moving on to setting up your 'Add layer(s) from WM(T)S Server' button on the 'Manage Layers Toolbar'
Since we are using one layer from a PostGIS database open you 'Project.qgs' file (in Gedit or similar text editor and ensure you add your PostGIS connection details similar to below under <datasource>. I understand you can leave out the password as it is already stored in the 'pgpass.conf' file. I've left this in for demo purposes.
|amend the <datasource> line to reflect your PostGIS database connection details.|
When your done...check again using the same URL as before:
How do we display a map image from our QGIS Desktop project file?
Before we do go back in your QGIS project check you can add your newly created WMS layers back into QGIS as with any other WMS from a different source.
|When you hit the 'connect' button you should see a list of layers you created earlier, if not go back and check from the beginning of this post.|
Select a layer and click 'Add' and the layer(s) should appear in your layer panel as normal qgis layers.
Lastly, r/c on your largest area wms layer and go to 'Properties' and make a note of the bounding box co-ordinates.
|The layer extent is from left to right 262377,179121,297597,215872|
We can now use these co-ordinates in the 'GetMap' part in the url:-
http://localhost/cgi-bin/project/qgis_mapserv.fcgi? this part of the url locates the qgis-server executable on the apache2 host server.
SERVICE=WMS&VERSION=1.3.0&SRS=EPSG:27700& this part calls the WMS service, it's version and the target spatial reference system.
REQUEST=GetMap&map=/usr/lib/cgi-bin/project/southuk.qgs& this part is the request to get the 'map' from the qgis project file.
BBOX=262377,179121,297597,2158721&WIDTH=550&HEIGHT=500& this part sets the size of the retrieved image boundary and the 'WIDTH' and 'HEIGHT' of the image area in the browser.
LAYERS=coast_polyline,b_road_polyline&STYLES=,,&FORMAT=image/png the final part is the description and display of the layers of the WMS. Note there is no 'STYLES' specified because it in specified the .qgs file. Finally, the output format is a png image.
|The final output is a png image in the browser window.|
|and a closer look shows it is identical to the qgis project.|
We could also add many more parameters and requests into the url in order to enhance the visual appearance for example.
REQUEST=GetFeatureInfo...this request retrieves the underlying attributes and geometry values and pixel location.
GetLegendGraphic...this looks for the view legend information.
bgcolor...sets the background map colour.