37 void appendOwsLayerStyles( QDomDocument &doc, QDomElement &layerElem,
QgsMapLayer *currentLayer );
39 void appendOwsLayersFromTreeGroup( QDomDocument &doc,
40 QDomElement &parentLayer,
46 const QString &strGroup );
48 void appendOwsGeneralAndResourceList( QDomDocument &doc, QDomElement &parentElement,
57 #ifdef HAVE_SERVER_PYTHON_PLUGINS
62 const QDomDocument *contextDocument =
nullptr;
64 #ifdef HAVE_SERVER_PYTHON_PLUGINS
66 if ( cacheManager && cacheManager->
getCachedDocument( &doc, project, request, accessControl ) )
68 contextDocument = &doc;
72 doc =
getContext( serverIface, project, version, request );
78 contextDocument = &doc;
81 doc =
getContext( serverIface, project, version, request );
82 contextDocument = &doc;
84 response.
setHeader( QStringLiteral(
"Content-Type" ), QStringLiteral(
"text/xml; charset=utf-8" ) );
85 response.
write( contextDocument->toByteArray() );
95 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,
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 );
140 if ( !title.isEmpty() )
142 QDomElement titleElem = doc.createElement( QStringLiteral(
"ows:Title" ) );
143 QDomText titleText = doc.createTextNode( title );
144 titleElem.appendChild( titleText );
145 generalElem.appendChild( titleElem );
150 if ( !
abstract.isEmpty() )
152 QDomElement abstractElem = doc.createElement( QStringLiteral(
"ows:Abstract" ) );
153 QDomText abstractText = doc.createCDATASection(
abstract );
154 abstractElem.appendChild( abstractText );
155 generalElem.appendChild( abstractElem );
160 if ( !keywords.isEmpty() )
164 QDomElement keywordsElem = doc.createElement( QStringLiteral(
"ows:Keywords" ) );
166 for (
int i = 0; i < keywords.size(); ++i )
168 QString keyword = keywords.at( i );
169 if ( !keyword.isEmpty() )
171 QDomElement keywordElem = doc.createElement( QStringLiteral(
"ows:Keyword" ) );
172 QDomText keywordText = doc.createTextNode( keyword );
173 keywordElem.appendChild( keywordText );
176 keywordElem.setAttribute( QStringLiteral(
"vocabulary" ), QStringLiteral(
"SIA_Geo405" ) );
178 keywordsElem.appendChild( keywordElem );
181 generalElem.appendChild( keywordsElem );
185 parentElement.appendChild( generalElem );
188 QDomElement resourceListElem = doc.createElement( QStringLiteral(
"ResourceList" ) );
191 appendOwsLayersFromTreeGroup( doc, resourceListElem, serverIface, project, request, projectLayerTreeRoot, combinedBBox, QString() );
192 parentElement.appendChild( resourceListElem );
199 mapRect = combinedBBox;
201 QDomElement bboxElem = doc.createElement( QStringLiteral(
"ows:BoundingBox" ) );
202 bboxElem.setAttribute( QStringLiteral(
"crs" ), projectCrs.
authid() );
207 QDomElement lowerCornerElem = doc.createElement( QStringLiteral(
"ows:LowerCorner" ) );
208 QDomText lowerCornerText = doc.createTextNode( QString::number( mapRect.
xMinimum() ) +
" " + QString::number( mapRect.
yMinimum() ) );
209 lowerCornerElem.appendChild( lowerCornerText );
210 bboxElem.appendChild( lowerCornerElem );
211 QDomElement upperCornerElem = doc.createElement( QStringLiteral(
"ows:UpperCorner" ) );
212 QDomText upperCornerText = doc.createTextNode( QString::number( mapRect.
xMaximum() ) +
" " + QString::number( mapRect.
yMaximum() ) );
213 upperCornerElem.appendChild( upperCornerText );
214 bboxElem.appendChild( upperCornerElem );
215 generalElem.appendChild( bboxElem );
218 void appendOwsLayersFromTreeGroup( QDomDocument &doc,
219 QDomElement &parentLayer,
225 const QString &strGroup )
229 QList< QgsLayerTreeNode * > layerTreeGroupChildren = layerTreeGroup->
children();
230 for (
int i = 0; i < layerTreeGroupChildren.size(); ++i )
238 QString name = treeGroupChild->
name();
239 if ( restrictedLayers.contains( name ) )
245 if ( strGroup.isEmpty() )
251 group = strGroup +
"/" + name;
254 appendOwsLayersFromTreeGroup( doc, parentLayer, serverIface, project, request, treeGroupChild, combinedBBox, group );
260 if ( restrictedLayers.contains( l->
name() ) )
264 #ifdef HAVE_SERVER_PYTHON_PLUGINS
271 QDomElement layerElem = doc.createElement( QStringLiteral(
"Layer" ) );
276 layerElem.setAttribute( QStringLiteral(
"queryable" ), QStringLiteral(
"false" ) );
280 layerElem.setAttribute( QStringLiteral(
"queryable" ), QStringLiteral(
"true" ) );
286 layerElem.setAttribute( QStringLiteral(
"hidden" ), QStringLiteral(
"false" ) );
290 layerElem.setAttribute( QStringLiteral(
"hidden" ), QStringLiteral(
"true" ) );
294 if ( !strGroup.isEmpty() )
296 layerElem.setAttribute( QStringLiteral(
"group" ), strGroup );
301 layerElem.setAttribute( QStringLiteral(
"opacity" ), 1 );
303 QString wmsName = l->
name();
313 layerElem.setAttribute( QStringLiteral(
"name" ), wmsName );
315 layerElem.setAttribute( QStringLiteral(
"id" ), wmsName.replace( QRegExp(
"[\\W]" ), QStringLiteral(
"_" ) ) );
318 QDomElement titleElem = doc.createElement( QStringLiteral(
"ows:Title" ) );
319 QString title = l->
title();
320 if ( title.isEmpty() )
324 QDomText titleText = doc.createTextNode( title );
325 titleElem.appendChild( titleText );
326 layerElem.appendChild( titleElem );
329 QDomElement formatElem = doc.createElement( QStringLiteral(
"ows:OutputFormat" ) );
330 QDomText formatText = doc.createTextNode( QStringLiteral(
"image/png" ) );
331 formatElem.appendChild( formatText );
332 layerElem.appendChild( formatElem );
338 QString hrefString = href.toString();
339 hrefString.append( href.hasQuery() ?
"&" :
"?" );
342 QDomElement serverElem = doc.createElement( QStringLiteral(
"Server" ) );
343 serverElem.setAttribute( QStringLiteral(
"service" ), QStringLiteral(
"urn:ogc:serviceType:WMS" ) );
344 serverElem.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.3.0" ) );
345 serverElem.setAttribute( QStringLiteral(
"default" ), QStringLiteral(
"true" ) );
346 QDomElement orServerElem = doc.createElement( QStringLiteral(
"OnlineResource" ) );
347 orServerElem.setAttribute( QStringLiteral(
"xlink:href" ), hrefString );
348 serverElem.appendChild( orServerElem );
349 layerElem.appendChild( serverElem );
352 if ( !
abstract.isEmpty() )
354 QDomElement abstractElem = doc.createElement( QStringLiteral(
"ows:Abstract" ) );
355 QDomText abstractText = doc.createTextNode(
abstract );
356 abstractElem.appendChild( abstractText );
357 layerElem.appendChild( abstractElem );
363 QString minScaleString = QString::number( l->
maximumScale() );
364 QString maxScaleString = QString::number( l->
minimumScale() );
365 QDomElement minScaleElem = doc.createElement( QStringLiteral(
"sld:MinScaleDenominator" ) );
366 QDomText minScaleText = doc.createTextNode( minScaleString );
367 minScaleElem.appendChild( minScaleText );
368 layerElem.appendChild( minScaleElem );
369 QDomElement maxScaleElem = doc.createElement( QStringLiteral(
"sld:MaxScaleDenominator" ) );
370 QDomText maxScaleText = doc.createTextNode( maxScaleString );
371 maxScaleElem.appendChild( maxScaleText );
372 layerElem.appendChild( maxScaleElem );
376 appendOwsLayerStyles( doc, layerElem, l );
381 QStringList keywordStringList = l->
keywordList().split(
',' );
384 QDomElement keywordsElem = doc.createElement( QStringLiteral(
"ows:Keywords" ) );
385 for (
int i = 0; i < keywordStringList.size(); ++i )
387 QDomElement keywordElem = doc.createElement( QStringLiteral(
"ows:Keyword" ) );
388 QDomText keywordText = doc.createTextNode( keywordStringList.at( i ).trimmed() );
389 keywordElem.appendChild( keywordText );
392 keywordElem.setAttribute( QStringLiteral(
"vocabulary" ), QStringLiteral(
"SIA_Geo405" ) );
394 keywordsElem.appendChild( keywordElem );
396 layerElem.appendChild( keywordsElem );
400 QString dataUrl = l->
dataUrl();
401 if ( !dataUrl.isEmpty() )
403 QDomElement dataUrlElem = doc.createElement( QStringLiteral(
"DataURL" ) );
405 dataUrlElem.setAttribute( QStringLiteral(
"format" ), dataUrlFormat );
406 QDomElement dataORElem = doc.createElement( QStringLiteral(
"OnlineResource" ) );
407 dataORElem.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
408 dataORElem.setAttribute( QStringLiteral(
"xlink:type" ), QStringLiteral(
"simple" ) );
409 dataORElem.setAttribute( QStringLiteral(
"xlink:href" ), dataUrl );
410 dataUrlElem.appendChild( dataORElem );
411 layerElem.appendChild( dataUrlElem );
416 if ( !metadataUrl.isEmpty() )
418 QDomElement metaUrlElem = doc.createElement( QStringLiteral(
"MetadataURL" ) );
420 metaUrlElem.setAttribute( QStringLiteral(
"format" ), metadataUrlFormat );
421 QDomElement metaUrlORElem = doc.createElement( QStringLiteral(
"OnlineResource" ) );
422 metaUrlORElem.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
423 metaUrlORElem.setAttribute( QStringLiteral(
"xlink:type" ), QStringLiteral(
"simple" ) );
424 metaUrlORElem.setAttribute( QStringLiteral(
"xlink:href" ), metadataUrl );
425 metaUrlElem.appendChild( metaUrlORElem );
426 layerElem.appendChild( metaUrlElem );
448 if ( parentLayer.hasChildNodes() )
450 parentLayer.insertBefore( layerElem, parentLayer.firstChild() );
454 parentLayer.appendChild( layerElem );
460 void appendOwsLayerStyles( QDomDocument &doc, QDomElement &layerElem,
QgsMapLayer *currentLayer )
464 QDomElement styleListElem = doc.createElement( QStringLiteral(
"StyleList" ) );
466 QDomElement styleElem = doc.createElement( QStringLiteral(
"Style" ) );
467 styleElem.setAttribute( QStringLiteral(
"current" ), QStringLiteral(
"true" ) );
468 QDomElement styleNameElem = doc.createElement( QStringLiteral(
"Name" ) );
469 QDomText styleNameText = doc.createTextNode( styleName );
470 styleNameElem.appendChild( styleNameText );
471 QDomElement styleTitleElem = doc.createElement( QStringLiteral(
"Title" ) );
472 QDomText styleTitleText = doc.createTextNode( styleName );
473 styleTitleElem.appendChild( styleTitleText );
474 styleElem.appendChild( styleNameElem );
475 styleElem.appendChild( styleTitleElem );
476 styleListElem.appendChild( styleElem );
477 layerElem.appendChild( styleListElem );