QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
41 QStringList &layerList );
47 QDomDocument doc =
getStyles( serverIface, project, version, request );
48 response.
setHeader( QStringLiteral(
"Content-Type" ), QStringLiteral(
"text/xml; charset=utf-8" ) );
49 response.
write( doc.toByteArray() );
59 QString layersName = parameters.value(
"LAYERS" );
61 if ( layersName.isEmpty() )
67 QStringList layerList = layersName.split(
',', QString::SkipEmptyParts );
68 if ( layerList.isEmpty() )
74 return getStyledLayerDescriptorDocument( serverIface, project, layerList );
81 QDomDocument doc =
getStyle( serverIface, project, version, request );
82 response.
setHeader( QStringLiteral(
"Content-Type" ), QStringLiteral(
"text/xml; charset=utf-8" ) );
83 response.
write( doc.toByteArray() );
95 QString styleName = parameters.value( QStringLiteral(
"STYLE" ) );
96 QString layerName = parameters.value( QStringLiteral(
"LAYER" ) );
98 if ( styleName.isEmpty() )
104 if ( layerName.isEmpty() )
110 QStringList layerList;
111 layerList.append( layerName );
112 return getStyledLayerDescriptorDocument( serverIface, project, layerList );
118 QStringList &layerList )
120 QDomDocument myDocument = QDomDocument();
122 QDomNode header = myDocument.createProcessingInstruction( QStringLiteral(
"xml" ), QStringLiteral(
"version=\"1.0\" encoding=\"UTF-8\"" ) );
123 myDocument.appendChild( header );
126 QDomElement root = myDocument.createElementNS( QStringLiteral(
"http://www.opengis.net/sld" ), QStringLiteral(
"StyledLayerDescriptor" ) );
127 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.1.0" ) );
128 root.setAttribute( QStringLiteral(
"xsi:schemaLocation" ), QStringLiteral(
"http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" ) );
129 root.setAttribute( QStringLiteral(
"xmlns:ogc" ), QStringLiteral(
"http://www.opengis.net/ogc" ) );
130 root.setAttribute( QStringLiteral(
"xmlns:se" ), QStringLiteral(
"http://www.opengis.net/se" ) );
131 root.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
132 root.setAttribute( QStringLiteral(
"xmlns:xsi" ), QStringLiteral(
"http://www.w3.org/2001/XMLSchema-instance" ) );
133 myDocument.appendChild( root );
136 #ifdef HAVE_SERVER_PYTHON_PLUGINS
148 QString name = layer->name();
151 else if ( !layer->shortName().isEmpty() )
152 name = layer->shortName();
154 if ( !layerList.contains( name ) )
160 if ( restrictedLayers.contains( layer->name() ) )
162 throw QgsSecurityException( QStringLiteral(
"You are not allowed to access to this layer" ) );
164 #ifdef HAVE_SERVER_PYTHON_PLUGINS
167 throw QgsSecurityException( QStringLiteral(
"You are not allowed to access to this layer" ) );
171 QDomElement namedLayerNode = myDocument.createElement( QStringLiteral(
"NamedLayer" ) );
172 root.appendChild( namedLayerNode );
175 QDomElement nameNode = myDocument.createElement( QStringLiteral(
"se:Name" ) );
176 nameNode.appendChild( myDocument.createTextNode( name ) );
177 namedLayerNode.appendChild( nameNode );
189 props[ QStringLiteral(
"scaleMinDenom" ) ] = QString::number( vlayer->
maximumScale() );
190 props[ QStringLiteral(
"scaleMaxDenom" ) ] = QString::number( vlayer->
minimumScale() );
197 QDomElement userStyleElem = myDocument.createElement( QStringLiteral(
"UserStyle" ) );
199 QDomElement styleNameElem = myDocument.createElement( QStringLiteral(
"se:Name" ) );
200 styleNameElem.appendChild( myDocument.createTextNode( styleName ) );
202 userStyleElem.appendChild( styleNameElem );
204 QDomElement featureTypeStyleElem = myDocument.createElement( QStringLiteral(
"se:FeatureTypeStyle" ) );
205 userStyleElem.appendChild( featureTypeStyleElem );
207 vlayer->
renderer()->
toSld( myDocument, featureTypeStyleElem, props );
213 namedLayerNode.appendChild( userStyleElem );
QStringList styles() const
Returns list of all defined style names.
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
QDomDocument getStyle(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request)
Returns an SLD file with the style of the requested layer.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
bool layerReadPermission(const QgsMapLayer *layer) const
Returns the layer read right.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
virtual void toSld(QDomNode &parent, const QgsStringMap &props) const
Writes the SE 1.1 TextSymbolizer element based on the current layer labeling settings.
virtual void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props=QgsStringMap()) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
virtual QgsAccessControl * accessControls() const =0
Gets the registered access control filters.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
QMap< QString, QString > Parameters
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device.
SERVER_EXPORT bool wmsUseLayerIds(const QgsProject &project)
Returns if layer ids are used as name in WMS.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
SERVER_EXPORT QStringList wmsRestrictedLayers(const QgsProject &project)
Returns the restricted layer name list.
void writeGetStyle(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetStyle response.
@ QGIS_MissingParameterValue
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
double minimumScale() const
Returns the minimum map scale (i.e.
QString currentStyle() const
Returns name of the current style.
double maximumScale() const
Returns the maximum map scale (i.e.
QDomDocument getStyles(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request)
Returns an SLD file with the styles of the requested layers.
A helper class that centralizes restrictions given by all the access control filter plugins.
Median cut implementation.
QMap< QString, QString > QgsStringMap
Exception thrown in case of malformed request.
Represents a vector layer which manages a vector based data sets.
Base class for all map layer types.
bool setCurrentStyle(const QString &name)
Set a different style as the current style - will apply it to the layer.
void writeGetStyles(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetStyles response.
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
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...
QgsFeatureRenderer * renderer()
Returns renderer.