29#include <QJsonDocument>
35 : wfsParameters( wfsParams )
40 const QJsonDocument doc( createDescribeFeatureTypeDocument( serverIface, project, version, request ) );
42 response.
setHeader(
"Content-Type",
"application/vnd.geo+json; charset=utf-8" );
43 response.
write( doc.toJson( QJsonDocument::Compact ) );
52#ifdef HAVE_SERVER_PYTHON_PLUGINS
59 json[QStringLiteral(
"elementFormDefault" )] = QStringLiteral(
"qualified" );
61 json[QStringLiteral(
"targetPrefix" )] = QStringLiteral(
"qgs" );
63 QJsonArray featureTypes;
68 for (
int i = 0; i < wfsLayerIds.size(); ++i )
78 if ( !typeNameList.isEmpty() && !typeNameList.contains( name ) )
82#ifdef HAVE_SERVER_PYTHON_PLUGINS
83 if ( accessControl && !accessControl->layerReadPermission( layer ) )
85 if ( !typeNameList.isEmpty() )
87 throw QgsSecurityAccessException( QStringLiteral(
"Feature access permission denied" ) );
95 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );
96 QgsVectorDataProvider *provider = vLayer->
dataProvider();
102 featureTypes.append( schemaLayerToJson(
const_cast<QgsVectorLayer *
>( vLayer ) ) );
105 json[QStringLiteral(
"featureTypes" )] = featureTypes;
109QJsonObject QgsWfsDescribeFeatureTypeJson::schemaLayerToJson(
const QgsVectorLayer *layer )
const
114 QJsonArray properties;
116 json[QStringLiteral(
"typeName" )] = typeName;
120 QString geomType, geomLocalType;
121 getGeometryType( layer, geomType, geomLocalType );
123 QJsonObject property;
124 property[QStringLiteral(
"name" )] = QStringLiteral(
"geometry" );
125 property[QStringLiteral(
"minOccurs" )] = QStringLiteral(
"0" );
126 property[QStringLiteral(
"maxOccurs" )] = QStringLiteral(
"1" );
127 property[QStringLiteral(
"type" )] = geomType;
130 if ( !geomLocalType.isEmpty() )
132 property[QStringLiteral(
"localType" )] = geomLocalType;
134 properties.append( property );
138 const QgsFields fields = layer->
fields();
140 for (
int idx = 0; idx < fields.
count(); ++idx )
142 const QgsField field = fields.
at( idx );
149 QString attributeName, attributeType;
154 QJsonObject property;
155 property[QStringLiteral(
"name" )] = attributeName;
156 property[QStringLiteral(
"type" )] = attributeType;
157 property[QStringLiteral(
"localType" )] = attributeType;
161 property[QStringLiteral(
"nillable" )] =
"true";
164 const QString alias = field.
alias();
165 if ( !alias.isEmpty() )
167 property[QStringLiteral(
"alias" )] = alias;
170 properties.append( property );
173 json[QStringLiteral(
"properties" )] = properties;
177void QgsWfsDescribeFeatureTypeJson::getGeometryType(
const QgsVectorLayer *layer, QString &geomType, QString &geomLocalType )
const
184 geomType = QStringLiteral(
"gml:PointPropertyType" );
185 geomLocalType = QStringLiteral(
"Point" );
190 geomType = QStringLiteral(
"gml:LineStringPropertyType" );
191 geomLocalType = QStringLiteral(
"LineString" );
196 geomType = QStringLiteral(
"gml:PolygonPropertyType" );
197 geomLocalType = QStringLiteral(
"Polygon" );
202 geomType = QStringLiteral(
"gml:MultiPointPropertyType" );
203 geomLocalType = QStringLiteral(
"MultiPoint" );
209 geomType = QStringLiteral(
"gml:MultiCurvePropertyType" );
210 geomLocalType = QStringLiteral(
"MultiCurve" );
216 geomType = QStringLiteral(
"gml:MultiSurfacePropertyType" );
217 geomLocalType = QStringLiteral(
"MultiSurface" );
221 geomType = QStringLiteral(
"gml:GeometryPropertyType" );
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.