38 void appendOwsLayerStyles( QDomDocument &doc, QDomElement &layerElem,
QgsMapLayer *currentLayer );
40 void appendOwsLayersFromTreeGroup( QDomDocument &doc,
41 QDomElement &parentLayer,
44 const QgsWmsRequest &request,
47 const QString &strGroup );
49 void appendOwsGeneralAndResourceList( QDomDocument &doc, QDomElement &parentElement,
51 const QgsWmsRequest &request );
55 const QgsWmsRequest &request,
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, request );
79 contextDocument = &doc;
82 doc =
getContext( serverIface, project, request );
83 contextDocument = &doc;
85 response.
setHeader( QStringLiteral(
"Content-Type" ), QStringLiteral(
"text/xml; charset=utf-8" ) );
86 response.
write( contextDocument->toByteArray() );
92 const QgsWmsRequest &request )
95 const QDomProcessingInstruction xmlDeclaration = doc.createProcessingInstruction( QStringLiteral(
"xml" ),
96 QStringLiteral(
"version=\"1.0\" encoding=\"utf-8\"" ) );
98 doc.appendChild( xmlDeclaration );
100 QDomElement owsContextElem = doc.createElement( QStringLiteral(
"OWSContext" ) );
101 owsContextElem.setAttribute( QStringLiteral(
"xmlns" ), QStringLiteral(
"http://www.opengis.net/ows-context" ) );
102 owsContextElem.setAttribute( QStringLiteral(
"xmlns:ows-context" ), QStringLiteral(
"http://www.opengis.net/ows-context" ) );
103 owsContextElem.setAttribute( QStringLiteral(
"xmlns:context" ), QStringLiteral(
"http://www.opengis.net/context" ) );
104 owsContextElem.setAttribute( QStringLiteral(
"xmlns:ows" ), QStringLiteral(
"http://www.opengis.net/ows" ) );
105 owsContextElem.setAttribute( QStringLiteral(
"xmlns:sld" ), QStringLiteral(
"http://www.opengis.net/sld" ) );
106 owsContextElem.setAttribute( QStringLiteral(
"xmlns:ogc" ), QStringLiteral(
"http://www.opengis.net/ogc" ) );
107 owsContextElem.setAttribute( QStringLiteral(
"xmlns:gml" ), QStringLiteral(
"http://www.opengis.net/gml" ) );
108 owsContextElem.setAttribute( QStringLiteral(
"xmlns:kml" ), QStringLiteral(
"http://www.opengis.net/kml/2.2" ) );
109 owsContextElem.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
110 owsContextElem.setAttribute( QStringLiteral(
"xmlns:ns9" ), QStringLiteral(
"http://www.w3.org/2005/Atom" ) );
111 owsContextElem.setAttribute( QStringLiteral(
"xmlns:xal" ), QStringLiteral(
"urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" ) );
112 owsContextElem.setAttribute( QStringLiteral(
"xmlns:ins" ), QStringLiteral(
"http://www.inspire.org" ) );
113 owsContextElem.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"0.3.1" ) );
114 doc.appendChild( owsContextElem );
116 appendOwsGeneralAndResourceList( doc, owsContextElem, serverIface, project, request );
122 void appendOwsGeneralAndResourceList( QDomDocument &doc, QDomElement &parentElement,
124 const QgsWmsRequest &request )
126 parentElement.setAttribute( QStringLiteral(
"id" ),
"ows-context-" + project->
baseName() );
129 QDomElement generalElem = doc.createElement( QStringLiteral(
"General" ) );
132 QDomElement windowElem = doc.createElement( QStringLiteral(
"Window" ) );
133 windowElem.setAttribute( QStringLiteral(
"height" ), QStringLiteral(
"600" ) );
134 windowElem.setAttribute( QStringLiteral(
"width" ), QStringLiteral(
"800" ) );
135 generalElem.appendChild( windowElem );
139 QDomElement titleElem = doc.createElement( QStringLiteral(
"ows:Title" ) );
140 const QDomText titleText = doc.createTextNode( title );
141 titleElem.appendChild( titleText );
142 generalElem.appendChild( titleElem );
146 if ( !
abstract.isEmpty() )
148 QDomElement abstractElem = doc.createElement( QStringLiteral(
"ows:Abstract" ) );
149 const QDomText abstractText = doc.createCDATASection(
abstract );
150 abstractElem.appendChild( abstractText );
151 generalElem.appendChild( abstractElem );
156 if ( !keywords.isEmpty() )
160 QDomElement keywordsElem = doc.createElement( QStringLiteral(
"ows:Keywords" ) );
162 for (
int i = 0; i < keywords.size(); ++i )
164 const QString keyword = keywords.at( i );
165 if ( !keyword.isEmpty() )
167 QDomElement keywordElem = doc.createElement( QStringLiteral(
"ows:Keyword" ) );
168 const QDomText keywordText = doc.createTextNode( keyword );
169 keywordElem.appendChild( keywordText );
172 keywordElem.setAttribute( QStringLiteral(
"vocabulary" ), QStringLiteral(
"SIA_Geo405" ) );
174 keywordsElem.appendChild( keywordElem );
177 generalElem.appendChild( keywordsElem );
181 parentElement.appendChild( generalElem );
184 QDomElement resourceListElem = doc.createElement( QStringLiteral(
"ResourceList" ) );
187 appendOwsLayersFromTreeGroup( doc, resourceListElem, serverIface, project, request, projectLayerTreeRoot, combinedBBox, QString() );
188 parentElement.appendChild( resourceListElem );
195 mapRect = combinedBBox;
197 QDomElement bboxElem = doc.createElement( QStringLiteral(
"ows:BoundingBox" ) );
198 bboxElem.setAttribute( QStringLiteral(
"crs" ), projectCrs.
authid() );
203 QDomElement lowerCornerElem = doc.createElement( QStringLiteral(
"ows:LowerCorner" ) );
204 const QDomText lowerCornerText = doc.createTextNode( QString::number( mapRect.
xMinimum() ) +
" " + QString::number( mapRect.
yMinimum() ) );
205 lowerCornerElem.appendChild( lowerCornerText );
206 bboxElem.appendChild( lowerCornerElem );
207 QDomElement upperCornerElem = doc.createElement( QStringLiteral(
"ows:UpperCorner" ) );
208 const QDomText upperCornerText = doc.createTextNode( QString::number( mapRect.
xMaximum() ) +
" " + QString::number( mapRect.
yMaximum() ) );
209 upperCornerElem.appendChild( upperCornerText );
210 bboxElem.appendChild( upperCornerElem );
211 generalElem.appendChild( bboxElem );
214 void appendOwsLayersFromTreeGroup( QDomDocument &doc,
215 QDomElement &parentLayer,
218 const QgsWmsRequest &request,
221 const QString &strGroup )
225 const QList< QgsLayerTreeNode * > layerTreeGroupChildren = layerTreeGroup->
children();
226 for (
int i = 0; i < layerTreeGroupChildren.size(); ++i )
234 const QString name = treeGroupChild->
name();
235 if ( restrictedLayers.contains( name ) )
241 if ( strGroup.isEmpty() )
247 group = strGroup +
"/" + name;
250 appendOwsLayersFromTreeGroup( doc, parentLayer, serverIface, project, request, treeGroupChild, combinedBBox, group );
256 if ( restrictedLayers.contains( l->
name() ) )
260 #ifdef HAVE_SERVER_PYTHON_PLUGINS
267 QDomElement layerElem = doc.createElement( QStringLiteral(
"Layer" ) );
272 layerElem.setAttribute( QStringLiteral(
"queryable" ), QStringLiteral(
"false" ) );
276 layerElem.setAttribute( QStringLiteral(
"queryable" ), QStringLiteral(
"true" ) );
282 layerElem.setAttribute( QStringLiteral(
"hidden" ), QStringLiteral(
"false" ) );
286 layerElem.setAttribute( QStringLiteral(
"hidden" ), QStringLiteral(
"true" ) );
290 if ( !strGroup.isEmpty() )
292 layerElem.setAttribute( QStringLiteral(
"group" ), strGroup );
297 layerElem.setAttribute( QStringLiteral(
"opacity" ), 1 );
299 QString wmsName = l->
name();
309 layerElem.setAttribute( QStringLiteral(
"name" ), wmsName );
311 layerElem.setAttribute( QStringLiteral(
"id" ), wmsName.replace( QRegExp(
"[\\W]" ), QStringLiteral(
"_" ) ) );
314 QDomElement titleElem = doc.createElement( QStringLiteral(
"ows:Title" ) );
315 QString title = l->
title();
316 if ( title.isEmpty() )
320 const QDomText titleText = doc.createTextNode( title );
321 titleElem.appendChild( titleText );
322 layerElem.appendChild( titleElem );
325 QDomElement formatElem = doc.createElement( QStringLiteral(
"ows:OutputFormat" ) );
326 const QDomText formatText = doc.createTextNode( QStringLiteral(
"image/png" ) );
327 formatElem.appendChild( formatText );
328 layerElem.appendChild( formatElem );
334 QString hrefString = href.toString();
335 hrefString.append( href.hasQuery() ?
"&" :
"?" );
338 QDomElement serverElem = doc.createElement( QStringLiteral(
"Server" ) );
339 serverElem.setAttribute( QStringLiteral(
"service" ), QStringLiteral(
"urn:ogc:serviceType:WMS" ) );
340 serverElem.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.3.0" ) );
341 serverElem.setAttribute( QStringLiteral(
"default" ), QStringLiteral(
"true" ) );
342 QDomElement orServerElem = doc.createElement( QStringLiteral(
"OnlineResource" ) );
343 orServerElem.setAttribute( QStringLiteral(
"xlink:href" ), hrefString );
344 serverElem.appendChild( orServerElem );
345 layerElem.appendChild( serverElem );
347 const QString
abstract = l->
abstract();
348 if ( !
abstract.isEmpty() )
350 QDomElement abstractElem = doc.createElement( QStringLiteral(
"ows:Abstract" ) );
351 const QDomText abstractText = doc.createTextNode(
abstract );
352 abstractElem.appendChild( abstractText );
353 layerElem.appendChild( abstractElem );
359 const QString minScaleString = QString::number( l->
maximumScale() );
360 const QString maxScaleString = QString::number( l->
minimumScale() );
361 QDomElement minScaleElem = doc.createElement( QStringLiteral(
"sld:MinScaleDenominator" ) );
362 const QDomText minScaleText = doc.createTextNode( minScaleString );
363 minScaleElem.appendChild( minScaleText );
364 layerElem.appendChild( minScaleElem );
365 QDomElement maxScaleElem = doc.createElement( QStringLiteral(
"sld:MaxScaleDenominator" ) );
366 const QDomText maxScaleText = doc.createTextNode( maxScaleString );
367 maxScaleElem.appendChild( maxScaleText );
368 layerElem.appendChild( maxScaleElem );
372 appendOwsLayerStyles( doc, layerElem, l );
377 const QStringList keywordStringList = l->
keywordList().split(
',' );
380 QDomElement keywordsElem = doc.createElement( QStringLiteral(
"ows:Keywords" ) );
381 for (
int i = 0; i < keywordStringList.size(); ++i )
383 QDomElement keywordElem = doc.createElement( QStringLiteral(
"ows:Keyword" ) );
384 const QDomText keywordText = doc.createTextNode( keywordStringList.at( i ).trimmed() );
385 keywordElem.appendChild( keywordText );
388 keywordElem.setAttribute( QStringLiteral(
"vocabulary" ), QStringLiteral(
"SIA_Geo405" ) );
390 keywordsElem.appendChild( keywordElem );
392 layerElem.appendChild( keywordsElem );
396 const QString dataUrl = l->
dataUrl();
397 if ( !dataUrl.isEmpty() )
399 QDomElement dataUrlElem = doc.createElement( QStringLiteral(
"DataURL" ) );
401 dataUrlElem.setAttribute( QStringLiteral(
"format" ), dataUrlFormat );
402 QDomElement dataORElem = doc.createElement( QStringLiteral(
"OnlineResource" ) );
403 dataORElem.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
404 dataORElem.setAttribute( QStringLiteral(
"xlink:type" ), QStringLiteral(
"simple" ) );
405 dataORElem.setAttribute( QStringLiteral(
"xlink:href" ), dataUrl );
406 dataUrlElem.appendChild( dataORElem );
407 layerElem.appendChild( dataUrlElem );
414 QDomElement metaUrlElem = doc.createElement( QStringLiteral(
"MetadataURL" ) );
415 metaUrlElem.setAttribute( QStringLiteral(
"format" ), url.format );
416 QDomElement metaUrlORElem = doc.createElement( QStringLiteral(
"OnlineResource" ) );
417 metaUrlORElem.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
418 metaUrlORElem.setAttribute( QStringLiteral(
"xlink:type" ), QStringLiteral(
"simple" ) );
419 metaUrlORElem.setAttribute( QStringLiteral(
"xlink:href" ), url.url );
420 metaUrlElem.appendChild( metaUrlORElem );
421 layerElem.appendChild( metaUrlElem );
443 if ( parentLayer.hasChildNodes() )
445 parentLayer.insertBefore( layerElem, parentLayer.firstChild() );
449 parentLayer.appendChild( layerElem );
455 void appendOwsLayerStyles( QDomDocument &doc, QDomElement &layerElem,
QgsMapLayer *currentLayer )
459 QDomElement styleListElem = doc.createElement( QStringLiteral(
"StyleList" ) );
461 QDomElement styleElem = doc.createElement( QStringLiteral(
"Style" ) );
462 styleElem.setAttribute( QStringLiteral(
"current" ), QStringLiteral(
"true" ) );
463 QDomElement styleNameElem = doc.createElement( QStringLiteral(
"Name" ) );
464 const QDomText styleNameText = doc.createTextNode( styleName );
465 styleNameElem.appendChild( styleNameText );
466 QDomElement styleTitleElem = doc.createElement( QStringLiteral(
"Title" ) );
467 const QDomText styleTitleText = doc.createTextNode( styleName );
468 styleTitleElem.appendChild( styleTitleText );
469 styleElem.appendChild( styleNameElem );
470 styleElem.appendChild( styleTitleElem );
471 styleListElem.appendChild( styleElem );
472 layerElem.appendChild( styleListElem );