Skip to content
Permalink
Browse files
[geometry] Add method to drop z/m values from a geometry
  • 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.
@@ -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.
@@ -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;
};
@@ -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();

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

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

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

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

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

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

0 comments on commit d388a4f

Please sign in to comment.