Skip to content
Permalink
Browse files

Take inheritance into account in qgsgeometry_cast

  • Loading branch information
m-kuhn committed Aug 12, 2017
1 parent f70b5b5 commit b282b89c825eb32194ead99df7347e286ce5cb6b
@@ -151,7 +151,13 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
*/
inline const QgsCurvePolygon *cast( const QgsAbstractGeometry *geom ) const
{
if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == QgsWkbTypes::CurvePolygon )
if ( !geom )
return nullptr;

QgsWkbTypes::Type flatType = geom->wkbType();
if ( flatType == QgsWkbTypes::CurvePolygon
|| flatType == QgsWkbTypes::Polygon
|| flatType == QgsWkbTypes::Triangle )
return static_cast<const QgsCurvePolygon *>( geom );
return nullptr;
}
@@ -146,7 +146,7 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
*/
inline const QgsGeometryCollection *cast( const QgsAbstractGeometry *geom ) const
{
if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == QgsWkbTypes::GeometryCollection )
if ( geom && QgsWkbTypes::isMultiType( geom->wkbType() ) )
return static_cast<const QgsGeometryCollection *>( geom );
return nullptr;
}
@@ -62,7 +62,12 @@ class CORE_EXPORT QgsMultiCurve: public QgsGeometryCollection
*/
inline const QgsMultiCurve *cast( const QgsAbstractGeometry *geom )
{
if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == QgsWkbTypes::MultiCurve )
if ( !geom )
return nullptr;

QgsWkbTypes::Type flatType = QgsWkbTypes::flatType( geom->wkbType() );
if ( flatType == QgsWkbTypes::MultiCurve
||  flatType == QgsWkbTypes::MultiLineString )
return static_cast<const QgsMultiCurve *>( geom );
return nullptr;
}
@@ -58,7 +58,13 @@ class CORE_EXPORT QgsMultiSurface: public QgsGeometryCollection
*/
inline const QgsMultiSurface *cast( const QgsAbstractGeometry *geom )
{
if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == QgsWkbTypes::MultiSurface )
if ( !geom )
return nullptr;

QgsWkbTypes::Type flatType = QgsWkbTypes::flatType( geom->wkbType() );

if ( flatType == QgsWkbTypes::MultiSurface
|| flatType == QgsWkbTypes::MultiPolygon )
return static_cast<const QgsMultiSurface *>( geom );
return nullptr;
}
@@ -80,7 +80,13 @@ class CORE_EXPORT QgsPolygonV2: public QgsCurvePolygon
*/
inline const QgsPolygonV2 *cast( const QgsAbstractGeometry *geom ) const
{
if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == QgsWkbTypes::Polygon )
if ( !geom )
return nullptr;

QgsWkbTypes::Type flatType = QgsWkbTypes::flatType( geom->wkbType() );

if ( flatType == QgsWkbTypes::Polygon
|| flatType == QgsWkbTypes::Triangle )
return static_cast<const QgsPolygonV2 *>( geom );
return nullptr;
}

0 comments on commit b282b89

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