Skip to content

Commit

Permalink
QgsPointV2 fixes
Browse files Browse the repository at this point in the history
-Fix bounding box was not invalidated for some QgsPointV2 routines
-If WKT type is PointZ/M/ZM and not enough coordinates specified,
initialise extra coordinated to 0

(cherry-picked from 8c0fe47)
  • Loading branch information
nyalldawson committed Nov 25, 2015
1 parent 0680b13 commit d7bd98a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/core/geometry/qgspointv2.cpp
Expand Up @@ -64,6 +64,7 @@ bool QgsPointV2::fromWkb( const unsigned char* wkb )
QgsWKBTypes::Type type = wkbPtr.readHeader();
if ( QgsWKBTypes::flatType( type ) != QgsWKBTypes::Point )
{
clear();
return false;
}
mWkbType = type;
Expand All @@ -75,6 +76,8 @@ bool QgsPointV2::fromWkb( const unsigned char* wkb )
if ( isMeasure() )
wkbPtr >> mM;

mBoundingBox = QgsRectangle();

return true;
}

Expand All @@ -88,8 +91,8 @@ bool QgsPointV2::fromWkt( const QString& wkt )
return false;
mWkbType = parts.first;

QStringList coordinates = parts.second.split( " ", QString::SkipEmptyParts );
if ( coordinates.size() < 2 + is3D() + isMeasure() )
QStringList coordinates = parts.second.split( ' ', QString::SkipEmptyParts );
if ( coordinates.size() < 2 )
{
clear();
return false;
Expand All @@ -111,9 +114,9 @@ bool QgsPointV2::fromWkt( const QString& wkt )
int idx = 0;
mX = coordinates[idx++].toDouble();
mY = coordinates[idx++].toDouble();
if ( is3D() )
if ( is3D() && coordinates.length() > 2 )
mZ = coordinates[idx++].toDouble();
if ( isMeasure() )
if ( isMeasure() && coordinates.length() > 2 + is3D() )
mM = coordinates[idx++].toDouble();

return true;
Expand Down Expand Up @@ -197,10 +200,12 @@ void QgsPointV2::clear()
{
mWkbType = QgsWKBTypes::Unknown;
mX = mY = mZ = mM = 0.;
mBoundingBox = QgsRectangle();
}

void QgsPointV2::transform( const QgsCoordinateTransform& ct, QgsCoordinateTransform::TransformDirection d )
{
mBoundingBox = QgsRectangle();
ct.transformInPlace( mX, mY, mZ, d );
}

Expand All @@ -215,6 +220,7 @@ void QgsPointV2::coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coor
bool QgsPointV2::moveVertex( const QgsVertexId& position, const QgsPointV2& newPos )
{
Q_UNUSED( position );
mBoundingBox = QgsRectangle();
mX = newPos.mX;
mY = newPos.mY;
if ( is3D() && newPos.is3D() )
Expand All @@ -225,7 +231,6 @@ bool QgsPointV2::moveVertex( const QgsVertexId& position, const QgsPointV2& newP
{
mM = newPos.mM;
}
mBoundingBox = QgsRectangle(); //set bounding box invalid
return true;
}

Expand Down Expand Up @@ -279,6 +284,7 @@ bool QgsPointV2::addMValue( double mValue )

void QgsPointV2::transform( const QTransform& t )
{
mBoundingBox = QgsRectangle();
qreal x, y;
t.map( mX, mY, &x, &y );
mX = x; mY = y;
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgspointv2.h
Expand Up @@ -44,8 +44,8 @@ class CORE_EXPORT QgsPointV2: public QgsAbstractGeometryV2
double z() const { return mZ; }
double m() const { return mM; }

void setX( double x ) { mX = x; }
void setY( double y ) { mY = y; }
void setX( double x ) { mX = x; mBoundingBox = QgsRectangle(); }
void setY( double y ) { mY = y; mBoundingBox = QgsRectangle(); }
void setZ( double z ) { mZ = z; }
void setM( double m ) { mM = m; }

Expand Down

0 comments on commit d7bd98a

Please sign in to comment.