Skip to content

Commit

Permalink
Detect geometries with Z and M values in HANA provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksim Rylov authored and mrylov committed Dec 7, 2020
1 parent 16eb692 commit 9894ac8
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 13 deletions.
11 changes: 6 additions & 5 deletions src/providers/hana/qgshanaconnection.cpp
Expand Up @@ -565,7 +565,7 @@ QgsWkbTypes::Type QgsHanaConnection::getLayerGeometryType( const QgsHanaLayerPro

QgsWkbTypes::Type ret;

QString sql = QStringLiteral( "SELECT upper(%1.ST_GeometryType()) AS geom_type FROM %2.%3 "
QString sql = QStringLiteral( "SELECT upper(%1.ST_GeometryType()), %1.ST_Is3D(), %1.ST_IsMeasured() FROM %2.%3 "
"WHERE %1 IS NOT NULL LIMIT %4" ).arg(
QgsHanaUtils::quotedIdentifier( layerProperty.geometryColName ),
QgsHanaUtils::quotedIdentifier( layerProperty.schemaName ),
Expand All @@ -575,11 +575,12 @@ QgsWkbTypes::Type QgsHanaConnection::getLayerGeometryType( const QgsHanaLayerPro
try
{
StatementRef stmt = mConnection->createStatement();
ResultSetRef rsGeomType = stmt->executeQuery( reinterpret_cast<const char16_t *>( sql.utf16() ) );
ResultSetRef rsGeomInfo = stmt->executeQuery( reinterpret_cast<const char16_t *>( sql.utf16() ) );
QgsWkbTypes::Type geomType = QgsWkbTypes::Unknown, prevGeomType = QgsWkbTypes::Unknown;
while ( rsGeomType->next() )
while ( rsGeomInfo->next() )
{
geomType = QgsWkbTypes::singleType( QgsHanaUtils::toWkbType( rsGeomType->getString( 1 )->c_str() ) );
geomType = QgsWkbTypes::singleType( QgsHanaUtils::toWkbType(
rsGeomInfo->getString( 1 ), rsGeomInfo->getInt( 2 ), rsGeomInfo->getInt( 3 ) ) );
if ( prevGeomType != QgsWkbTypes::Unknown && geomType != prevGeomType )
{
geomType = QgsWkbTypes::Unknown;
Expand All @@ -588,7 +589,7 @@ QgsWkbTypes::Type QgsHanaConnection::getLayerGeometryType( const QgsHanaLayerPro
prevGeomType = geomType;
}
ret = geomType;
rsGeomType->close();
rsGeomInfo->close();
}
catch ( const Exception &ex )
{
Expand Down
85 changes: 78 additions & 7 deletions src/providers/hana/qgshanautils.cpp
Expand Up @@ -266,24 +266,95 @@ QVariant QgsHanaUtils::toVariant( const Binary &value )
return QByteArray( value->data(), static_cast<int>( value->size() ) );
}

QgsWkbTypes::Type QgsHanaUtils::toWkbType( const QString &hanaType )
QgsWkbTypes::Type QgsHanaUtils::toWkbType( const odbc::String &type, const odbc::Int &hasZ, const odbc::Int &hasM )
{
if ( type.isNull() )
return QgsWkbTypes::Unknown;

bool hasZValue = hasZ.isNull() ? false : *hasZ == 1;
bool hasMValue = hasM.isNull() ? false : *hasM == 1;
QString hanaType( type->c_str() );

if ( hanaType == QStringLiteral( "ST_POINT" ) )
return QgsWkbTypes::Type::Point;
{
if ( hasZValue && hasMValue )
return QgsWkbTypes::PointZM;
if ( hasZValue )
return QgsWkbTypes::PointZ;
if ( hasMValue )
return QgsWkbTypes::PointM;
return QgsWkbTypes::Point;
}
else if ( hanaType == QStringLiteral( "ST_MULTIPOINT" ) )
return QgsWkbTypes::Type::MultiPoint;
{
if ( hasZValue && hasMValue )
return QgsWkbTypes::MultiPointZM;
if ( hasZValue )
return QgsWkbTypes::MultiPointZ;
if ( hasMValue )
return QgsWkbTypes::MultiPointM;
return QgsWkbTypes::MultiPoint;
}
else if ( hanaType == QStringLiteral( "ST_LINESTRING" ) )
return QgsWkbTypes::Type::LineString;
{
if ( hasZValue && hasMValue )
return QgsWkbTypes::LineStringZM;
if ( hasZValue )
return QgsWkbTypes::LineStringZ;
if ( hasMValue )
return QgsWkbTypes::LineStringM;
return QgsWkbTypes::LineString;
}
else if ( hanaType == QStringLiteral( "ST_MULTILINESTRING" ) )
return QgsWkbTypes::Type::MultiLineString;
{
if ( hasZValue && hasMValue )
return QgsWkbTypes::MultiLineStringZM;
if ( hasZValue )
return QgsWkbTypes::MultiLineStringZ;
if ( hasMValue )
return QgsWkbTypes::MultiLineStringM;
return QgsWkbTypes::MultiLineString;
}
else if ( hanaType == QStringLiteral( "ST_POLYGON" ) )
return QgsWkbTypes::Type::Polygon;
{
if ( hasZValue && hasMValue )
return QgsWkbTypes::PolygonZM;
if ( hasZValue )
return QgsWkbTypes::PolygonZ;
if ( hasMValue )
return QgsWkbTypes::PolygonM;
return QgsWkbTypes::Polygon;
}
else if ( hanaType == QStringLiteral( "ST_MULTIPOLYGON" ) )
return QgsWkbTypes::Type::MultiPolygon;
{
if ( hasZValue && hasMValue )
return QgsWkbTypes::MultiPolygonZM;
if ( hasZValue )
return QgsWkbTypes::MultiPolygonZ;
if ( hasMValue )
return QgsWkbTypes::MultiPolygonM;
return QgsWkbTypes::MultiPolygon;
}
else if ( hanaType == QStringLiteral( "ST_GEOMETRYCOLLECTION" ) )
{
if ( hasZValue && hasMValue )
return QgsWkbTypes::GeometryCollectionZM;
if ( hasZValue )
return QgsWkbTypes::GeometryCollectionZ;
if ( hasMValue )
return QgsWkbTypes::GeometryCollectionM;
return QgsWkbTypes::Type::GeometryCollection;
}
else if ( hanaType == QStringLiteral( "ST_CIRCULARSTRING" ) )
{
if ( hasZValue && hasMValue )
return QgsWkbTypes::CircularStringZM;
if ( hasZValue )
return QgsWkbTypes::CircularStringZ;
if ( hasMValue )
return QgsWkbTypes::CircularStringM;
return QgsWkbTypes::Type::CircularString;
}

return QgsWkbTypes::Type::Unknown;
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/hana/qgshanautils.h
Expand Up @@ -64,7 +64,7 @@ class QgsHanaUtils
return QVariant( *value );
}

static QgsWkbTypes::Type toWkbType( const QString &hanaType );
static QgsWkbTypes::Type toWkbType( const odbc::String &type, const odbc::Int &hasZ, const odbc::Int &hasM );
static QVersionNumber toHANAVersion( const QString &dbVersion );
static int toPlanarSRID( int srid );
static bool convertField( QgsField &field );
Expand Down

0 comments on commit 9894ac8

Please sign in to comment.