Skip to content

Commit d7bd98a

Browse files
committed
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)
1 parent 0680b13 commit d7bd98a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/core/geometry/qgspointv2.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ bool QgsPointV2::fromWkb( const unsigned char* wkb )
6464
QgsWKBTypes::Type type = wkbPtr.readHeader();
6565
if ( QgsWKBTypes::flatType( type ) != QgsWKBTypes::Point )
6666
{
67+
clear();
6768
return false;
6869
}
6970
mWkbType = type;
@@ -75,6 +76,8 @@ bool QgsPointV2::fromWkb( const unsigned char* wkb )
7576
if ( isMeasure() )
7677
wkbPtr >> mM;
7778

79+
mBoundingBox = QgsRectangle();
80+
7881
return true;
7982
}
8083

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

91-
QStringList coordinates = parts.second.split( " ", QString::SkipEmptyParts );
92-
if ( coordinates.size() < 2 + is3D() + isMeasure() )
94+
QStringList coordinates = parts.second.split( ' ', QString::SkipEmptyParts );
95+
if ( coordinates.size() < 2 )
9396
{
9497
clear();
9598
return false;
@@ -111,9 +114,9 @@ bool QgsPointV2::fromWkt( const QString& wkt )
111114
int idx = 0;
112115
mX = coordinates[idx++].toDouble();
113116
mY = coordinates[idx++].toDouble();
114-
if ( is3D() )
117+
if ( is3D() && coordinates.length() > 2 )
115118
mZ = coordinates[idx++].toDouble();
116-
if ( isMeasure() )
119+
if ( isMeasure() && coordinates.length() > 2 + is3D() )
117120
mM = coordinates[idx++].toDouble();
118121

119122
return true;
@@ -197,10 +200,12 @@ void QgsPointV2::clear()
197200
{
198201
mWkbType = QgsWKBTypes::Unknown;
199202
mX = mY = mZ = mM = 0.;
203+
mBoundingBox = QgsRectangle();
200204
}
201205

202206
void QgsPointV2::transform( const QgsCoordinateTransform& ct, QgsCoordinateTransform::TransformDirection d )
203207
{
208+
mBoundingBox = QgsRectangle();
204209
ct.transformInPlace( mX, mY, mZ, d );
205210
}
206211

@@ -215,6 +220,7 @@ void QgsPointV2::coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coor
215220
bool QgsPointV2::moveVertex( const QgsVertexId& position, const QgsPointV2& newPos )
216221
{
217222
Q_UNUSED( position );
223+
mBoundingBox = QgsRectangle();
218224
mX = newPos.mX;
219225
mY = newPos.mY;
220226
if ( is3D() && newPos.is3D() )
@@ -225,7 +231,6 @@ bool QgsPointV2::moveVertex( const QgsVertexId& position, const QgsPointV2& newP
225231
{
226232
mM = newPos.mM;
227233
}
228-
mBoundingBox = QgsRectangle(); //set bounding box invalid
229234
return true;
230235
}
231236

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

280285
void QgsPointV2::transform( const QTransform& t )
281286
{
287+
mBoundingBox = QgsRectangle();
282288
qreal x, y;
283289
t.map( mX, mY, &x, &y );
284290
mX = x; mY = y;

src/core/geometry/qgspointv2.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class CORE_EXPORT QgsPointV2: public QgsAbstractGeometryV2
4444
double z() const { return mZ; }
4545
double m() const { return mM; }
4646

47-
void setX( double x ) { mX = x; }
48-
void setY( double y ) { mY = y; }
47+
void setX( double x ) { mX = x; mBoundingBox = QgsRectangle(); }
48+
void setY( double y ) { mY = y; mBoundingBox = QgsRectangle(); }
4949
void setZ( double z ) { mZ = z; }
5050
void setM( double m ) { mM = m; }
5151

0 commit comments

Comments
 (0)