Skip to content

Commit

Permalink
WFS-T Apply axis inversion logic
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Oct 16, 2020
1 parent fd43194 commit 785854c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/core/qgsogcutils.cpp
Expand Up @@ -1173,7 +1173,8 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry &geometry, QDomDocumen
return geometryToGML( geometry, doc, ( format == QLatin1String( "GML2" ) ) ? GML_2_1_2 : GML_3_2_1, QString(), false, QString(), precision );
}

QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry &geometry, QDomDocument &doc,
QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry &geometry,
QDomDocument &doc,
GMLVersion gmlVersion,
const QString &srsName,
bool invertAxisOrientation,
Expand Down
3 changes: 2 additions & 1 deletion src/providers/wfs/qgswfsdatasourceuri.cpp
Expand Up @@ -376,7 +376,8 @@ bool QgsWFSDataSourceURI::hideDownloadProgressDialog() const

bool QgsWFSDataSourceURI::preferCoordinatesForWfst11() const
{
return mURI.hasParam( QgsWFSConstants::URI_PARAM_WFST_1_1_PREFER_COORDINATES );
return mURI.hasParam( QgsWFSConstants::URI_PARAM_WFST_1_1_PREFER_COORDINATES ) &&
mURI.param( QgsWFSConstants::URI_PARAM_WFST_1_1_PREFER_COORDINATES ).toUpper() == QLatin1String( "TRUE" );
}

QString QgsWFSDataSourceURI::build( const QString &baseUri,
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wfs/qgswfsdatasourceuri.h
Expand Up @@ -113,7 +113,7 @@ class QgsWFSDataSourceURI
//! Whether to hide download progress dialog in QGIS main app. Defaults to false
bool hideDownloadProgressDialog() const;

//! Whether to use "ccordinates" instead of "pos" and "posList" for WFS-T 1.1 transactions (ESRI mapserver)
//! Whether to use "coordinates" instead of "pos" and "posList" for WFS-T 1.1 transactions (ESRI mapserver)
bool preferCoordinatesForWfst11() const;

//! Returns authorization parameters
Expand Down
70 changes: 46 additions & 24 deletions src/providers/wfs/qgswfsprovider.cpp
Expand Up @@ -787,6 +787,46 @@ void QgsWFSProvider::reloadProviderData()
mShared->invalidateCache();
}

QDomElement QgsWFSProvider::geometryElement( const QgsGeometry &geometry, QDomDocument &transactionDoc )
{
QDomElement gmlElem;

// Determine axis orientation and gml version
bool applyAxisInversion;
QgsOgcUtils::GMLVersion gmlVersion;

if ( mShared->mWFSVersion.startsWith( QLatin1String( "1.1" ) ) )
{
// WFS 1.1.0 uses preferably GML 3, but ESRI mapserver in 2020 doesn't like it so we stick to GML2
if ( ! mShared->mServerPrefersCoordinatesForTransactions_1_1 )
{
gmlVersion = QgsOgcUtils::GML_3_1_0;
}
else
{
gmlVersion = QgsOgcUtils::GML_2_1_2;
}
applyAxisInversion = ( crs().hasAxisInverted() && ! mShared->mURI.ignoreAxisOrientation() )
|| mShared->mURI.invertAxisOrientation();
}
else // 1.0
{
gmlVersion = QgsOgcUtils::GML_2_1_2;
applyAxisInversion = mShared->mURI.invertAxisOrientation();
}

gmlElem = QgsOgcUtils::geometryToGML(
geometry,
transactionDoc,
gmlVersion,
crs().authid(),
applyAxisInversion,
QString()
);

return gmlElem;
}

QgsWkbTypes::Type QgsWFSProvider::wkbType() const
{
return mShared->mWKBType;
Expand Down Expand Up @@ -877,19 +917,10 @@ bool QgsWFSProvider::addFeatures( QgsFeatureList &flist, Flags flags )
{
the_geom.convertToMultiType();
}
QDomElement gmlElem;
// WFS 1.1.0 uses preferably GML 3, but ESRI mapserver in 2020 doesn't like it so we stick to GML2
if ( mShared->mWFSVersion == QStringLiteral( "1.1.0" ) && ! mShared->mServerPrefersCoordinatesForTransactions_1_1 )
{
gmlElem = QgsOgcUtils::geometryToGML( the_geom, transactionDoc, QLatin1String( "GML3" ) );
}
else
{
gmlElem = QgsOgcUtils::geometryToGML( the_geom, transactionDoc, QLatin1String( "GML2" ) );
}
if ( !gmlElem.isNull() )

const QDomElement gmlElem { geometryElement( the_geom, transactionDoc ) };
if ( ! gmlElem.isNull() )
{
gmlElem.setAttribute( QStringLiteral( "srsName" ), crs().authid() );
geomElem.appendChild( gmlElem );
featureElem.appendChild( geomElem );
}
Expand Down Expand Up @@ -1054,18 +1085,9 @@ bool QgsWFSProvider::changeGeometryValues( const QgsGeometryMap &geometry_map )
nameElem.appendChild( nameText );
propertyElem.appendChild( nameElem );
QDomElement valueElem = transactionDoc.createElementNS( QgsWFSConstants::WFS_NAMESPACE, QStringLiteral( "Value" ) );
QDomElement gmlElem;
// WFS 1.1.0 uses preferably GML 3, but ESRI mapserver in 2020 doesn't like it so we stick to GML2
if ( mShared->mWFSVersion == QStringLiteral( "1.1.0" ) && ! mShared->mServerPrefersCoordinatesForTransactions_1_1 )
{
gmlElem = QgsOgcUtils::geometryToGML( geomIt.value(), transactionDoc, QLatin1String( "GML3" ) );
}
else
{
gmlElem = QgsOgcUtils::geometryToGML( geomIt.value(), transactionDoc, QLatin1String( "GML2" ) );
}
gmlElem.setAttribute( QStringLiteral( "srsName" ), crs().authid() );
valueElem.appendChild( gmlElem );

valueElem.appendChild( geometryElement( geomIt.value(), transactionDoc ) );

propertyElem.appendChild( valueElem );
updateElem.appendChild( propertyElem );

Expand Down
5 changes: 5 additions & 0 deletions src/providers/wfs/qgswfsprovider.h
Expand Up @@ -140,6 +140,11 @@ class QgsWFSProvider final: public QgsVectorDataProvider

friend class QgsWFSFeatureSource;

/**
* Create the geometry element
*/
QDomElement geometryElement( const QgsGeometry &geometry, QDomDocument &transactionDoc );

protected:

//! String used to define a subset of the layer
Expand Down
Binary file modified tests/testdata/qgis_server/test_project_wms_grouped_layers.gpkg
Binary file not shown.

0 comments on commit 785854c

Please sign in to comment.