33using namespace Qt::StringLiterals;
38 : wfsParameters( wfsParams )
45#ifdef HAVE_SERVER_PYTHON_PLUGINS
49 const QDomDocument *describeDocument =
nullptr;
51#ifdef HAVE_SERVER_PYTHON_PLUGINS
53 if ( cacheManager && cacheManager->
getCachedDocument( &doc, project, request, accessControl ) )
55 describeDocument = &doc;
59 doc = createDescribeFeatureTypeDocument( serverIface, project, version, request );
65 describeDocument = &doc;
68 doc = createDescribeFeatureTypeDocument( serverIface, project, version, request );
69 describeDocument = &doc;
71 response.
setHeader(
"Content-Type",
"text/xml; charset=utf-8" );
72 response.
write( describeDocument->toByteArray() );
82#ifdef HAVE_SERVER_PYTHON_PLUGINS
91 QDomElement schemaElement = doc.createElement( u
"schema"_s );
92 schemaElement.setAttribute( u
"xmlns"_s, u
"http://www.w3.org/2001/XMLSchema"_s );
93 schemaElement.setAttribute( u
"xmlns:xsd"_s, u
"http://www.w3.org/2001/XMLSchema"_s );
97 schemaElement.setAttribute( u
"targetNamespace"_s,
QGS_NAMESPACE );
98 schemaElement.setAttribute( u
"elementFormDefault"_s, u
"qualified"_s );
99 schemaElement.setAttribute( u
"version"_s, u
"1.0"_s );
100 doc.appendChild( schemaElement );
103 QDomElement importElement = doc.createElement( u
"import"_s );
106 importElement.setAttribute( u
"schemaLocation"_s, u
"http://schemas.opengis.net/gml/2.1.2/feature.xsd"_s );
108 importElement.setAttribute( u
"schemaLocation"_s, u
"http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"_s );
109 schemaElement.appendChild( importElement );
114 for (
int i = 0; i < wfsLayerIds.size(); ++i )
124 if ( !typeNameList.isEmpty() && !typeNameList.contains( name ) )
128#ifdef HAVE_SERVER_PYTHON_PLUGINS
131 if ( !typeNameList.isEmpty() )
133 throw QgsSecurityAccessException( u
"Feature access permission denied"_s );
141 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );
142 QgsVectorDataProvider *provider = vLayer->
dataProvider();
147 setSchemaLayer( schemaElement, doc,
const_cast<QgsVectorLayer *
>( vLayer ) );
152void QgsWfsDescribeFeatureTypeGml::setSchemaLayer( QDomElement &parentElement, QDomDocument &doc,
const QgsVectorLayer *layer )
const
154 const QgsVectorDataProvider *provider = layer->
dataProvider();
163 QDomElement elementElem = doc.createElement( u
"element"_s );
164 elementElem.setAttribute( u
"name"_s, typeName );
165 elementElem.setAttribute( u
"type"_s,
"qgs:" + typeName +
"Type" );
166 elementElem.setAttribute( u
"substitutionGroup"_s, u
"gml:_Feature"_s );
167 parentElement.appendChild( elementElem );
170 QDomElement complexTypeElem = doc.createElement( u
"complexType"_s );
171 complexTypeElem.setAttribute( u
"name"_s, typeName +
"Type" );
172 parentElement.appendChild( complexTypeElem );
175 QDomElement complexContentElem = doc.createElement( u
"complexContent"_s );
176 complexTypeElem.appendChild( complexContentElem );
179 QDomElement extensionElem = doc.createElement( u
"extension"_s );
180 extensionElem.setAttribute( u
"base"_s, u
"gml:AbstractFeatureType"_s );
181 complexContentElem.appendChild( extensionElem );
184 QDomElement sequenceElem = doc.createElement( u
"sequence"_s );
185 extensionElem.appendChild( sequenceElem );
190 QDomElement geomElem = doc.createElement( u
"element"_s );
191 geomElem.setAttribute( u
"name"_s, u
"geometry"_s );
192 geomElem.setAttribute( u
"type"_s, getGmlGeometryType( layer ) );
193 geomElem.setAttribute( u
"minOccurs"_s, u
"0"_s );
194 geomElem.setAttribute( u
"maxOccurs"_s, u
"1"_s );
195 sequenceElem.appendChild( geomElem );
199 const QgsFields fields = layer->
fields();
201 for (
int idx = 0; idx < fields.
count(); ++idx )
203 const QgsField field = fields.
at( idx );
210 QString attributeName, attributeType;
216 QDomElement attElem = doc.createElement( u
"element"_s );
218 attElem.setAttribute( u
"name"_s, attributeName );
219 attElem.setAttribute( u
"type"_s, attributeType );
223 attElem.setAttribute( u
"nillable"_s, u
"true"_s );
226 sequenceElem.appendChild( attElem );
228 const QString alias = field.
alias();
229 if ( !alias.isEmpty() )
231 attElem.setAttribute( u
"alias"_s, alias );
236QString QgsWfsDescribeFeatureTypeGml::getGmlGeometryType(
const QgsVectorLayer *layer )
const
239 switch ( wfsParameters.outputFormat() )
241 case QgsWfsParameters::Format::GML2:
247 return u
"gml:PointPropertyType"_s;
252 return u
"gml:LineStringPropertyType"_s;
257 return u
"gml:PolygonPropertyType"_s;
262 return u
"gml:MultiPointPropertyType"_s;
269 return u
"gml:MultiLineStringPropertyType"_s;
276 return u
"gml:MultiPolygonPropertyType"_s;
279 return u
"gml:GeometryPropertyType"_s;
281 case QgsWfsParameters::Format::GML3:
287 return u
"gml:PointPropertyType"_s;
292 return u
"gml:LineStringPropertyType"_s;
297 return u
"gml:PolygonPropertyType"_s;
301 return u
"gml:MultiPointPropertyType"_s;
308 return u
"gml:MultiCurvePropertyType"_s;
314 return u
"gml:MultiSurfacePropertyType"_s;
317 return u
"gml:GeometryPropertyType"_s;
320 return u
"gml:GeometryPropertyType"_s;
WkbType
The WKB type describes the number of dimensions a geometry has.
@ LineString25D
LineString25D.
@ MultiPointZ
MultiPointZ.
@ MultiPolygon25D
MultiPolygon25D.
@ MultiLineString25D
MultiLineString25D.
@ MultiPolygon
MultiPolygon.
@ MultiSurfaceZ
MultiSurfaceZ.
@ MultiLineString
MultiLineString.
@ MultiPoint25D
MultiPoint25D.
@ MultiLineStringZ
MultiLineStringZ.
@ MultiPolygonZ
MultiPolygonZ.
@ MultiCurveZ
MultiCurveZ.
@ LineStringZ
LineStringZ.
@ MultiSurface
MultiSurface.
@ HideFromWfs
Field is not available if layer is served as WFS from QGIS server.
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.
@ ConstraintNotNull
Field may not be null.
Qgis::FieldConfigurationFlags configurationFlags
QgsFieldConstraints constraints
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
QString wfsTypeName() const
Returns WFS typename for the layer.
Base class for all map layer types.
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
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.
Defines 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.
static QStringList wfsLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published in WFS.
Defines requests passed to QgsService classes.
Defines the response interface passed to QgsService.
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...
Represents a vector layer which manages a vector based dataset.
bool isSpatial() const final
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
Q_INVOKABLE Qgis::WkbType wkbType() const final
Returns the WKBType or WKBUnknown in case of error.
QgsVectorDataProvider * dataProvider() final
Returns the layer's data provider, it may be nullptr.
void writeDescribeFeatureType(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response) const
Output GML response.
QgsWfsDescribeFeatureTypeGml(const QgsWfs::QgsWfsParameters wfsParams)
Constructor.
Provides an interface to retrieve and manipulate WFS parameters received from the client.
Format outputFormat() const
Returns format.
void getFieldAttributes(const QgsField &field, QString &fieldName, QString &fieldType)
Helper for returning the field type and type name.
const QString QGS_NAMESPACE
QStringList getRequestTypeNames(const QgsServerRequest &request, const QgsWfsParameters &wfsParams)
Helper for returning typename list from the request.