29#include <QJsonDocument>
34 : 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 ) );
47QJsonObject QgsWfsDescribeFeatureTypeJson::createDescribeFeatureTypeDocument(
QgsServerInterface *serverIface,
const QgsProject *project,
const QString &version,
53#ifdef HAVE_SERVER_PYTHON_PLUGINS
60 json[QStringLiteral(
"elementFormDefault" )] = QStringLiteral(
"qualified" );
62 json[QStringLiteral(
"targetPrefix" )] = QStringLiteral(
"qgs" );
64 QJsonArray featureTypes;
69 for (
int i = 0; i < wfsLayerIds.size(); ++i )
79 if ( !typeNameList.isEmpty() && !typeNameList.contains( name ) )
83#ifdef HAVE_SERVER_PYTHON_PLUGINS
84 if ( accessControl && !accessControl->layerReadPermission( layer ) )
86 if ( !typeNameList.isEmpty() )
103 featureTypes.append( schemaLayerToJson(
const_cast<QgsVectorLayer *
>( vLayer ) ) );
106 json[QStringLiteral(
"featureTypes" )] = featureTypes;
110QJsonObject QgsWfsDescribeFeatureTypeJson::schemaLayerToJson(
const QgsVectorLayer *layer )
const
115 QJsonArray properties;
117 json[QStringLiteral(
"typeName" )] =
typeName;
121 QString geomType, geomLocalType;
122 getGeometryType( layer, geomType, geomLocalType );
124 QJsonObject property;
125 property[QStringLiteral(
"name" )] = QStringLiteral(
"geometry" );
126 property[QStringLiteral(
"minOccurs" )] = QStringLiteral(
"0" );
127 property[QStringLiteral(
"maxOccurs" )] = QStringLiteral(
"1" );
128 property[QStringLiteral(
"type" )] = geomType;
131 if ( !geomLocalType.isEmpty() )
133 property[QStringLiteral(
"localType" )] = geomLocalType;
135 properties.append( property );
141 for (
int idx = 0; idx < fields.
count(); ++idx )
150 QString attributeName, attributeType;
155 QJsonObject property;
156 property[QStringLiteral(
"name" )] = attributeName;
157 property[QStringLiteral(
"type" )] = attributeType;
158 property[QStringLiteral(
"localType" )] = attributeType;
162 property[QStringLiteral(
"nillable" )] =
"true";
165 const QString alias = field.
alias();
166 if ( !alias.isEmpty() )
168 property[QStringLiteral(
"alias" )] = alias;
171 properties.append( property );
174 json[QStringLiteral(
"properties" )] = properties;
178void QgsWfsDescribeFeatureTypeJson::getGeometryType(
const QgsVectorLayer *layer, QString &geomType, QString &geomLocalType )
const
185 geomType = QStringLiteral(
"gml:PointPropertyType" );
186 geomLocalType = QStringLiteral(
"Point" );
191 geomType = QStringLiteral(
"gml:LineStringPropertyType" );
192 geomLocalType = QStringLiteral(
"LineString" );
197 geomType = QStringLiteral(
"gml:PolygonPropertyType" );
198 geomLocalType = QStringLiteral(
"Polygon" );
203 geomType = QStringLiteral(
"gml:MultiPointPropertyType" );
204 geomLocalType = QStringLiteral(
"MultiPoint" );
210 geomType = QStringLiteral(
"gml:MultiCurvePropertyType" );
211 geomLocalType = QStringLiteral(
"MultiCurve" );
217 geomType = QStringLiteral(
"gml:MultiSurfacePropertyType" );
218 geomLocalType = QStringLiteral(
"MultiSurface" );
222 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.
Encapsulate a field in an attribute table or data source.
Qgis::FieldConfigurationFlags configurationFlags
QgsFieldConstraints constraints
Container of fields for a vector layer.
int count() const
Returns number of items.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Base class for all map layer types.
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.
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
virtual QgsAccessControl * accessControls() const =0
Gets the registered access control filters.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
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...
This is the base class for vector data providers.
Represents a vector layer which manages a vector based data sets.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
QgsFields fields() const FINAL
Returns the list of fields of this layer.
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.
Exception thrown when data access violates access controls.
Provides an interface to retrieve and manipulate WFS parameters received from the client.
SERVER_EXPORT QStringList wfsLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published in WFS.
QString layerTypeName(const QgsMapLayer *layer)
Returns typename from vector layer.
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.