Skip to content
Permalink
Browse files

QgsPointV2 fixes

-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 d7bd98a9d2782c5fa49153f2c145d2a3b9d61924
Showing with 13 additions and 7 deletions.
  1. +11 −5 src/core/geometry/qgspointv2.cpp
  2. +2 −2 src/core/geometry/qgspointv2.h
@@ -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;
@@ -75,6 +76,8 @@ bool QgsPointV2::fromWkb( const unsigned char* wkb )
if ( isMeasure() )
wkbPtr >> mM;

mBoundingBox = QgsRectangle();

return true;
}

@@ -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;
@@ -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;
@@ -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 );
}

@@ -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() )
@@ -225,7 +231,6 @@ bool QgsPointV2::moveVertex( const QgsVertexId& position, const QgsPointV2& newP
{
mM = newPos.mM;
}
mBoundingBox = QgsRectangle(); //set bounding box invalid
return true;
}

@@ -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;
@@ -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; }

0 comments on commit d7bd98a

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