Skip to content
Permalink
Browse files

[BUGFIX][QGIS Server] WFS DescribeFeatureType Geometry element type

In the OGR provider, we can read:
```
Some ogr drivers (e.g. GML) are not able to determine the geometry type of a layer like this.
In such cases, we use virtual sublayers for each geometry if the layer contains
multiple geometries (see subLayers) otherwise we guess geometry type from first feature
```
It means that in DescribeFeatureType Geometry element can be describe as simple and the GML contains
simple and multi. It's not XML valid.
To fix it, for OGR provider Geometry element type is set to `gml:GeometryPropertyType`

For the next release, it will be interesting to allow users to specify whether the geometries are multi.
  • Loading branch information
rldhont committed Feb 25, 2016
1 parent 8fc5381 commit 36b0c3c10ab3a8d45f3733698f3e2b26f4391444
Showing with 54 additions and 44 deletions.
  1. +53 −43 src/server/qgswfsprojectparser.cpp
  2. +1 −1 tests/testdata/qgis_server/wfs_describefeaturetype.txt
@@ -400,40 +400,50 @@ void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomEle
extensionElem.appendChild( sequenceElem );

//xsd:element
QDomElement geomElem = doc.createElement( "element"/*xsd:element*/ );
geomElem.setAttribute( "name", "geometry" );
QGis::WkbType wkbType = layer->wkbType();
if ( wkbType != QGis::WKBNoGeometry )
if ( layer->hasGeometryType() )
{
switch ( wkbType )
QDomElement geomElem = doc.createElement( "element"/*xsd:element*/ );
geomElem.setAttribute( "name", "geometry" );
if ( provider->name() == "ogr" )
{
// because some ogr drivers (e.g. ESRI ShapeFile, GML)
// are not able to determine the geometry type of a layer.
// we set to GeometryType
geomElem.setAttribute( "type", "gml:GeometryPropertyType" );
}
else
{
case QGis::WKBPoint25D:
case QGis::WKBPoint:
geomElem.setAttribute( "type", "gml:PointPropertyType" );
break;
case QGis::WKBLineString25D:
case QGis::WKBLineString:
geomElem.setAttribute( "type", "gml:LineStringPropertyType" );
break;
case QGis::WKBPolygon25D:
case QGis::WKBPolygon:
geomElem.setAttribute( "type", "gml:PolygonPropertyType" );
break;
case QGis::WKBMultiPoint25D:
case QGis::WKBMultiPoint:
geomElem.setAttribute( "type", "gml:MultiPointPropertyType" );
break;
case QGis::WKBMultiLineString25D:
case QGis::WKBMultiLineString:
geomElem.setAttribute( "type", "gml:MultiLineStringPropertyType" );
break;
case QGis::WKBMultiPolygon25D:
case QGis::WKBMultiPolygon:
geomElem.setAttribute( "type", "gml:MultiPolygonPropertyType" );
break;
default:
geomElem.setAttribute( "type", "gml:GeometryPropertyType" );
break;
QGis::WkbType wkbType = layer->wkbType();
switch ( wkbType )
{
case QGis::WKBPoint25D:
case QGis::WKBPoint:
geomElem.setAttribute( "type", "gml:PointPropertyType" );
break;
case QGis::WKBLineString25D:
case QGis::WKBLineString:
geomElem.setAttribute( "type", "gml:LineStringPropertyType" );
break;
case QGis::WKBPolygon25D:
case QGis::WKBPolygon:
geomElem.setAttribute( "type", "gml:PolygonPropertyType" );
break;
case QGis::WKBMultiPoint25D:
case QGis::WKBMultiPoint:
geomElem.setAttribute( "type", "gml:MultiPointPropertyType" );
break;
case QGis::WKBMultiLineString25D:
case QGis::WKBMultiLineString:
geomElem.setAttribute( "type", "gml:MultiLineStringPropertyType" );
break;
case QGis::WKBMultiPolygon25D:
case QGis::WKBMultiPolygon:
geomElem.setAttribute( "type", "gml:MultiPolygonPropertyType" );
break;
default:
geomElem.setAttribute( "type", "gml:GeometryPropertyType" );
break;
}
}
geomElem.setAttribute( "minOccurs", "0" );
geomElem.setAttribute( "maxOccurs", "1" );
@@ -453,30 +463,30 @@ void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomEle
}

//xsd:element
QDomElement geomElem = doc.createElement( "element"/*xsd:element*/ );
geomElem.setAttribute( "name", attributeName );
QDomElement attElem = doc.createElement( "element"/*xsd:element*/ );
attElem.setAttribute( "name", attributeName );
QVariant::Type attributeType = fields[idx].type();
if ( attributeType == QVariant::Int )
geomElem.setAttribute( "type", "integer" );
attElem.setAttribute( "type", "integer" );
else if ( attributeType == QVariant::Double )
geomElem.setAttribute( "type", "double" );
attElem.setAttribute( "type", "double" );
else if ( attributeType == QVariant::Bool )
geomElem.setAttribute( "type", "boolean" );
attElem.setAttribute( "type", "boolean" );
else if ( attributeType == QVariant::Date )
geomElem.setAttribute( "type", "date" );
attElem.setAttribute( "type", "date" );
else if ( attributeType == QVariant::Time )
geomElem.setAttribute( "type", "time" );
attElem.setAttribute( "type", "time" );
else if ( attributeType == QVariant::DateTime )
geomElem.setAttribute( "type", "dateTime" );
attElem.setAttribute( "type", "dateTime" );
else
geomElem.setAttribute( "type", "string" );
attElem.setAttribute( "type", "string" );

sequenceElem.appendChild( geomElem );
sequenceElem.appendChild( attElem );

QString alias = layer->attributeAlias( idx );
if ( !alias.isEmpty() )
{
geomElem.setAttribute( "alias", alias );
attElem.setAttribute( "alias", alias );
}
}
}
@@ -8,7 +8,7 @@ Content-Type: text/xml; charset=utf-8
<complexContent>
<extension base="gml:AbstractFeatureType">
<sequence>
<element minOccurs="0" maxOccurs="1" type="gml:PointPropertyType" name="geometry"/>
<element minOccurs="0" maxOccurs="1" type="gml:GeometryPropertyType" name="geometry"/>
<element type="integer" name="id"/>
<element type="string" name="name"/>
<element type="string" name="utf8nameè"/>

0 comments on commit 36b0c3c

Please sign in to comment.
You can’t perform that action at this time.