29#include <QJsonDocument>
33using namespace Qt::StringLiterals;
38 : wfsParameters( wfsParams )
43 const QJsonDocument doc( createDescribeFeatureTypeDocument( serverIface, project, version, request ) );
45 response.
setHeader(
"Content-Type",
"application/vnd.geo+json; charset=utf-8" );
46 response.
write( doc.toJson( QJsonDocument::Compact ) );
55#ifdef HAVE_SERVER_PYTHON_PLUGINS
62 json[u
"elementFormDefault"_s] = u
"qualified"_s;
64 json[u
"targetPrefix"_s] = u
"qgs"_s;
66 QJsonArray featureTypes;
71 for (
int i = 0; i < wfsLayerIds.size(); ++i )
81 if ( !typeNameList.isEmpty() && !typeNameList.contains( name ) )
85#ifdef HAVE_SERVER_PYTHON_PLUGINS
86 if ( accessControl && !accessControl->layerReadPermission( layer ) )
88 if ( !typeNameList.isEmpty() )
90 throw QgsSecurityAccessException( u
"Feature access permission denied"_s );
98 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );
99 QgsVectorDataProvider *provider = vLayer->
dataProvider();
105 featureTypes.append( schemaLayerToJson(
const_cast<QgsVectorLayer *
>( vLayer ) ) );
108 json[u
"featureTypes"_s] = featureTypes;
112QJsonObject QgsWfsDescribeFeatureTypeJson::schemaLayerToJson(
const QgsVectorLayer *layer )
const
117 QJsonArray properties;
119 json[u
"typeName"_s] = typeName;
123 QString geomType, geomLocalType;
124 getGeometryType( layer, geomType, geomLocalType );
126 QJsonObject property;
127 property[u
"name"_s] = u
"geometry"_s;
128 property[u
"minOccurs"_s] = u
"0"_s;
129 property[u
"maxOccurs"_s] = u
"1"_s;
130 property[u
"type"_s] = geomType;
133 if ( !geomLocalType.isEmpty() )
135 property[u
"localType"_s] = geomLocalType;
137 properties.append( property );
141 const QgsFields fields = layer->
fields();
143 for (
int idx = 0; idx < fields.
count(); ++idx )
145 const QgsField field = fields.
at( idx );
152 QString attributeName, attributeType;
157 QJsonObject property;
158 property[u
"name"_s] = attributeName;
159 property[u
"type"_s] = attributeType;
160 property[u
"localType"_s] = attributeType;
164 property[u
"nillable"_s] =
"true";
167 const QString alias = field.
alias();
168 if ( !alias.isEmpty() )
170 property[u
"alias"_s] = alias;
173 properties.append( property );
176 json[u
"properties"_s] = properties;
180void QgsWfsDescribeFeatureTypeJson::getGeometryType(
const QgsVectorLayer *layer, QString &geomType, QString &geomLocalType )
const
187 geomType = u
"gml:PointPropertyType"_s;
188 geomLocalType = u
"Point"_s;
193 geomType = u
"gml:LineStringPropertyType"_s;
194 geomLocalType = u
"LineString"_s;
199 geomType = u
"gml:PolygonPropertyType"_s;
200 geomLocalType = u
"Polygon"_s;
205 geomType = u
"gml:MultiPointPropertyType"_s;
206 geomLocalType = u
"MultiPoint"_s;
212 geomType = u
"gml:MultiCurvePropertyType"_s;
213 geomLocalType = u
"MultiCurve"_s;
219 geomType = u
"gml:MultiSurfacePropertyType"_s;
220 geomLocalType = u
"MultiSurface"_s;
224 geomType = u
"gml:GeometryPropertyType"_s;
WkbType
The WKB type describes the number of dimensions a geometry has.
@ LineString25D
LineString25D.
@ MultiPolygon25D
MultiPolygon25D.
@ MultiLineString25D
MultiLineString25D.
@ MultiPolygon
MultiPolygon.
@ MultiLineString
MultiLineString.
@ MultiPoint25D
MultiPoint25D.
@ 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.
@ 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.
Defines interfaces exposed by QGIS Server and made available to plugins.
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.
QgsWfsDescribeFeatureTypeJson(const QgsWfs::QgsWfsParameters wfsParams)
Constructor.
void writeDescribeFeatureType(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response) const
Output GeoJson response.
Provides an interface to retrieve and manipulate WFS parameters received from the client.
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.