Skip to content

Commit

Permalink
More string comparison fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jun 7, 2016
1 parent d0feea5 commit fdb28c0
Show file tree
Hide file tree
Showing 34 changed files with 58 additions and 22 deletions.
5 changes: 5 additions & 0 deletions python/core/geometry/qgsabstractgeometryv2.sip
Expand Up @@ -114,6 +114,11 @@ class QgsAbstractGeometryV2
*/
QgsWKBTypes::Type wkbType() const;

/** Returns the flat WKB type of the geometry class. Corresponds to information obtained from
* geometryType().
*/
virtual QgsWKBTypes::Type flatWkbType() const = 0;

/** Returns the WKT type string of the geometry.
* @see geometryType
* @see wkbType
Expand Down
1 change: 1 addition & 0 deletions python/core/geometry/qgscircularstringv2.sip
Expand Up @@ -12,6 +12,7 @@ class QgsCircularStringV2: public QgsCurveV2
virtual bool operator!=( const QgsCurveV2& other ) const;

virtual QString geometryType() const;
virtual QgsWKBTypes::Type flatWkbType() const;
virtual int dimension() const;
virtual QgsCircularStringV2* clone() const;
virtual void clear();
Expand Down
1 change: 1 addition & 0 deletions python/core/geometry/qgscompoundcurvev2.sip
Expand Up @@ -14,6 +14,7 @@ class QgsCompoundCurveV2: public QgsCurveV2
virtual bool operator!=( const QgsCurveV2& other ) const;

virtual QString geometryType() const;
virtual QgsWKBTypes::Type flatWkbType() const;
virtual int dimension() const;
virtual QgsCompoundCurveV2* clone() const;
virtual void clear();
Expand Down
1 change: 1 addition & 0 deletions python/core/geometry/qgscurvepolygonv2.sip
Expand Up @@ -11,6 +11,7 @@ class QgsCurvePolygonV2: public QgsSurfaceV2
~QgsCurvePolygonV2();

virtual QString geometryType() const;
virtual QgsWKBTypes::Type flatWkbType() const;
virtual int dimension() const;
virtual QgsCurvePolygonV2* clone() const;
void clear();
Expand Down
1 change: 1 addition & 0 deletions python/core/geometry/qgsgeometrycollectionv2.sip
Expand Up @@ -29,6 +29,7 @@ class QgsGeometryCollectionV2: public QgsAbstractGeometryV2
//methods inherited from QgsAbstractGeometry
virtual int dimension() const;
virtual QString geometryType() const;
virtual QgsWKBTypes::Type flatWkbType() const;
virtual void clear();

/** Adds a geometry and takes ownership. Returns true in case of success.*/
Expand Down
1 change: 1 addition & 0 deletions python/core/geometry/qgslinestringv2.sip
Expand Up @@ -113,6 +113,7 @@ class QgsLineStringV2: public QgsCurveV2
//reimplemented methods

virtual QString geometryType() const;
virtual QgsWKBTypes::Type flatWkbType() const;
virtual int dimension() const;
virtual QgsLineStringV2* clone() const /Factory/;
virtual void clear();
Expand Down
1 change: 1 addition & 0 deletions python/core/geometry/qgsmulticurvev2.sip
Expand Up @@ -6,6 +6,7 @@ class QgsMultiCurveV2: public QgsGeometryCollectionV2

public:
virtual QString geometryType() const;
virtual QgsWKBTypes::Type flatWkbType() const;
virtual QgsMultiCurveV2* clone() const;

bool fromWkt( const QString& wkt );
Expand Down
1 change: 1 addition & 0 deletions python/core/geometry/qgsmultilinestringv2.sip
Expand Up @@ -6,6 +6,7 @@ class QgsMultiLineStringV2: public QgsMultiCurveV2

public:
virtual QString geometryType() const;
virtual QgsWKBTypes::Type flatWkbType() const;
virtual QgsMultiLineStringV2* clone() const;

bool fromWkt( const QString& wkt );
Expand Down
1 change: 1 addition & 0 deletions python/core/geometry/qgsmultipointv2.sip
Expand Up @@ -5,6 +5,7 @@ class QgsMultiPointV2: public QgsGeometryCollectionV2
%End
public:
virtual QString geometryType() const;
virtual QgsWKBTypes::Type flatWkbType() const;
virtual QgsMultiPointV2* clone() const;

bool fromWkt( const QString& wkt );
Expand Down
1 change: 1 addition & 0 deletions python/core/geometry/qgsmultipolygonv2.sip
Expand Up @@ -5,6 +5,7 @@ class QgsMultiPolygonV2: public QgsMultiSurfaceV2
%End
public:
virtual QString geometryType() const;
virtual QgsWKBTypes::Type flatWkbType() const;
virtual QgsMultiPolygonV2* clone() const;

bool fromWkt( const QString& wkt );
Expand Down
1 change: 1 addition & 0 deletions python/core/geometry/qgsmultisurfacev2.sip
Expand Up @@ -5,6 +5,7 @@ class QgsMultiSurfaceV2: public QgsGeometryCollectionV2
%End
public:
virtual QString geometryType() const;
virtual QgsWKBTypes::Type flatWkbType() const;
virtual QgsMultiSurfaceV2* clone() const;

bool fromWkt( const QString& wkt );
Expand Down
1 change: 1 addition & 0 deletions python/core/geometry/qgspointv2.sip
Expand Up @@ -141,6 +141,7 @@ class QgsPointV2: public QgsAbstractGeometryV2
//implementation of inherited methods
virtual QgsRectangle boundingBox() const;
virtual QString geometryType() const;
virtual QgsWKBTypes::Type flatWkbType() const;
virtual int dimension() const;
virtual QgsPointV2* clone() const /Factory/;
void clear();
Expand Down
1 change: 1 addition & 0 deletions python/core/geometry/qgspolygonv2.sip
Expand Up @@ -11,6 +11,7 @@ class QgsPolygonV2: public QgsCurvePolygonV2
bool operator!=( const QgsPolygonV2& other ) const;

virtual QString geometryType() const;
virtual QgsWKBTypes::Type flatWkbType() const;
virtual QgsPolygonV2* clone() const;

virtual bool fromWkb( QgsConstWkbPtr wkb );
Expand Down
9 changes: 7 additions & 2 deletions src/core/geometry/qgsabstractgeometryv2.h
Expand Up @@ -75,18 +75,23 @@ class CORE_EXPORT QgsAbstractGeometryV2
virtual int dimension() const = 0;
//virtual int coordDim() const { return mCoordDimension; }

/** Returns a unique string representing the geometry type.
/** Returns a unique string representing the geometry class type.
* @see wkbType
* @see wktTypeStr
*/
virtual QString geometryType() const = 0;

/** Returns the WKB type of the geometry.
/** Returns the WKB type of the saved geometry.
* @see geometryType
* @see wktTypeStr
*/
QgsWKBTypes::Type wkbType() const { return mWkbType; }

/** Returns the flat WKB type of the geometry class. Corresponds to information obtained from
* geometryType().
*/
virtual QgsWKBTypes::Type flatWkbType() const = 0;

/** Returns the WKT type string of the geometry.
* @see geometryType
* @see wkbType
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgscircularstringv2.cpp
Expand Up @@ -252,7 +252,7 @@ bool QgsCircularStringV2::fromWkt( const QString& wkt )

QPair<QgsWKBTypes::Type, QString> parts = QgsGeometryUtils::wktReadBlock( wkt );

if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::parseType( geometryType() ) )
if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::CircularString )
return false;
mWkbType = parts.first;

Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgscircularstringv2.h
Expand Up @@ -37,6 +37,7 @@ class CORE_EXPORT QgsCircularStringV2: public QgsCurveV2
virtual bool operator!=( const QgsCurveV2& other ) const override;

virtual QString geometryType() const override { return "CircularString"; }
virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::CircularString; }
virtual int dimension() const override { return 1; }
virtual QgsCircularStringV2* clone() const override;
virtual void clear() override;
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgscompoundcurvev2.cpp
Expand Up @@ -149,7 +149,7 @@ bool QgsCompoundCurveV2::fromWkt( const QString& wkt )

QPair<QgsWKBTypes::Type, QString> parts = QgsGeometryUtils::wktReadBlock( wkt );

if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::parseType( geometryType() ) )
if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::CompoundCurve )
return false;
mWkbType = parts.first;

Expand Down Expand Up @@ -430,7 +430,7 @@ void QgsCompoundCurveV2::addVertex( const QgsPointV2& pt )
}

QgsLineStringV2* line = nullptr;
if ( !lastCurve || lastCurve->geometryType() != "LineString" )
if ( !lastCurve || QgsWKBTypes::flatType( lastCurve->wkbType() ) != QgsWKBTypes::LineString )
{
line = new QgsLineStringV2();
mCurves.append( line );
Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgscompoundcurvev2.h
Expand Up @@ -38,6 +38,7 @@ class CORE_EXPORT QgsCompoundCurveV2: public QgsCurveV2
virtual bool operator!=( const QgsCurveV2& other ) const override;

virtual QString geometryType() const override { return "CompoundCurve"; }
virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::CompoundCurve; }
virtual int dimension() const override { return 1; }
virtual QgsCompoundCurveV2* clone() const override;
virtual void clear() override;
Expand Down
6 changes: 3 additions & 3 deletions src/core/geometry/qgscurvepolygonv2.cpp
Expand Up @@ -149,7 +149,7 @@ bool QgsCurvePolygonV2::fromWkt( const QString& wkt )

QPair<QgsWKBTypes::Type, QString> parts = QgsGeometryUtils::wktReadBlock( wkt );

if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::parseType( geometryType() ) )
if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::Polygon )
return false;

mWkbType = parts.first;
Expand Down Expand Up @@ -466,11 +466,11 @@ void QgsCurvePolygonV2::setExteriorRing( QgsCurveV2* ring )
mExteriorRing = ring;

//set proper wkb type
if ( geometryType() == "Polygon" )
if ( QgsWKBTypes::flatType( wkbType() ) == QgsWKBTypes::Polygon )
{
setZMTypeFromSubGeometry( ring, QgsWKBTypes::Polygon );
}
else if ( geometryType() == "CurvePolygon" )
else if ( QgsWKBTypes::flatType( wkbType() ) == QgsWKBTypes::CurvePolygon )
{
setZMTypeFromSubGeometry( ring, QgsWKBTypes::CurvePolygon );
}
Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgscurvepolygonv2.h
Expand Up @@ -37,6 +37,7 @@ class CORE_EXPORT QgsCurvePolygonV2: public QgsSurfaceV2
~QgsCurvePolygonV2();

virtual QString geometryType() const override { return "CurvePolygon"; }
virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::CurvePolygon; }
virtual int dimension() const override { return 2; }
virtual QgsCurvePolygonV2* clone() const override;
void clear() override;
Expand Down
13 changes: 7 additions & 6 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -449,7 +449,7 @@ bool QgsGeometry::deleteVertex( int atVertex )
}

//maintain compatibility with < 2.10 API
if ( d->geometry->geometryType() == "MultiPoint" )
if ( QgsWKBTypes::flatType( d->geometry->wkbType() ) == QgsWKBTypes::MultiPoint )
{
detach( true );
removeWkbGeos();
Expand Down Expand Up @@ -487,7 +487,7 @@ bool QgsGeometry::insertVertex( double x, double y, int beforeVertex )
}

//maintain compatibility with < 2.10 API
if ( d->geometry->geometryType() == "MultiPoint" )
if ( QgsWKBTypes::flatType( d->geometry->wkbType() ) == QgsWKBTypes::MultiPoint )
{
detach( true );
removeWkbGeos();
Expand Down Expand Up @@ -1008,7 +1008,7 @@ bool QgsGeometry::convertToSingleType()

QgsPoint QgsGeometry::asPoint() const
{
if ( !d->geometry || d->geometry->geometryType() != "Point" )
if ( !d->geometry || QgsWKBTypes::flatType( d->geometry->wkbType() ) != QgsWKBTypes::Point )
{
return QgsPoint();
}
Expand All @@ -1029,7 +1029,8 @@ QgsPolyline QgsGeometry::asPolyline() const
return polyLine;
}

bool doSegmentation = ( d->geometry->geometryType() == "CompoundCurve" || d->geometry->geometryType() == "CircularString" );
bool doSegmentation = ( QgsWKBTypes::flatType( d->geometry->wkbType() ) == QgsWKBTypes::CompoundCurve
|| QgsWKBTypes::flatType( d->geometry->wkbType() ) == QgsWKBTypes::CircularString );
QgsLineStringV2* line = nullptr;
if ( doSegmentation )
{
Expand Down Expand Up @@ -1071,7 +1072,7 @@ QgsPolygon QgsGeometry::asPolygon() const
if ( !d->geometry )
return QgsPolygon();

bool doSegmentation = ( d->geometry->geometryType() == "CurvePolygon" );
bool doSegmentation = ( QgsWKBTypes::flatType( d->geometry->wkbType() ) == QgsWKBTypes::CurvePolygon );

QgsPolygonV2* p = nullptr;
if ( doSegmentation )
Expand Down Expand Up @@ -1105,7 +1106,7 @@ QgsPolygon QgsGeometry::asPolygon() const

QgsMultiPoint QgsGeometry::asMultiPoint() const
{
if ( !d->geometry || d->geometry->geometryType() != "MultiPoint" )
if ( !d->geometry || QgsWKBTypes::flatType( d->geometry->wkbType() ) != QgsWKBTypes::MultiPoint )
{
return QgsMultiPoint();
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgsgeometrycollectionv2.cpp
Expand Up @@ -491,7 +491,7 @@ bool QgsGeometryCollectionV2::fromCollectionWkt( const QString &wkt, const QList

QPair<QgsWKBTypes::Type, QString> parts = QgsGeometryUtils::wktReadBlock( wkt );

if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::parseType( geometryType() ) )
if ( QgsWKBTypes::flatType( parts.first ) != flatWkbType() )
return false;
mWkbType = parts.first;

Expand All @@ -504,7 +504,7 @@ bool QgsGeometryCollectionV2::fromCollectionWkt( const QString &wkt, const QList
bool success = false;
Q_FOREACH ( const QgsAbstractGeometryV2* geom, subtypes )
{
if ( QgsWKBTypes::flatType( childParts.first ) == QgsWKBTypes::parseType( geom->geometryType() ) )
if ( QgsWKBTypes::flatType( childParts.first ) == geom->flatWkbType() )
{
mGeometries.append( geom->clone() );
if ( mGeometries.back()->fromWkt( childWkt ) )
Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgsgeometrycollectionv2.h
Expand Up @@ -53,6 +53,7 @@ class CORE_EXPORT QgsGeometryCollectionV2: public QgsAbstractGeometryV2
//methods inherited from QgsAbstractGeometry
virtual int dimension() const override;
virtual QString geometryType() const override { return "GeometryCollection"; }
virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::GeometryCollection; }
virtual void clear() override;

/** Adds a geometry and takes ownership. Returns true in case of success.*/
Expand Down
9 changes: 5 additions & 4 deletions src/core/geometry/qgsgeometryeditutils.cpp
Expand Up @@ -120,13 +120,14 @@ int QgsGeometryEditUtils::addPart( QgsAbstractGeometryV2* geom, QgsAbstractGeome
}

bool added = false;
if ( geom->geometryType() == "MultiSurface" || geom->geometryType() == "MultiPolygon" )
if ( QgsWKBTypes::flatType( geom->wkbType() ) == QgsWKBTypes::MultiSurface
|| QgsWKBTypes::flatType( geom->wkbType() ) == QgsWKBTypes::MultiPolygon )
{
QgsCurveV2* curve = dynamic_cast<QgsCurveV2*>( part );
if ( curve && curve->isClosed() && curve->numPoints() >= 4 )
{
QgsCurvePolygonV2 *poly = nullptr;
if ( curve->geometryType() == "LineString" )
if ( QgsWKBTypes::flatType( curve->wkbType() ) == QgsWKBTypes::LineString )
{
poly = new QgsPolygonV2();
}
Expand All @@ -137,11 +138,11 @@ int QgsGeometryEditUtils::addPart( QgsAbstractGeometryV2* geom, QgsAbstractGeome
poly->setExteriorRing( curve );
added = geomCollection->addGeometry( poly );
}
else if ( part->geometryType() == "Polygon" )
else if ( QgsWKBTypes::flatType( part->wkbType() ) == QgsWKBTypes::Polygon )
{
added = geomCollection->addGeometry( part );
}
else if ( part->geometryType() == "MultiPolygon" )
else if ( QgsWKBTypes::flatType( part->wkbType() ) == QgsWKBTypes::MultiPolygon )
{
QgsGeometryCollectionV2 *parts = static_cast<QgsGeometryCollectionV2*>( part );

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgslinestringv2.cpp
Expand Up @@ -150,7 +150,7 @@ bool QgsLineStringV2::fromWkt( const QString& wkt )

QPair<QgsWKBTypes::Type, QString> parts = QgsGeometryUtils::wktReadBlock( wkt );

if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::parseType( geometryType() ) )
if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::LineString )
return false;
mWkbType = parts.first;

Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgslinestringv2.h
Expand Up @@ -139,6 +139,7 @@ class CORE_EXPORT QgsLineStringV2: public QgsCurveV2
//reimplemented methods

virtual QString geometryType() const override { return "LineString"; }
virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::LineString; }
virtual int dimension() const override { return 1; }
virtual QgsLineStringV2* clone() const override;
virtual void clear() override;
Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgsmulticurvev2.h
Expand Up @@ -28,6 +28,7 @@ class CORE_EXPORT QgsMultiCurveV2: public QgsGeometryCollectionV2
{
public:
virtual QString geometryType() const override { return "MultiCurve"; }
virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::MultiCurve; }
QgsMultiCurveV2* clone() const override;

bool fromWkt( const QString& wkt ) override;
Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgsmultilinestringv2.h
Expand Up @@ -28,6 +28,7 @@ class CORE_EXPORT QgsMultiLineStringV2: public QgsMultiCurveV2
{
public:
virtual QString geometryType() const override { return "MultiLineString"; }
virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::MultiLineString; }
QgsMultiLineStringV2* clone() const override;

bool fromWkt( const QString& wkt ) override;
Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgsmultipointv2.h
Expand Up @@ -28,6 +28,7 @@ class CORE_EXPORT QgsMultiPointV2: public QgsGeometryCollectionV2
{
public:
virtual QString geometryType() const override { return "MultiPoint"; }
virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::MultiPoint; }
QgsMultiPointV2* clone() const override;

bool fromWkt( const QString& wkt ) override;
Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgsmultipolygonv2.h
Expand Up @@ -28,6 +28,7 @@ class CORE_EXPORT QgsMultiPolygonV2: public QgsMultiSurfaceV2
{
public:
virtual QString geometryType() const override { return "MultiPolygon"; }
virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::MultiPolygon; }
QgsMultiPolygonV2* clone() const override;

bool fromWkt( const QString& wkt ) override;
Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgsmultisurfacev2.h
Expand Up @@ -28,6 +28,7 @@ class CORE_EXPORT QgsMultiSurfaceV2: public QgsGeometryCollectionV2
{
public:
virtual QString geometryType() const override { return "MultiSurface"; }
virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::MultiSurface; }
QgsMultiSurfaceV2* clone() const override;

bool fromWkt( const QString& wkt ) override;
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgspointv2.cpp
Expand Up @@ -130,7 +130,7 @@ bool QgsPointV2::fromWkt( const QString& wkt )

QPair<QgsWKBTypes::Type, QString> parts = QgsGeometryUtils::wktReadBlock( wkt );

if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::parseType( geometryType() ) )
if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::Point )
return false;
mWkbType = parts.first;

Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgspointv2.h
Expand Up @@ -153,6 +153,7 @@ class CORE_EXPORT QgsPointV2: public QgsAbstractGeometryV2
//implementation of inherited methods
virtual QgsRectangle boundingBox() const override { return QgsRectangle( mX, mY, mX, mY ); }
virtual QString geometryType() const override { return "Point"; }
virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::Point; }
virtual int dimension() const override { return 0; }
virtual QgsPointV2* clone() const override;
void clear() override;
Expand Down

0 comments on commit fdb28c0

Please sign in to comment.