Skip to content

Commit

Permalink
Fix and update mapping of ogr wkt types to QGIS wkb types
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 9, 2017
1 parent 6ed44ff commit f290109
Show file tree
Hide file tree
Showing 3 changed files with 301 additions and 55 deletions.
25 changes: 7 additions & 18 deletions src/providers/ogr/qgsogrdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,34 +361,23 @@ static QgsOgrLayerItem *dataItemForLayer( QgsDataItem *parentItem, QString name,

QgsLayerItem::LayerType layerType = QgsLayerItem::Vector;
OGRwkbGeometryType ogrType = QgsOgrProvider::getOgrGeomType( hLayer );
switch ( ogrType )
QgsWkbTypes::Type wkbType = QgsOgrProviderUtils::qgisTypeFromOgrType( ogrType );
switch ( QgsWkbTypes::geometryType( wkbType ) )
{
case wkbUnknown:
case wkbGeometryCollection:
case QgsWkbTypes::UnknownGeometry:
break;
case wkbNone:
case QgsWkbTypes::NullGeometry:
layerType = QgsLayerItem::TableLayer;
break;
case wkbPoint:
case wkbMultiPoint:
case wkbPoint25D:
case wkbMultiPoint25D:
case QgsWkbTypes::PointGeometry:
layerType = QgsLayerItem::Point;
break;
case wkbLineString:
case wkbMultiLineString:
case wkbLineString25D:
case wkbMultiLineString25D:
case QgsWkbTypes::LineGeometry:
layerType = QgsLayerItem::Line;
break;
case wkbPolygon:
case wkbMultiPolygon:
case wkbPolygon25D:
case wkbMultiPolygon25D:
case QgsWkbTypes::PolygonGeometry:
layerType = QgsLayerItem::Polygon;
break;
default:
break;
}

QgsDebugMsgLevel( QString( "ogrType = %1 layertype = %2" ).arg( ogrType ).arg( layerType ), 2 );
Expand Down
324 changes: 287 additions & 37 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2993,47 +2993,18 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
OGRwkbGeometryType OGRvectortype = wkbUnknown;
switch ( vectortype )
{
case QgsWkbTypes::Point:
OGRvectortype = wkbPoint;
break;
case QgsWkbTypes::Point25D:
OGRvectortype = wkbPoint25D;
break;
case QgsWkbTypes::LineString:
OGRvectortype = wkbLineString;
break;
case QgsWkbTypes::LineString25D:
OGRvectortype = wkbLineString25D;
break;
case QgsWkbTypes::Polygon:
OGRvectortype = wkbPolygon;
break;
case QgsWkbTypes::Polygon25D:
OGRvectortype = wkbPolygon25D;
break;
case QgsWkbTypes::MultiPoint:
OGRvectortype = wkbMultiPoint;
break;
case QgsWkbTypes::MultiPoint25D:
OGRvectortype = wkbMultiPoint25D;
break;
case QgsWkbTypes::MultiLineString:
OGRvectortype = wkbMultiLineString;
break;
case QgsWkbTypes::MultiLineString25D:
OGRvectortype = wkbMultiLineString25D;
break;
case QgsWkbTypes::MultiPolygon:
OGRvectortype = wkbMultiPolygon;
break;
case QgsWkbTypes::MultiPolygon25D:
OGRvectortype = wkbMultiPolygon25D;
break;
default:
case QgsWkbTypes::GeometryCollection:
case QgsWkbTypes::GeometryCollectionZ:
case QgsWkbTypes::GeometryCollectionM:
case QgsWkbTypes::GeometryCollectionZM:
case QgsWkbTypes::Unknown:
{
QgsMessageLog::logMessage( QObject::tr( "Unknown vector type of %1" ).arg( ( int )( vectortype ) ), QObject::tr( "OGR" ) );
return false;
}

default:
OGRvectortype = QgsOgrProviderUtils::ogrTypeFromQgisType( vectortype );
}

char **papszOptions = nullptr;
Expand Down Expand Up @@ -4390,6 +4361,285 @@ void QgsOgrProviderUtils::invalidateCachedLastModifiedDate( const QString &dsNam
}
}

OGRwkbGeometryType QgsOgrProviderUtils::ogrTypeFromQgisType( QgsWkbTypes::Type type )
{
switch ( type )
{
case QgsWkbTypes::Point:
return wkbPoint;
case QgsWkbTypes::Point25D:
case QgsWkbTypes::PointZ:
return wkbPoint25D;
case QgsWkbTypes::PointM:
return wkbPointM;
case QgsWkbTypes::PointZM:
return wkbPointZM;

case QgsWkbTypes::LineString:
return wkbLineString;
case QgsWkbTypes::LineString25D:
case QgsWkbTypes::LineStringZ:
return wkbLineString25D;
case QgsWkbTypes::LineStringM:
return wkbLineStringM;
case QgsWkbTypes::LineStringZM:
return wkbLineStringZM;

case QgsWkbTypes::Polygon:
return wkbPolygon;
case QgsWkbTypes::Polygon25D:
case QgsWkbTypes::PolygonZ:
return wkbPolygon25D;
case QgsWkbTypes::PolygonM:
return wkbPolygonM;
case QgsWkbTypes::PolygonZM:
return wkbPolygonZM;

case QgsWkbTypes::MultiPoint:
return wkbMultiPoint;
case QgsWkbTypes::MultiPoint25D:
case QgsWkbTypes::MultiPointZ:
return wkbMultiPoint25D;
case QgsWkbTypes::MultiPointM:
return wkbMultiPointM;
case QgsWkbTypes::MultiPointZM:
return wkbMultiPointZM;

case QgsWkbTypes::MultiLineString:
return wkbMultiLineString;
case QgsWkbTypes::MultiLineString25D:
case QgsWkbTypes::MultiLineStringZ:
return wkbMultiLineString25D;
case QgsWkbTypes::MultiLineStringM:
return wkbMultiLineStringM;
case QgsWkbTypes::MultiLineStringZM:
return wkbMultiLineStringZM;

case QgsWkbTypes::MultiPolygon:
return wkbMultiPolygon;
case QgsWkbTypes::MultiPolygon25D:
case QgsWkbTypes::MultiPolygonZ:
return wkbMultiPolygon25D;
case QgsWkbTypes::MultiPolygonM:
return wkbMultiPolygonM;
case QgsWkbTypes::MultiPolygonZM:
return wkbMultiPolygonZM;

case QgsWkbTypes::CircularString:
return wkbCircularString;
case QgsWkbTypes::CircularStringZ:
return wkbCircularStringZ;
case QgsWkbTypes::CircularStringM:
return wkbCircularStringM;
case QgsWkbTypes::CircularStringZM:
return wkbCircularStringZM;

case QgsWkbTypes::CompoundCurve:
return wkbCompoundCurve;
case QgsWkbTypes::CompoundCurveZ:
return wkbCompoundCurveZ;
case QgsWkbTypes::CompoundCurveM:
return wkbCompoundCurveM;
case QgsWkbTypes::CompoundCurveZM:
return wkbCompoundCurveZM;

case QgsWkbTypes::CurvePolygon:
return wkbCurvePolygon;
case QgsWkbTypes::CurvePolygonZ:
return wkbCurvePolygonZ;
case QgsWkbTypes::CurvePolygonM:
return wkbCurvePolygonM;
case QgsWkbTypes::CurvePolygonZM:
return wkbCurvePolygonZM;

case QgsWkbTypes::MultiCurve:
return wkbMultiCurve;
case QgsWkbTypes::MultiCurveZ:
return wkbMultiCurveZ;
case QgsWkbTypes::MultiCurveM:
return wkbMultiCurveM;
case QgsWkbTypes::MultiCurveZM:
return wkbMultiCurveZM;

case QgsWkbTypes::MultiSurface:
return wkbMultiSurface;
case QgsWkbTypes::MultiSurfaceZ:
return wkbMultiSurfaceZ;
case QgsWkbTypes::MultiSurfaceM:
return wkbMultiSurfaceM;
case QgsWkbTypes::MultiSurfaceZM:
return wkbMultiSurfaceZM;

case QgsWkbTypes::Triangle:
return wkbTriangle;
case QgsWkbTypes::TriangleZ:
return wkbTriangleZ;
case QgsWkbTypes::TriangleM:
return wkbTriangleM;
case QgsWkbTypes::TriangleZM:
return wkbTriangleZM;

case QgsWkbTypes::NoGeometry:
return wkbNone;

case QgsWkbTypes::GeometryCollection:
return wkbGeometryCollection;
case QgsWkbTypes::GeometryCollectionZ:
return wkbGeometryCollection25D;
case QgsWkbTypes::GeometryCollectionM:
return wkbGeometryCollectionM;
case QgsWkbTypes::GeometryCollectionZM:
return wkbGeometryCollectionZM;

case QgsWkbTypes::Unknown:
return wkbUnknown;
}
// no warnings!
return wkbUnknown;
}

QgsWkbTypes::Type QgsOgrProviderUtils::qgisTypeFromOgrType( OGRwkbGeometryType type )
{
switch ( type )
{
case wkbUnknown:
return QgsWkbTypes::Unknown;

case wkbPoint:
return QgsWkbTypes::Point;
case wkbLineString:
return QgsWkbTypes::LineString;
case wkbPolygon:
return QgsWkbTypes::Polygon;
case wkbMultiPoint:
return QgsWkbTypes::MultiPoint;
case wkbMultiLineString:
return QgsWkbTypes::MultiLineString;
case wkbMultiPolygon:
return QgsWkbTypes::MultiPolygon;
case wkbGeometryCollection:
return QgsWkbTypes::GeometryCollection;
case wkbCircularString:
return QgsWkbTypes::CircularString;
case wkbCompoundCurve:
return QgsWkbTypes::CompoundCurve;
case wkbCurvePolygon:
return QgsWkbTypes::CurvePolygon;
case wkbMultiCurve:
return QgsWkbTypes::MultiCurve;
case wkbMultiSurface:
return QgsWkbTypes::MultiSurface;
case wkbTriangle:
return QgsWkbTypes::Triangle;
case wkbNone:
return QgsWkbTypes::NoGeometry;

case wkbCircularStringZ:
return QgsWkbTypes::CircularStringZ;
case wkbCompoundCurveZ:
return QgsWkbTypes::CompoundCurveZ;
case wkbCurvePolygonZ:
return QgsWkbTypes::PolygonZ;
case wkbMultiCurveZ:
return QgsWkbTypes::MultiCurveZ;
case wkbMultiSurfaceZ:
return QgsWkbTypes::MultiSurfaceZ;
case wkbTriangleZ:
return QgsWkbTypes::TriangleZ;

case wkbPointM:
return QgsWkbTypes::PointM;
case wkbLineStringM:
return QgsWkbTypes::LineStringM;
case wkbPolygonM:
return QgsWkbTypes::PolygonM;
case wkbMultiPointM:
return QgsWkbTypes::PointM;
case wkbMultiLineStringM:
return QgsWkbTypes::LineStringM;
case wkbMultiPolygonM:
return QgsWkbTypes::PolygonM;
case wkbGeometryCollectionM:
return QgsWkbTypes::GeometryCollectionM;
case wkbCircularStringM:
return QgsWkbTypes::CircularStringM;
case wkbCompoundCurveM:
return QgsWkbTypes::CompoundCurveM;
case wkbCurvePolygonM:
return QgsWkbTypes::PolygonM;
case wkbMultiCurveM:
return QgsWkbTypes::MultiCurveM;
case wkbMultiSurfaceM:
return QgsWkbTypes::MultiSurfaceM;
case wkbTriangleM:
return QgsWkbTypes::TriangleM;

case wkbPointZM:
return QgsWkbTypes::PointZM;
case wkbLineStringZM:
return QgsWkbTypes::LineStringZM;
case wkbPolygonZM:
return QgsWkbTypes::PolygonZM;
case wkbMultiPointZM:
return QgsWkbTypes::MultiPointZM;
case wkbMultiLineStringZM:
return QgsWkbTypes::MultiLineStringZM;
case wkbMultiPolygonZM:
return QgsWkbTypes::MultiPolygonZM;
case wkbGeometryCollectionZM:
return QgsWkbTypes::GeometryCollectionZM;
case wkbCircularStringZM:
return QgsWkbTypes::CircularStringZM;
case wkbCompoundCurveZM:
return QgsWkbTypes::CompoundCurveZM;
case wkbCurvePolygonZM:
return QgsWkbTypes::CurvePolygonZM;
case wkbMultiCurveZM:
return QgsWkbTypes::MultiCurveZM;
case wkbMultiSurfaceZM:
return QgsWkbTypes::MultiSurfaceZM;
case wkbTriangleZM:
return QgsWkbTypes::TriangleZM;

case wkbPoint25D:
return QgsWkbTypes::Point25D;
case wkbLineString25D:
return QgsWkbTypes::LineString25D;
case wkbPolygon25D:
return QgsWkbTypes::Polygon25D;
case wkbMultiPoint25D:
return QgsWkbTypes::MultiPoint25D;
case wkbMultiLineString25D:
return QgsWkbTypes::MultiLineString25D;
case wkbMultiPolygon25D:
return QgsWkbTypes::MultiPolygon25D;
case wkbGeometryCollection25D:
return QgsWkbTypes::GeometryCollectionZ;

case wkbCurve:
case wkbSurface:
case wkbCurveZ:
case wkbSurfaceZ:
case wkbCurveM:
case wkbSurfaceM:
case wkbCurveZM:
case wkbSurfaceZM:
return QgsWkbTypes::Unknown; // abstract types - no direct mapping to QGIS types

case wkbLinearRing:
case wkbTIN:
case wkbTINZ:
case wkbTINM:
case wkbTINZM:
case wkbPolyhedralSurface:
case wkbPolyhedralSurfaceZ:
case wkbPolyhedralSurfaceM:
case wkbPolyhedralSurfaceZM:
return QgsWkbTypes::Unknown; // unsupported types
}
return QgsWkbTypes::Unknown;
}


QString QgsOgrProviderUtils::expandAuthConfig( const QString &dsName )
{
Expand Down
7 changes: 7 additions & 0 deletions src/providers/ogr/qgsogrprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,13 @@ class QgsOgrProviderUtils

//! Invalidate the cached last modified date of a dataset
static void invalidateCachedLastModifiedDate( const QString &dsName );

//! Converts a QGIS WKB type to the corresponding OGR wkb type
static OGRwkbGeometryType ogrTypeFromQgisType( QgsWkbTypes::Type type );

//! Converts a OGR WKB type to the corresponding QGIS wkb type
static QgsWkbTypes::Type qgisTypeFromOgrType( OGRwkbGeometryType type );

};


Expand Down

0 comments on commit f290109

Please sign in to comment.