QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
qgswcsdescribecoverage.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgswcsdescribecoverage.cpp
3 -------------------------
4 begin : January 16 , 2017
5 copyright : (C) 2013 by René-Luc D'Hont ( parts from qgswcsserver )
6 (C) 2017 by David Marteau
7 email : rldhont at 3liz dot com
8 david dot marteau at 3liz dot com
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19#include "qgswcsutils.h"
22
23#include "qgsproject.h"
24#include "qgsmaplayer.h"
25#include "qgsrasterlayer.h"
26
27namespace QgsWcs
28{
29
33 void writeDescribeCoverage( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
34 const QgsServerRequest &request, QgsServerResponse &response )
35 {
36#ifdef HAVE_SERVER_PYTHON_PLUGINS
37 QgsAccessControl *accessControl = serverIface->accessControls();
38#endif
39 QDomDocument doc;
40 const QDomDocument *describeDocument = nullptr;
41
42#ifdef HAVE_SERVER_PYTHON_PLUGINS
43 QgsServerCacheManager *cacheManager = serverIface->cacheManager();
44 if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
45 {
46 describeDocument = &doc;
47 }
48 else //describe feature xml not in cache. Create a new one
49 {
50 doc = createDescribeCoverageDocument( serverIface, project, version, request );
51
52 if ( cacheManager )
53 {
54 cacheManager->setCachedDocument( &doc, project, request, accessControl );
55 }
56 describeDocument = &doc;
57 }
58#else
59 doc = createDescribeCoverageDocument( serverIface, project, version, request );
60 describeDocument = &doc;
61#endif
62 response.setHeader( "Content-Type", "text/xml; charset=utf-8" );
63 response.write( describeDocument->toByteArray() );
64 }
65
66
67 QDomDocument createDescribeCoverageDocument( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
68 const QgsServerRequest &request )
69 {
70 Q_UNUSED( version )
71
72 QDomDocument doc;
73
74 const QgsServerRequest::Parameters parameters = request.parameters();
75
76#ifdef HAVE_SERVER_PYTHON_PLUGINS
77 QgsAccessControl *accessControl = serverIface->accessControls();
78#else
79 ( void )serverIface;
80#endif
81
82 //wcs:WCS_Capabilities element
83 QDomElement coveDescElement = doc.createElement( QStringLiteral( "CoverageDescription" )/*wcs:CoverageDescription*/ );
84 coveDescElement.setAttribute( QStringLiteral( "xmlns" ), WCS_NAMESPACE );
85 coveDescElement.setAttribute( QStringLiteral( "xmlns:xsi" ), QStringLiteral( "http://www.w3.org/2001/XMLSchema-instance" ) );
86 coveDescElement.setAttribute( QStringLiteral( "xsi:schemaLocation" ), WCS_NAMESPACE + " http://schemas.opengis.net/wcs/1.0.0/describeCoverage.xsd" );
87 coveDescElement.setAttribute( QStringLiteral( "xmlns:gml" ), GML_NAMESPACE );
88 coveDescElement.setAttribute( QStringLiteral( "xmlns:xlink" ), QStringLiteral( "http://www.w3.org/1999/xlink" ) );
89 coveDescElement.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0.0" ) );
90 coveDescElement.setAttribute( QStringLiteral( "updateSequence" ), QStringLiteral( "0" ) );
91 doc.appendChild( coveDescElement );
92
93 //defining coverage name
94 QString coveNames;
95 //read COVERAGE
96 const QMap<QString, QString>::const_iterator cove_name_it = parameters.constFind( QStringLiteral( "COVERAGE" ) );
97 if ( cove_name_it != parameters.constEnd() )
98 {
99 coveNames = cove_name_it.value();
100 }
101 if ( coveNames.isEmpty() )
102 {
103 const QMap<QString, QString>::const_iterator cove_name_it = parameters.constFind( QStringLiteral( "IDENTIFIER" ) );
104 if ( cove_name_it != parameters.constEnd() )
105 {
106 coveNames = cove_name_it.value();
107 }
108 }
109
110 QStringList coveNameList;
111 if ( !coveNames.isEmpty() )
112 {
113 coveNameList = coveNames.split( ',' );
114 for ( int i = 0; i < coveNameList.size(); ++i )
115 {
116 coveNameList.replace( i, coveNameList.at( i ).trimmed() );
117 }
118 }
119
120 const QStringList wcsLayersId = QgsServerProjectUtils::wcsLayerIds( *project );
121 for ( int i = 0; i < wcsLayersId.size(); ++i )
122 {
123 QgsMapLayer *layer = project->mapLayer( wcsLayersId.at( i ) );
124 if ( !layer )
125 {
126 continue;
127 }
128 if ( layer->type() != Qgis::LayerType::Raster )
129 {
130 continue;
131 }
132#ifdef HAVE_SERVER_PYTHON_PLUGINS
133 if ( !accessControl->layerReadPermission( layer ) )
134 {
135 continue;
136 }
137#endif
138 QString name = layer->name();
139 if ( !layer->shortName().isEmpty() )
140 name = layer->shortName();
141 name = name.replace( ' ', '_' );
142
143 if ( coveNameList.size() == 0 || coveNameList.contains( name ) )
144 {
145 QgsRasterLayer *rLayer = qobject_cast<QgsRasterLayer *>( layer );
146 coveDescElement.appendChild( getCoverageOffering( doc, const_cast<QgsRasterLayer *>( rLayer ), project ) );
147 }
148 }
149 return doc;
150 }
151
152} // namespace QgsWcs
153
154
155
@ Raster
Raster layer.
A helper class that centralizes restrictions given by all the access control filter plugins.
bool layerReadPermission(const QgsMapLayer *layer) const
Returns the layer read right.
Base class for all map layer types.
Definition qgsmaplayer.h:75
QString name
Definition qgsmaplayer.h:78
Qgis::LayerType type
Definition qgsmaplayer.h:82
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
Represents a raster layer.
A helper class that centralizes caches accesses given by all the server cache filter plugins.
bool setCachedDocument(const QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl) const
Updates or inserts the document in cache like capabilities.
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.
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
virtual QgsServerCacheManager * cacheManager() const =0
Gets the registered server cache filters.
virtual QgsAccessControl * accessControls() const =0
Gets the registered access control filters.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.
QMap< QString, QString > Parameters
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device.
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...
SERVER_EXPORT QStringList wcsLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published in WCS.
WCS implementation.
Definition qgswcs.cpp:30
QDomElement getCoverageOffering(QDomDocument &doc, const QgsRasterLayer *layer, const QgsProject *project, bool brief)
CoverageOffering or CoverageOfferingBrief element.
void writeDescribeCoverage(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WCS DescribeCoverage response.
const QString WCS_NAMESPACE
Definition qgswcsutils.h:63
QDomDocument createDescribeCoverageDocument(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request)
Create describe coverage document.
const QString GML_NAMESPACE
Definition qgswcsutils.h:64