Skip to content

Commit a333fc8

Browse files
committedOct 13, 2015
Add method to geometries for adding z/m dimension, initialized
to a specified value
1 parent 6653796 commit a333fc8

21 files changed

+346
-0
lines changed
 

‎python/core/geometry/qgsabstractgeometryv2.sip

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,20 @@ class QgsAbstractGeometryV2
134134
virtual int vertexCount(int part = 0, int ring = 0) const = 0;
135135
virtual int ringCount(int part = 0) const = 0;
136136
virtual int partCount() const = 0;
137+
138+
/** Adds a z-dimension to the geometry, initialized to a preset value.
139+
* @param zValue initial z-value for all nodes
140+
* @returns true on success
141+
* @note added in QGIS 2.12
142+
* @see addMValue
143+
*/
144+
virtual bool addZValue( double zValue = 0 ) = 0;
145+
146+
/** Adds a measure to the geometry, initialized to a preset value.
147+
* @param mValue initial m-value for all nodes
148+
* @returns true on success
149+
* @note added in QGIS 2.12
150+
* @see addZValue
151+
*/
152+
virtual bool addMValue( double mValue = 0 ) = 0;
137153
};

‎python/core/geometry/qgscircularstringv2.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class QgsCircularStringV2: public QgsCurveV2
6060
@return rotation in radians, clockwise from north*/
6161
double vertexAngle( const QgsVertexId& vertex ) const;
6262

63+
virtual bool addZValue( double zValue = 0 );
64+
virtual bool addMValue( double mValue = 0 );
65+
6366
private:
6467
void segmentize( const QgsPointV2& p1, const QgsPointV2& p2, const QgsPointV2& p3, QList<QgsPointV2>& points ) const;
6568
};

‎python/core/geometry/qgscompoundcurvev2.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,7 @@ class QgsCompoundCurveV2: public QgsCurveV2
6565
@param vertex the vertex id
6666
@return rotation in radians, clockwise from north*/
6767
double vertexAngle( const QgsVertexId& vertex ) const;
68+
69+
virtual bool addZValue( double zValue = 0 );
70+
virtual bool addMValue( double mValue = 0 );
6871
};

‎python/core/geometry/qgscurvepolygonv2.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,7 @@ class QgsCurvePolygonV2: public QgsSurfaceV2
7070
virtual int vertexCount(int part = 0, int ring = 0) const;
7171
virtual int ringCount(int part = 0) const;
7272
virtual int partCount() const;
73+
74+
virtual bool addZValue( double zValue = 0 );
75+
virtual bool addMValue( double mValue = 0 );
7376
};

‎python/core/geometry/qgsgeometrycollectionv2.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,7 @@ class QgsGeometryCollectionV2: public QgsAbstractGeometryV2
7070
virtual int ringCount(int part = 0) const;
7171
virtual int partCount() const;
7272
virtual QgsPointV2 vertexAt( const QgsVertexId& id ) const;
73+
74+
virtual bool addZValue( double zValue = 0 );
75+
virtual bool addMValue( double mValue = 0 );
7376
};

‎python/core/geometry/qgslinestringv2.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,7 @@ class QgsLineStringV2: public QgsCurveV2
6060
@param vertex the vertex id
6161
@return rotation in radians, clockwise from north*/
6262
double vertexAngle( const QgsVertexId& vertex ) const;
63+
64+
virtual bool addZValue( double zValue = 0 );
65+
virtual bool addMValue( double mValue = 0 );
6366
};

‎python/core/geometry/qgspointv2.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,7 @@ class QgsPointV2: public QgsAbstractGeometryV2
6666
virtual int ringCount(int part = 0) const;
6767
virtual int partCount() const;
6868
virtual QgsPointV2 vertexAt( const QgsVertexId& id ) const;
69+
70+
virtual bool addZValue( double zValue = 0 );
71+
virtual bool addMValue( double mValue = 0 );
6972
};

‎src/core/geometry/qgsabstractgeometryv2.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,22 @@ class CORE_EXPORT QgsAbstractGeometryV2
294294
virtual int ringCount( int part = 0 ) const = 0;
295295
virtual int partCount() const = 0;
296296

297+
/** Adds a z-dimension to the geometry, initialized to a preset value.
298+
* @param zValue initial z-value for all nodes
299+
* @returns true on success
300+
* @note added in QGIS 2.12
301+
* @see addMValue
302+
*/
303+
virtual bool addZValue( double zValue = 0 ) = 0;
304+
305+
/** Adds a measure to the geometry, initialized to a preset value.
306+
* @param mValue initial m-value for all nodes
307+
* @returns true on success
308+
* @note added in QGIS 2.12
309+
* @see addZValue
310+
*/
311+
virtual bool addMValue( double mValue = 0 ) = 0;
312+
297313
protected:
298314
QgsWKBTypes::Type mWkbType;
299315
mutable QgsRectangle mBoundingBox;

‎src/core/geometry/qgscircularstringv2.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,3 +1008,37 @@ double QgsCircularStringV2::vertexAngle( const QgsVertexId& vId ) const
10081008
}
10091009
return 0.0;
10101010
}
1011+
1012+
bool QgsCircularStringV2::addZValue( double zValue )
1013+
{
1014+
if ( QgsWKBTypes::hasZ( mWkbType ) )
1015+
return false;
1016+
1017+
mWkbType = QgsWKBTypes::addZ( mWkbType );
1018+
1019+
int nPoints = numPoints();
1020+
mZ.clear();
1021+
mZ.reserve( nPoints );
1022+
for ( int i = 0; i < nPoints; ++i )
1023+
{
1024+
mZ << zValue;
1025+
}
1026+
return true;
1027+
}
1028+
1029+
bool QgsCircularStringV2::addMValue( double mValue )
1030+
{
1031+
if ( QgsWKBTypes::hasM( mWkbType ) )
1032+
return false;
1033+
1034+
mWkbType = QgsWKBTypes::addM( mWkbType );
1035+
1036+
int nPoints = numPoints();
1037+
mM.clear();
1038+
mM.reserve( nPoints );
1039+
for ( int i = 0; i < nPoints; ++i )
1040+
{
1041+
mM << mValue;
1042+
}
1043+
return true;
1044+
}

‎src/core/geometry/qgscircularstringv2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ class CORE_EXPORT QgsCircularStringV2: public QgsCurveV2
125125
@return rotation in radians, clockwise from north*/
126126
double vertexAngle( const QgsVertexId& vertex ) const override;
127127

128+
virtual bool addZValue( double zValue = 0 ) override;
129+
virtual bool addMValue( double mValue = 0 ) override;
130+
128131
private:
129132
QVector<double> mX;
130133
QVector<double> mY;

‎src/core/geometry/qgscompoundcurvev2.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,3 +608,31 @@ double QgsCompoundCurveV2::vertexAngle( const QgsVertexId& vertex ) const
608608
}
609609
}
610610

611+
bool QgsCompoundCurveV2::addZValue( double zValue )
612+
{
613+
if ( QgsWKBTypes::hasZ( mWkbType ) )
614+
return false;
615+
616+
mWkbType = QgsWKBTypes::addZ( mWkbType );
617+
618+
Q_FOREACH ( QgsCurveV2* curve, mCurves )
619+
{
620+
curve->addZValue( zValue );
621+
}
622+
return true;
623+
}
624+
625+
bool QgsCompoundCurveV2::addMValue( double mValue )
626+
{
627+
if ( QgsWKBTypes::hasM( mWkbType ) )
628+
return false;
629+
630+
mWkbType = QgsWKBTypes::addM( mWkbType );
631+
632+
Q_FOREACH ( QgsCurveV2* curve, mCurves )
633+
{
634+
curve->addMValue( mValue );
635+
}
636+
return true;
637+
}
638+

‎src/core/geometry/qgscompoundcurvev2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ class CORE_EXPORT QgsCompoundCurveV2: public QgsCurveV2
109109
@return rotation in radians, clockwise from north*/
110110
double vertexAngle( const QgsVertexId& vertex ) const override;
111111

112+
virtual bool addZValue( double zValue = 0 ) override;
113+
virtual bool addMValue( double mValue = 0 ) override;
114+
112115
private:
113116
QList< QgsCurveV2* > mCurves;
114117
/** Turns a vertex id for the compound curve into one or more ids for the subcurves

‎src/core/geometry/qgscurvepolygonv2.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,3 +700,35 @@ QgsPointV2 QgsCurvePolygonV2::vertexAt( const QgsVertexId& id ) const
700700
{
701701
return id.ring == 0 ? mExteriorRing->vertexAt( id ) : mInteriorRings[id.ring - 1]->vertexAt( id );
702702
}
703+
704+
bool QgsCurvePolygonV2::addZValue( double zValue )
705+
{
706+
if ( QgsWKBTypes::hasZ( mWkbType ) )
707+
return false;
708+
709+
mWkbType = QgsWKBTypes::addZ( mWkbType );
710+
711+
if ( mExteriorRing )
712+
mExteriorRing->addZValue( zValue );
713+
Q_FOREACH ( QgsCurveV2* curve, mInteriorRings )
714+
{
715+
curve->addZValue( zValue );
716+
}
717+
return true;
718+
}
719+
720+
bool QgsCurvePolygonV2::addMValue( double mValue )
721+
{
722+
if ( QgsWKBTypes::hasM( mWkbType ) )
723+
return false;
724+
725+
mWkbType = QgsWKBTypes::addM( mWkbType );
726+
727+
if ( mExteriorRing )
728+
mExteriorRing->addMValue( mValue );
729+
Q_FOREACH ( QgsCurveV2* curve, mInteriorRings )
730+
{
731+
curve->addMValue( mValue );
732+
}
733+
return true;
734+
}

‎src/core/geometry/qgscurvepolygonv2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ class CORE_EXPORT QgsCurvePolygonV2: public QgsSurfaceV2
103103
virtual int partCount() const override { return ringCount() > 0 ? 1 : 0; }
104104
virtual QgsPointV2 vertexAt( const QgsVertexId& id ) const override;
105105

106+
virtual bool addZValue( double zValue = 0 ) override;
107+
virtual bool addMValue( double mValue = 0 ) override;
108+
106109
protected:
107110

108111
QgsCurveV2* mExteriorRing;

‎src/core/geometry/qgsgeometrycollectionv2.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,31 @@ double QgsGeometryCollectionV2::vertexAngle( const QgsVertexId& vertex ) const
537537

538538
return geom->vertexAngle( vertex );
539539
}
540+
541+
bool QgsGeometryCollectionV2::addZValue( double zValue )
542+
{
543+
if ( QgsWKBTypes::hasZ( mWkbType ) )
544+
return false;
545+
546+
mWkbType = QgsWKBTypes::addZ( mWkbType );
547+
548+
Q_FOREACH ( QgsAbstractGeometryV2* geom, mGeometries )
549+
{
550+
geom->addZValue( zValue );
551+
}
552+
return true;
553+
}
554+
555+
bool QgsGeometryCollectionV2::addMValue( double mValue )
556+
{
557+
if ( QgsWKBTypes::hasM( mWkbType ) )
558+
return false;
559+
560+
mWkbType = QgsWKBTypes::addM( mWkbType );
561+
562+
Q_FOREACH ( QgsAbstractGeometryV2* geom, mGeometries )
563+
{
564+
geom->addMValue( mValue );
565+
}
566+
return true;
567+
}

‎src/core/geometry/qgsgeometrycollectionv2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ class CORE_EXPORT QgsGeometryCollectionV2: public QgsAbstractGeometryV2
119119
virtual int partCount() const override { return mGeometries.size(); }
120120
virtual QgsPointV2 vertexAt( const QgsVertexId& id ) const override { return mGeometries[id.part]->vertexAt( id ); }
121121

122+
virtual bool addZValue( double zValue = 0 ) override;
123+
virtual bool addMValue( double mValue = 0 ) override;
124+
122125
protected:
123126
QVector< QgsAbstractGeometryV2* > mGeometries;
124127

‎src/core/geometry/qgslinestringv2.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,3 +531,37 @@ double QgsLineStringV2::vertexAngle( const QgsVertexId& vertex ) const
531531
return QgsGeometryUtils::averageAngle( previous.x(), previous.y(), current.x(), current.y(), after.x(), after.y() );
532532
}
533533
}
534+
535+
bool QgsLineStringV2::addZValue( double zValue )
536+
{
537+
if ( QgsWKBTypes::hasZ( mWkbType ) )
538+
return false;
539+
540+
mWkbType = QgsWKBTypes::addZ( mWkbType );
541+
542+
mZ.clear();
543+
int nPoints = numPoints();
544+
mZ.reserve( nPoints );
545+
for ( int i = 0; i < nPoints; ++i )
546+
{
547+
mZ << zValue;
548+
}
549+
return true;
550+
}
551+
552+
bool QgsLineStringV2::addMValue( double mValue )
553+
{
554+
if ( QgsWKBTypes::hasM( mWkbType ) )
555+
return false;
556+
557+
mWkbType = QgsWKBTypes::addM( mWkbType );
558+
559+
mM.clear();
560+
int nPoints = numPoints();
561+
mM.reserve( nPoints );
562+
for ( int i = 0; i < nPoints; ++i )
563+
{
564+
mM << mValue;
565+
}
566+
return true;
567+
}

‎src/core/geometry/qgslinestringv2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class CORE_EXPORT QgsLineStringV2: public QgsCurveV2
9595
@return rotation in radians, clockwise from north*/
9696
double vertexAngle( const QgsVertexId& vertex ) const override;
9797

98+
virtual bool addZValue( double zValue = 0 ) override;
99+
virtual bool addMValue( double mValue = 0 ) override;
100+
98101
private:
99102
QPolygonF mCoords;
100103
QVector<double> mZ;

‎src/core/geometry/qgspointv2.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,26 @@ bool QgsPointV2::nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const
244244
}
245245
}
246246

247+
bool QgsPointV2::addZValue( double zValue )
248+
{
249+
if ( QgsWKBTypes::hasZ( mWkbType ) )
250+
return false;
251+
252+
mWkbType = QgsWKBTypes::addZ( mWkbType );
253+
mZ = zValue;
254+
return true;
255+
}
256+
257+
bool QgsPointV2::addMValue( double mValue )
258+
{
259+
if ( QgsWKBTypes::hasM( mWkbType ) )
260+
return false;
261+
262+
mWkbType = QgsWKBTypes::addM( mWkbType );
263+
mM = mValue;
264+
return true;
265+
}
266+
247267
void QgsPointV2::transform( const QTransform& t )
248268
{
249269
qreal x, y;

‎src/core/geometry/qgspointv2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class CORE_EXPORT QgsPointV2: public QgsAbstractGeometryV2
9696
virtual int partCount() const override { return 1; }
9797
virtual QgsPointV2 vertexAt( const QgsVertexId& /*id*/ ) const override { return *this; }
9898

99+
virtual bool addZValue( double zValue = 0 ) override;
100+
virtual bool addMValue( double mValue = 0 ) override;
101+
99102
private:
100103
double mX;
101104
double mY;

0 commit comments

Comments
 (0)