Skip to content

Commit

Permalink
[geometry] Add method to drop z/m values from a geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 1, 2015
1 parent a3d780c commit d388a4f
Show file tree
Hide file tree
Showing 23 changed files with 302 additions and 2 deletions.
16 changes: 16 additions & 0 deletions python/core/geometry/qgsabstractgeometryv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ class QgsAbstractGeometryV2
*/
virtual bool addMValue( double mValue = 0 ) = 0;

/** Drops any z-dimensions which exist in the geometry.
* @returns true if Z values were present and have been removed
* @see addZValue()
* @see dropMValue()
* @note added in QGIS 2.14
*/
virtual bool dropZValue() = 0;

/** Drops any measure values which exist in the geometry.
* @returns true if m-values were present and have been removed
* @see addMValue()
* @see dropZValue()
* @note added in QGIS 2.14
*/
virtual bool dropMValue() = 0;

protected:

/** Updates the geometry type based on whether sub geometries contain z or m values.
Expand Down
3 changes: 3 additions & 0 deletions python/core/geometry/qgscircularstringv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class QgsCircularStringV2: public QgsCurveV2
virtual bool addZValue( double zValue = 0 );
virtual bool addMValue( double mValue = 0 );

virtual bool dropZValue();
virtual bool dropMValue();

private:
void segmentize( const QgsPointV2& p1, const QgsPointV2& p2, const QgsPointV2& p3, QList<QgsPointV2>& points ) const;
};
4 changes: 4 additions & 0 deletions python/core/geometry/qgscompoundcurvev2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ class QgsCompoundCurveV2: public QgsCurveV2

virtual bool addZValue( double zValue = 0 );
virtual bool addMValue( double mValue = 0 );

virtual bool dropZValue();
virtual bool dropMValue();

};
2 changes: 2 additions & 0 deletions python/core/geometry/qgscurvepolygonv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,6 @@ class QgsCurvePolygonV2: public QgsSurfaceV2

virtual bool addZValue( double zValue = 0 );
virtual bool addMValue( double mValue = 0 );
virtual bool dropZValue();
virtual bool dropMValue();
};
14 changes: 14 additions & 0 deletions python/core/geometry/qgscurvev2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,18 @@ class QgsCurveV2: public QgsAbstractGeometryV2
virtual int ringCount(int part = 0) const;
virtual int partCount() const;
virtual QgsPointV2 vertexAt( const QgsVertexId& id ) const;

/** Drops any Z dimensions which exist in the geometry.
* @returns true if Z values were present and have been removed
* @see dropMValue()
* @note added in QGIS 2.14
*/
virtual bool dropZValue() = 0;

/** Drops any M values which exist in the geometry.
* @returns true if M values were present and have been removed
* @see dropZValue()
* @note added in QGIS 2.14
*/
virtual bool dropMValue() = 0;
};
2 changes: 2 additions & 0 deletions python/core/geometry/qgsgeometrycollectionv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class QgsGeometryCollectionV2: public QgsAbstractGeometryV2

virtual bool addZValue( double zValue = 0 );
virtual bool addMValue( double mValue = 0 );
virtual bool dropZValue();
virtual bool dropMValue();

protected:

Expand Down
3 changes: 3 additions & 0 deletions python/core/geometry/qgslinestringv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,7 @@ class QgsLineStringV2: public QgsCurveV2
virtual bool addZValue( double zValue = 0 );
virtual bool addMValue( double mValue = 0 );

virtual bool dropZValue();
virtual bool dropMValue();

};
3 changes: 3 additions & 0 deletions python/core/geometry/qgspointv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,7 @@ class QgsPointV2: public QgsAbstractGeometryV2

virtual bool addZValue( double zValue = 0 );
virtual bool addMValue( double mValue = 0 );
virtual bool dropZValue();
virtual bool dropMValue();

};
22 changes: 20 additions & 2 deletions src/core/geometry/qgsabstractgeometryv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,36 @@ class CORE_EXPORT QgsAbstractGeometryV2
* @param zValue initial z-value for all nodes
* @returns true on success
* @note added in QGIS 2.12
* @see addMValue
* @see dropZValue()
* @see addMValue()
*/
virtual bool addZValue( double zValue = 0 ) = 0;

/** Adds a measure to the geometry, initialized to a preset value.
* @param mValue initial m-value for all nodes
* @returns true on success
* @note added in QGIS 2.12
* @see addZValue
* @see dropMValue()
* @see addZValue()
*/
virtual bool addMValue( double mValue = 0 ) = 0;

/** Drops any z-dimensions which exist in the geometry.
* @returns true if Z values were present and have been removed
* @see addZValue()
* @see dropMValue()
* @note added in QGIS 2.14
*/
virtual bool dropZValue() = 0;

/** Drops any measure values which exist in the geometry.
* @returns true if m-values were present and have been removed
* @see addMValue()
* @see dropZValue()
* @note added in QGIS 2.14
*/
virtual bool dropMValue() = 0;

protected:
QgsWKBTypes::Type mWkbType;
mutable QgsRectangle mBoundingBox;
Expand Down
20 changes: 20 additions & 0 deletions src/core/geometry/qgscircularstringv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,3 +1064,23 @@ bool QgsCircularStringV2::addMValue( double mValue )
}
return true;
}

bool QgsCircularStringV2::dropZValue()
{
if ( !QgsWKBTypes::hasZ( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::dropZ( mWkbType );
mZ.clear();
return true;
}

bool QgsCircularStringV2::dropMValue()
{
if ( !QgsWKBTypes::hasM( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::dropM( mWkbType );
mM.clear();
return true;
}
3 changes: 3 additions & 0 deletions src/core/geometry/qgscircularstringv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class CORE_EXPORT QgsCircularStringV2: public QgsCurveV2
virtual bool addZValue( double zValue = 0 ) override;
virtual bool addMValue( double mValue = 0 ) override;

virtual bool dropZValue() override;
virtual bool dropMValue() override;

private:
QVector<double> mX;
QVector<double> mY;
Expand Down
26 changes: 26 additions & 0 deletions src/core/geometry/qgscompoundcurvev2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,3 +664,29 @@ bool QgsCompoundCurveV2::addMValue( double mValue )
return true;
}

bool QgsCompoundCurveV2::dropZValue()
{
if ( !QgsWKBTypes::hasZ( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::dropZ( mWkbType );
Q_FOREACH ( QgsCurveV2* curve, mCurves )
{
curve->dropZValue();
}
return true;
}

bool QgsCompoundCurveV2::dropMValue()
{
if ( !QgsWKBTypes::hasM( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::dropM( mWkbType );
Q_FOREACH ( QgsCurveV2* curve, mCurves )
{
curve->dropMValue();
}
return true;
}

3 changes: 3 additions & 0 deletions src/core/geometry/qgscompoundcurvev2.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class CORE_EXPORT QgsCompoundCurveV2: public QgsCurveV2
virtual bool addZValue( double zValue = 0 ) override;
virtual bool addMValue( double mValue = 0 ) override;

virtual bool dropZValue() override;
virtual bool dropMValue() override;

private:
QList< QgsCurveV2* > mCurves;
/** Turns a vertex id for the compound curve into one or more ids for the subcurves
Expand Down
30 changes: 30 additions & 0 deletions src/core/geometry/qgscurvepolygonv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,3 +772,33 @@ bool QgsCurvePolygonV2::addMValue( double mValue )
}
return true;
}

bool QgsCurvePolygonV2::dropZValue()
{
if ( !is3D() )
return false;

mWkbType = QgsWKBTypes::dropZ( mWkbType );
if ( mExteriorRing )
mExteriorRing->dropZValue();
Q_FOREACH ( QgsCurveV2* curve, mInteriorRings )
{
curve->dropZValue();
}
return true;
}

bool QgsCurvePolygonV2::dropMValue()
{
if ( !isMeasure() )
return false;

mWkbType = QgsWKBTypes::dropM( mWkbType );
if ( mExteriorRing )
mExteriorRing->dropMValue();
Q_FOREACH ( QgsCurveV2* curve, mInteriorRings )
{
curve->dropMValue();
}
return true;
}
2 changes: 2 additions & 0 deletions src/core/geometry/qgscurvepolygonv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class CORE_EXPORT QgsCurvePolygonV2: public QgsSurfaceV2

virtual bool addZValue( double zValue = 0 ) override;
virtual bool addMValue( double mValue = 0 ) override;
virtual bool dropZValue() override;
virtual bool dropMValue() override;

protected:

Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgscurvev2.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class CORE_EXPORT QgsCurveV2: public QgsAbstractGeometryV2
virtual int ringCount( int /*part*/ = 0 ) const override { return numPoints() > 0 ? 1 : 0; }
virtual int partCount() const override { return numPoints() > 0 ? 1 : 0; }
virtual QgsPointV2 vertexAt( const QgsVertexId& id ) const override;

};

#endif // QGSCURVEV2_H
27 changes: 27 additions & 0 deletions src/core/geometry/qgsgeometrycollectionv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,30 @@ bool QgsGeometryCollectionV2::addMValue( double mValue )
}
return true;
}


bool QgsGeometryCollectionV2::dropZValue()
{
if ( !is3D() )
return false;

mWkbType = QgsWKBTypes::dropZ( mWkbType );
Q_FOREACH ( QgsAbstractGeometryV2* geom, mGeometries )
{
geom->dropZValue();
}
return true;
}

bool QgsGeometryCollectionV2::dropMValue()
{
if ( !isMeasure() )
return false;

mWkbType = QgsWKBTypes::dropM( mWkbType );
Q_FOREACH ( QgsAbstractGeometryV2* geom, mGeometries )
{
geom->dropMValue();
}
return true;
}
2 changes: 2 additions & 0 deletions src/core/geometry/qgsgeometrycollectionv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ class CORE_EXPORT QgsGeometryCollectionV2: public QgsAbstractGeometryV2

virtual bool addZValue( double zValue = 0 ) override;
virtual bool addMValue( double mValue = 0 ) override;
virtual bool dropZValue() override;
virtual bool dropMValue() override;

protected:
QVector< QgsAbstractGeometryV2* > mGeometries;
Expand Down
20 changes: 20 additions & 0 deletions src/core/geometry/qgslinestringv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,3 +895,23 @@ bool QgsLineStringV2::addMValue( double mValue )
}
return true;
}

bool QgsLineStringV2::dropZValue()
{
if ( !is3D() )
return false;

mWkbType = QgsWKBTypes::dropZ( mWkbType );
mZ.clear();
return true;
}

bool QgsLineStringV2::dropMValue()
{
if ( !isMeasure() )
return false;

mWkbType = QgsWKBTypes::dropM( mWkbType );
mM.clear();
return true;
}
3 changes: 3 additions & 0 deletions src/core/geometry/qgslinestringv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ class CORE_EXPORT QgsLineStringV2: public QgsCurveV2
virtual bool addZValue( double zValue = 0 ) override;
virtual bool addMValue( double mValue = 0 ) override;

virtual bool dropZValue() override;
virtual bool dropMValue() override;

private:
QVector<double> mX;
QVector<double> mY;
Expand Down
21 changes: 21 additions & 0 deletions src/core/geometry/qgspointv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,24 @@ void QgsPointV2::transform( const QTransform& t )
t.map( mX, mY, &x, &y );
mX = x; mY = y;
}


bool QgsPointV2::dropZValue()
{
if ( !is3D() )
return false;

mWkbType = QgsWKBTypes::dropZ( mWkbType );
mZ = 0.0;
return true;
}

bool QgsPointV2::dropMValue()
{
if ( !isMeasure() )
return false;

mWkbType = QgsWKBTypes::dropM( mWkbType );
mM = 0.0;
return true;
}
2 changes: 2 additions & 0 deletions src/core/geometry/qgspointv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class CORE_EXPORT QgsPointV2: public QgsAbstractGeometryV2

virtual bool addZValue( double zValue = 0 ) override;
virtual bool addMValue( double mValue = 0 ) override;
virtual bool dropZValue() override;
virtual bool dropMValue() override;

private:
double mX;
Expand Down
Loading

0 comments on commit d388a4f

Please sign in to comment.