Skip to content
Permalink
Browse files

[MSSQL] Correctly set geometry type from geometry_columns table

  • Loading branch information
NathanW2 committed Jul 4, 2017
1 parent 1fc81d6 commit b5360f8dcfe6ae01a2f27444ff23bd4fb60d00fa
@@ -542,24 +542,19 @@ QgsMssqlLayerItem *QgsMssqlSchemaItem::addLayer( const QgsMssqlLayerProperty &la
QString tip = tr( "%1 as %2 in %3" ).arg( layerProperty.geometryColName, QgsWkbTypes::displayString( wkbType ), layerProperty.srid );

QgsLayerItem::LayerType layerType;
switch ( wkbType )
QgsWkbTypes::Type flatType = QgsWkbTypes::flatType( wkbType );
switch ( flatType )
{
case QgsWkbTypes::Point:
case QgsWkbTypes::Point25D:
case QgsWkbTypes::MultiPoint:
case QgsWkbTypes::MultiPoint25D:
layerType = QgsLayerItem::Point;
break;
case QgsWkbTypes::LineString:
case QgsWkbTypes::LineString25D:
case QgsWkbTypes::MultiLineString:
case QgsWkbTypes::MultiLineString25D:
layerType = QgsLayerItem::Line;
break;
case QgsWkbTypes::Polygon:
case QgsWkbTypes::Polygon25D:
case QgsWkbTypes::MultiPolygon:
case QgsWkbTypes::MultiPolygon25D:
layerType = QgsLayerItem::Polygon;
break;
default:
@@ -352,15 +352,15 @@ void QgsMssqlProvider::loadMetadata()

QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );
if ( !query.exec( QStringLiteral( "select f_geometry_column, coord_dimension, srid, geometry_type from geometry_columns where f_table_schema = '%1' and f_table_name = '%2'" ).arg( mSchemaName, mTableName ) ) )
if ( !query.exec( QStringLiteral( "select f_geometry_column, srid, geometry_type from geometry_columns where f_table_schema = '%1' and f_table_name = '%2'" ).arg( mSchemaName, mTableName ) ) )
{
QgsDebugMsg( query.lastError().text() );
}
if ( query.isActive() && query.next() )
{
mGeometryColName = query.value( 0 ).toString();
mSRId = query.value( 2 ).toInt();
mWkbType = getWkbType( query.value( 3 ).toString(), query.value( 1 ).toInt() );
mSRId = query.value( 1 ).toInt();
mWkbType = getWkbType( query.value( 2 ).toString() );
}
}

@@ -1658,42 +1658,9 @@ void QgsMssqlProvider::mssqlWkbTypeAndDimension( QgsWkbTypes::Type wkbType, QStr
dim = 0;
}

QgsWkbTypes::Type QgsMssqlProvider::getWkbType( const QString &geometryType, int dim )
QgsWkbTypes::Type QgsMssqlProvider::getWkbType( const QString &geometryType )
{
if ( dim == 3 )
{
if ( geometryType == QLatin1String( "POINT" ) )
return QgsWkbTypes::Point25D;
if ( geometryType == QLatin1String( "LINESTRING" ) )
return QgsWkbTypes::LineString25D;
if ( geometryType == QLatin1String( "POLYGON" ) )
return QgsWkbTypes::Polygon25D;
if ( geometryType == QLatin1String( "MULTIPOINT" ) )
return QgsWkbTypes::MultiPoint25D;
if ( geometryType == QLatin1String( "MULTILINESTRING" ) )
return QgsWkbTypes::MultiLineString25D;
if ( geometryType == QLatin1String( "MULTIPOLYGON" ) )
return QgsWkbTypes::MultiPolygon25D;
else
return QgsWkbTypes::Unknown;
}
else
{
if ( geometryType == QLatin1String( "POINT" ) )
return QgsWkbTypes::Point;
if ( geometryType == QLatin1String( "LINESTRING" ) )
return QgsWkbTypes::LineString;
if ( geometryType == QLatin1String( "POLYGON" ) )
return QgsWkbTypes::Polygon;
if ( geometryType == QLatin1String( "MULTIPOINT" ) )
return QgsWkbTypes::MultiPoint;
if ( geometryType == QLatin1String( "MULTILINESTRING" ) )
return QgsWkbTypes::MultiLineString;
if ( geometryType == QLatin1String( "MULTIPOLYGON" ) )
return QgsWkbTypes::MultiPolygon;
else
return QgsWkbTypes::Unknown;
}
return QgsWkbTypes::parseType( geometryType );
}


@@ -213,7 +213,7 @@ class QgsMssqlProvider : public QgsVectorDataProvider
}

static void mssqlWkbTypeAndDimension( QgsWkbTypes::Type wkbType, QString &geometryType, int &dim );
static QgsWkbTypes::Type getWkbType( const QString &wkbType, int dim );
static QgsWkbTypes::Type getWkbType( const QString &wkbType );

friend class QgsMssqlFeatureSource;

@@ -397,61 +397,5 @@ QString QgsMssqlTableModel::layerURI( const QModelIndex &index, const QString &c
QgsWkbTypes::Type QgsMssqlTableModel::wkbTypeFromMssql( QString type )
{
type = type.toUpper();

if ( type == QLatin1String( "POINT" ) )
{
return QgsWkbTypes::Point;
}
else if ( type == QLatin1String( "POINTM" ) )
{
return QgsWkbTypes::Point25D;
}
else if ( type == QLatin1String( "MULTIPOINT" ) )
{
return QgsWkbTypes::MultiPoint;
}
else if ( type == QLatin1String( "MULTIPOINTM" ) )
{
return QgsWkbTypes::MultiPoint25D;
}
else if ( type == QLatin1String( "LINESTRING" ) )
{
return QgsWkbTypes::LineString;
}
else if ( type == QLatin1String( "LINESTRINGM" ) )
{
return QgsWkbTypes::LineString25D;
}
else if ( type == QLatin1String( "MULTILINESTRING" ) )
{
return QgsWkbTypes::MultiLineString;
}
else if ( type == QLatin1String( "MULTILINESTRINGM" ) )
{
return QgsWkbTypes::MultiLineString25D;
}
else if ( type == QLatin1String( "POLYGON" ) )
{
return QgsWkbTypes::Polygon;
}
else if ( type == QLatin1String( "POLYGONM" ) )
{
return QgsWkbTypes::Polygon25D;
}
else if ( type == QLatin1String( "MULTIPOLYGON" ) )
{
return QgsWkbTypes::MultiPolygon;
}
else if ( type == QLatin1String( "MULTIPOLYGONM" ) )
{
return QgsWkbTypes::MultiPolygon25D;
}
else if ( type == QLatin1String( "NONE" ) )
{
return QgsWkbTypes::NoGeometry;
}
else
{
return QgsWkbTypes::Unknown;
}
return QgsWkbTypes::parseType( type );
}

0 comments on commit b5360f8

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