29#include <QJsonDocument>
33using namespace Qt::StringLiterals;
38 : wfsParameters( wfsParams )
45 const QJsonDocument doc( createDescribeFeatureTypeDocument( serverIface, project, version, request ) );
47 response.
setHeader(
"Content-Type",
"application/vnd.geo+json; charset=utf-8" );
48 response.
write( doc.toJson( QJsonDocument::Compact ) );
57#ifdef HAVE_SERVER_PYTHON_PLUGINS
64 json[u
"elementFormDefault"_s] = u
"qualified"_s;
66 json[u
"targetPrefix"_s] = u
"qgs"_s;
68 QJsonArray featureTypes;
73 for (
int i = 0; i < wfsLayerIds.size(); ++i )
83 if ( !typeNameList.isEmpty() && !typeNameList.contains( name ) )
87#ifdef HAVE_SERVER_PYTHON_PLUGINS
88 if ( accessControl && !accessControl->layerReadPermission( layer ) )
90 if ( !typeNameList.isEmpty() )
92 throw QgsSecurityAccessException( u
"Feature access permission denied"_s );
100 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );
101 QgsVectorDataProvider *provider = vLayer->
dataProvider();
107 featureTypes.append( schemaLayerToJson(
const_cast<QgsVectorLayer *
>( vLayer ) ) );
110 json[u
"featureTypes"_s] = featureTypes;
114QJsonObject QgsWfsDescribeFeatureTypeJson::schemaLayerToJson(
const QgsVectorLayer *layer )
const
119 QJsonArray properties;
121 json[u
"typeName"_s] = typeName;
125 QString geomType, geomLocalType;
126 getGeometryType( layer, geomType, geomLocalType );
128 QJsonObject property;
129 property[u
"name"_s] = u
"geometry"_s;
130 property[u
"minOccurs"_s] = u
"0"_s;
131 property[u
"maxOccurs"_s] = u
"1"_s;
132 property[u
"type"_s] = geomType;
135 if ( !geomLocalType.isEmpty() )
137 property[u
"localType"_s] = geomLocalType;
139 properties.append( property );
143 const QgsFields fields = layer->
fields();
145 for (
int idx = 0; idx < fields.
count(); ++idx )
147 const QgsField field = fields.
at( idx );
154 QString attributeName, attributeType;
159 QJsonObject property;
160 property[u
"name"_s] = attributeName;
161 property[u
"type"_s] = attributeType;
162 property[u
"localType"_s] = attributeType;
166 property[u
"nillable"_s] =
"true";
169 const QString alias = field.
alias();
170 if ( !alias.isEmpty() )
172 property[u
"alias"_s] = alias;
175 properties.append( property );
178 json[u
"properties"_s] = properties;
182void QgsWfsDescribeFeatureTypeJson::getGeometryType(
const QgsVectorLayer *layer, QString &geomType, QString &geomLocalType )
const
189 geomType = u
"gml:PointPropertyType"_s;
190 geomLocalType = u
"Point"_s;
195 geomType = u
"gml:LineStringPropertyType"_s;
196 geomLocalType = u
"LineString"_s;
201 geomType = u
"gml:PolygonPropertyType"_s;
202 geomLocalType = u
"Polygon"_s;
207 geomType = u
"gml:MultiPointPropertyType"_s;
208 geomLocalType = u
"MultiPoint"_s;
214 geomType = u
"gml:MultiCurvePropertyType"_s;
215 geomLocalType = u
"MultiCurve"_s;
221 geomType = u
"gml:MultiSurfacePropertyType"_s;
222 geomLocalType = u
"MultiSurface"_s;
226 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.