38 void appendOwsLayerStyles( QDomDocument &doc, QDomElement &layerElem,
QgsMapLayer *currentLayer );
40 void appendOwsLayersFromTreeGroup( QDomDocument &doc,
41 QDomElement &parentLayer,
47 const QString &strGroup );
49 void appendOwsGeneralAndResourceList( QDomDocument &doc, QDomElement &parentElement,
58 #ifdef HAVE_SERVER_PYTHON_PLUGINS 63 const QDomDocument *contextDocument =
nullptr;
65 #ifdef HAVE_SERVER_PYTHON_PLUGINS 67 if ( cacheManager && cacheManager->
getCachedDocument( &doc, project, request, accessControl ) )
69 contextDocument = &doc;
73 doc =
getContext( serverIface, project, version, request );
79 contextDocument = &doc;
82 doc =
getContext( serverIface, project, version, request );
83 contextDocument = &doc;
85 response.
setHeader( QStringLiteral(
"Content-Type" ), QStringLiteral(
"text/xml; charset=utf-8" ) );
86 response.
write( contextDocument->toByteArray() );
96 QDomProcessingInstruction xmlDeclaration = doc.createProcessingInstruction( QStringLiteral(
"xml" ),
97 QStringLiteral(
"version=\"1.0\" encoding=\"utf-8\"" ) );
99 doc.appendChild( xmlDeclaration );
101 QDomElement owsContextElem = doc.createElement( QStringLiteral(
"OWSContext" ) );
102 owsContextElem.setAttribute( QStringLiteral(
"xmlns" ), QStringLiteral(
"http://www.opengis.net/ows-context" ) );
103 owsContextElem.setAttribute( QStringLiteral(
"xmlns:ows-context" ), QStringLiteral(
"http://www.opengis.net/ows-context" ) );
104 owsContextElem.setAttribute( QStringLiteral(
"xmlns:context" ), QStringLiteral(
"http://www.opengis.net/context" ) );
105 owsContextElem.setAttribute( QStringLiteral(
"xmlns:ows" ), QStringLiteral(
"http://www.opengis.net/ows" ) );
106 owsContextElem.setAttribute( QStringLiteral(
"xmlns:sld" ), QStringLiteral(
"http://www.opengis.net/sld" ) );
107 owsContextElem.setAttribute( QStringLiteral(
"xmlns:ogc" ), QStringLiteral(
"http://www.opengis.net/ogc" ) );
108 owsContextElem.setAttribute( QStringLiteral(
"xmlns:gml" ), QStringLiteral(
"http://www.opengis.net/gml" ) );
109 owsContextElem.setAttribute( QStringLiteral(
"xmlns:kml" ), QStringLiteral(
"http://www.opengis.net/kml/2.2" ) );
110 owsContextElem.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
111 owsContextElem.setAttribute( QStringLiteral(
"xmlns:ns9" ), QStringLiteral(
"http://www.w3.org/2005/Atom" ) );
112 owsContextElem.setAttribute( QStringLiteral(
"xmlns:xal" ), QStringLiteral(
"urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" ) );
113 owsContextElem.setAttribute( QStringLiteral(
"xmlns:ins" ), QStringLiteral(
"http://www.inspire.org" ) );
114 owsContextElem.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"0.3.1" ) );
115 doc.appendChild( owsContextElem );
117 appendOwsGeneralAndResourceList( doc, owsContextElem, serverIface, project, request );
123 void appendOwsGeneralAndResourceList( QDomDocument &doc, QDomElement &parentElement,
127 parentElement.setAttribute( QStringLiteral(
"id" ),
"ows-context-" + project->
baseName() );
130 QDomElement generalElem = doc.createElement( QStringLiteral(
"General" ) );
133 QDomElement windowElem = doc.createElement( QStringLiteral(
"Window" ) );
134 windowElem.setAttribute( QStringLiteral(
"height" ), QStringLiteral(
"600" ) );
135 windowElem.setAttribute( QStringLiteral(
"width" ), QStringLiteral(
"800" ) );
136 generalElem.appendChild( windowElem );
141 if ( !title.isEmpty() )
143 QDomElement titleElem = doc.createElement( QStringLiteral(
"ows:Title" ) );
144 QDomText titleText = doc.createTextNode( title );
145 titleElem.appendChild( titleText );
146 generalElem.appendChild( titleElem );
151 if ( !
abstract.isEmpty() )
153 QDomElement abstractElem = doc.createElement( QStringLiteral(
"ows:Abstract" ) );
154 QDomText abstractText = doc.createCDATASection(
abstract );
155 abstractElem.appendChild( abstractText );
156 generalElem.appendChild( abstractElem );
161 if ( !keywords.isEmpty() )
165 QDomElement keywordsElem = doc.createElement( QStringLiteral(
"ows:Keywords" ) );
167 for (
int i = 0; i < keywords.size(); ++i )
169 QString keyword = keywords.at( i );
170 if ( !keyword.isEmpty() )
172 QDomElement keywordElem = doc.createElement( QStringLiteral(
"ows:Keyword" ) );
173 QDomText keywordText = doc.createTextNode( keyword );
174 keywordElem.appendChild( keywordText );
177 keywordElem.setAttribute( QStringLiteral(
"vocabulary" ), QStringLiteral(
"SIA_Geo405" ) );
179 keywordsElem.appendChild( keywordElem );
182 generalElem.appendChild( keywordsElem );
186 parentElement.appendChild( generalElem );
189 QDomElement resourceListElem = doc.createElement( QStringLiteral(
"ResourceList" ) );
192 appendOwsLayersFromTreeGroup( doc, resourceListElem, serverIface, project, request, projectLayerTreeRoot, combinedBBox, QString() );
193 parentElement.appendChild( resourceListElem );
200 mapRect = combinedBBox;
202 QDomElement bboxElem = doc.createElement( QStringLiteral(
"ows:BoundingBox" ) );
203 bboxElem.setAttribute( QStringLiteral(
"crs" ), projectCrs.
authid() );
208 QDomElement lowerCornerElem = doc.createElement( QStringLiteral(
"ows:LowerCorner" ) );
209 QDomText lowerCornerText = doc.createTextNode( QString::number( mapRect.
xMinimum() ) +
" " + QString::number( mapRect.
yMinimum() ) );
210 lowerCornerElem.appendChild( lowerCornerText );
211 bboxElem.appendChild( lowerCornerElem );
212 QDomElement upperCornerElem = doc.createElement( QStringLiteral(
"ows:UpperCorner" ) );
213 QDomText upperCornerText = doc.createTextNode( QString::number( mapRect.
xMaximum() ) +
" " + QString::number( mapRect.
yMaximum() ) );
214 upperCornerElem.appendChild( upperCornerText );
215 bboxElem.appendChild( upperCornerElem );
216 generalElem.appendChild( bboxElem );
219 void appendOwsLayersFromTreeGroup( QDomDocument &doc,
220 QDomElement &parentLayer,
226 const QString &strGroup )
230 QList< QgsLayerTreeNode * > layerTreeGroupChildren = layerTreeGroup->
children();
231 for (
int i = 0; i < layerTreeGroupChildren.size(); ++i )
239 QString name = treeGroupChild->
name();
240 if ( restrictedLayers.contains( name ) )
246 if ( strGroup.isEmpty() )
252 group = strGroup +
"/" + name;
255 appendOwsLayersFromTreeGroup( doc, parentLayer, serverIface, project, request, treeGroupChild, combinedBBox, group );
261 if ( restrictedLayers.contains( l->
name() ) )
272 QDomElement layerElem = doc.createElement( QStringLiteral(
"Layer" ) );
277 layerElem.setAttribute( QStringLiteral(
"queryable" ), QStringLiteral(
"false" ) );
281 layerElem.setAttribute( QStringLiteral(
"queryable" ), QStringLiteral(
"true" ) );
287 layerElem.setAttribute( QStringLiteral(
"hidden" ), QStringLiteral(
"false" ) );
291 layerElem.setAttribute( QStringLiteral(
"hidden" ), QStringLiteral(
"true" ) );
295 if ( !strGroup.isEmpty() )
297 layerElem.setAttribute( QStringLiteral(
"group" ), strGroup );
302 layerElem.setAttribute( QStringLiteral(
"opacity" ), 1 );
304 QString wmsName = l->
name();
314 layerElem.setAttribute( QStringLiteral(
"name" ), wmsName );
316 layerElem.setAttribute( QStringLiteral(
"id" ), wmsName.replace( QRegExp(
"[\\W]" ), QStringLiteral(
"_" ) ) );
319 QDomElement titleElem = doc.createElement( QStringLiteral(
"ows:Title" ) );
320 QString title = l->
title();
321 if ( title.isEmpty() )
325 QDomText titleText = doc.createTextNode( title );
326 titleElem.appendChild( titleText );
327 layerElem.appendChild( titleElem );
330 QDomElement formatElem = doc.createElement( QStringLiteral(
"ows:OutputFormat" ) );
331 QDomText formatText = doc.createTextNode( QStringLiteral(
"image/png" ) );
332 formatElem.appendChild( formatText );
333 layerElem.appendChild( formatElem );
339 QString hrefString = href.toString();
340 hrefString.append( href.hasQuery() ?
"&" :
"?" );
343 QDomElement serverElem = doc.createElement( QStringLiteral(
"Server" ) );
344 serverElem.setAttribute( QStringLiteral(
"service" ), QStringLiteral(
"urn:ogc:serviceType:WMS" ) );
345 serverElem.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.3.0" ) );
346 serverElem.setAttribute( QStringLiteral(
"default" ), QStringLiteral(
"true" ) );
347 QDomElement orServerElem = doc.createElement( QStringLiteral(
"OnlineResource" ) );
348 orServerElem.setAttribute( QStringLiteral(
"xlink:href" ), hrefString );
349 serverElem.appendChild( orServerElem );
350 layerElem.appendChild( serverElem );
353 if ( !
abstract.isEmpty() )
355 QDomElement abstractElem = doc.createElement( QStringLiteral(
"ows:Abstract" ) );
356 QDomText abstractText = doc.createTextNode(
abstract );
357 abstractElem.appendChild( abstractText );
358 layerElem.appendChild( abstractElem );
364 QString minScaleString = QString::number( l->
maximumScale() );
365 QString maxScaleString = QString::number( l->
minimumScale() );
366 QDomElement minScaleElem = doc.createElement( QStringLiteral(
"sld:MinScaleDenominator" ) );
367 QDomText minScaleText = doc.createTextNode( minScaleString );
368 minScaleElem.appendChild( minScaleText );
369 layerElem.appendChild( minScaleElem );
370 QDomElement maxScaleElem = doc.createElement( QStringLiteral(
"sld:MaxScaleDenominator" ) );
371 QDomText maxScaleText = doc.createTextNode( maxScaleString );
372 maxScaleElem.appendChild( maxScaleText );
373 layerElem.appendChild( maxScaleElem );
377 appendOwsLayerStyles( doc, layerElem, l );
382 QStringList keywordStringList = l->
keywordList().split(
',' );
385 QDomElement keywordsElem = doc.createElement( QStringLiteral(
"ows:Keywords" ) );
386 for (
int i = 0; i < keywordStringList.size(); ++i )
388 QDomElement keywordElem = doc.createElement( QStringLiteral(
"ows:Keyword" ) );
389 QDomText keywordText = doc.createTextNode( keywordStringList.at( i ).trimmed() );
390 keywordElem.appendChild( keywordText );
393 keywordElem.setAttribute( QStringLiteral(
"vocabulary" ), QStringLiteral(
"SIA_Geo405" ) );
395 keywordsElem.appendChild( keywordElem );
397 layerElem.appendChild( keywordsElem );
401 QString dataUrl = l->
dataUrl();
402 if ( !dataUrl.isEmpty() )
404 QDomElement dataUrlElem = doc.createElement( QStringLiteral(
"DataURL" ) );
406 dataUrlElem.setAttribute( QStringLiteral(
"format" ), dataUrlFormat );
407 QDomElement dataORElem = doc.createElement( QStringLiteral(
"OnlineResource" ) );
408 dataORElem.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
409 dataORElem.setAttribute( QStringLiteral(
"xlink:type" ), QStringLiteral(
"simple" ) );
410 dataORElem.setAttribute( QStringLiteral(
"xlink:href" ), dataUrl );
411 dataUrlElem.appendChild( dataORElem );
412 layerElem.appendChild( dataUrlElem );
417 if ( !metadataUrl.isEmpty() )
419 QDomElement metaUrlElem = doc.createElement( QStringLiteral(
"MetadataURL" ) );
421 metaUrlElem.setAttribute( QStringLiteral(
"format" ), metadataUrlFormat );
422 QDomElement metaUrlORElem = doc.createElement( QStringLiteral(
"OnlineResource" ) );
423 metaUrlORElem.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
424 metaUrlORElem.setAttribute( QStringLiteral(
"xlink:type" ), QStringLiteral(
"simple" ) );
425 metaUrlORElem.setAttribute( QStringLiteral(
"xlink:href" ), metadataUrl );
426 metaUrlElem.appendChild( metaUrlORElem );
427 layerElem.appendChild( metaUrlElem );
449 if ( parentLayer.hasChildNodes() )
451 parentLayer.insertBefore( layerElem, parentLayer.firstChild() );
455 parentLayer.appendChild( layerElem );
461 void appendOwsLayerStyles( QDomDocument &doc, QDomElement &layerElem,
QgsMapLayer *currentLayer )
465 QDomElement styleListElem = doc.createElement( QStringLiteral(
"StyleList" ) );
467 QDomElement styleElem = doc.createElement( QStringLiteral(
"Style" ) );
468 styleElem.setAttribute( QStringLiteral(
"current" ), QStringLiteral(
"true" ) );
469 QDomElement styleNameElem = doc.createElement( QStringLiteral(
"Name" ) );
470 QDomText styleNameText = doc.createTextNode( styleName );
471 styleNameElem.appendChild( styleNameText );
472 QDomElement styleTitleElem = doc.createElement( QStringLiteral(
"Title" ) );
473 QDomText styleTitleText = doc.createTextNode( styleName );
474 styleTitleElem.appendChild( styleTitleText );
475 styleElem.appendChild( styleNameElem );
476 styleElem.appendChild( styleTitleElem );
477 styleListElem.appendChild( styleElem );
478 layerElem.appendChild( styleListElem );
Layer tree group node serves as a container for layers and further groups.
virtual void setHeader(const QString &key, const QString &value)=0
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...
A rectangle specified with double values.
Base class for all map layer types.
bool isEmpty() const
Returns true if the rectangle is empty.
bool getCachedDocument(QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl) const
Returns cached document (or 0 if document not in cache) like capabilities.
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
bool setCachedDocument(const QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl) const
Updates or inserts the document in cache like capabilities.
SERVER_EXPORT QStringList owsServiceKeywords(const QgsProject &project)
Returns the owsService keywords defined in project.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
double maximumScale() const
Returns the maximum map scale (i.e.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
bool itemVisibilityChecked() const
Returns whether a node is checked (independently of its ancestors or children)
SERVER_EXPORT QString owsServiceAbstract(const QgsProject &project)
Returns the owsService abstract defined in project.
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
SERVER_EXPORT bool wmsInfoFormatSia2045(const QgsProject &project)
Returns if the info format is SIA20145.
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
QDomDocument getContext(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request)
Returns XML document for the 'GetContext' request.
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device...
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Namespace with helper functions for layer tree operations.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
void writeGetContext(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetContext response.
A helper class that centralizes caches accesses given by all the server cache filter plugins...
This class is a base class for nodes in a layer tree.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
Reads and writes project states.
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
QString abstract() const
Returns the abstract of the layer used by QGIS Server in GetCapabilities request. ...
double minimumScale() const
Returns the minimum map scale (i.e.
Median cut implementation.
QString metadataUrl() const
Returns the metadata URL of the layer used by QGIS Server in GetCapabilities request.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle...
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QString baseName() const
Returns the base name of the project file without the path and without extension - derived from fileN...
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins...
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
SERVER_EXPORT QgsRectangle wmsExtent(const QgsProject &project)
Returns the WMS Extent restriction.
This class represents a coordinate reference system (CRS).
QString authid() const
Returns the authority identifier for the CRS.
virtual QgsServerCacheManager * cacheManager() const =0
Gets the registered server cache filters.
QUrl serviceUrl(const QgsServerRequest &request, const QgsProject *project)
Returns WMS service URL.
A helper class that centralizes restrictions given by all the access control filter plugins...
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
QString name() const override
Returns the group's name.
NodeType nodeType() const
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree...
Custom exception class for Coordinate Reference System related exceptions.
virtual QgsAccessControl * accessControls() const =0
Gets the registered access control filters.
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
SERVER_EXPORT QStringList wmsRestrictedLayers(const QgsProject &project)
Returns the restricted layer name list.
Container of other groups and layers.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
If the layer is identifiable using the identify map tool and as a WMS layer.
QString metadataUrlFormat() const
Returns the metadata format of the layer used by QGIS Server in GetCapabilities request.
SERVER_EXPORT QString owsServiceTitle(const QgsProject &project)
Returns the owsService title defined in project.
QgsCoordinateReferenceSystem crs
bool hasAxisInverted() const
Returns whether axis is inverted (e.g., for WMS 1.3) for the CRS.
void invert()
Swap x/y coordinates in the rectangle.
Layer tree node points to a map layer.
SERVER_EXPORT bool wmsUseLayerIds(const QgsProject &project)
Returns if layer ids are used as name in WMS.
QStringList styles() const
Returns list of all defined style names.
bool layerReadPermission(const QgsMapLayer *layer) const
Returns the layer read right.