Skip to content
Permalink
Browse files

Add method to geometries for adding z/m dimension, initialized

to a specified value
  • Loading branch information
nyalldawson committed Oct 13, 2015
1 parent 6653796 commit a333fc8248495b3d8d110cd29e78b20ff392efa3
@@ -134,4 +134,20 @@ class QgsAbstractGeometryV2
virtual int vertexCount(int part = 0, int ring = 0) const = 0;
virtual int ringCount(int part = 0) const = 0;
virtual int partCount() const = 0;

/** Adds a z-dimension to the geometry, initialized to a preset value.
* @param zValue initial z-value for all nodes
* @returns true on success
* @note added in QGIS 2.12
* @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
*/
virtual bool addMValue( double mValue = 0 ) = 0;
};
@@ -60,6 +60,9 @@ class QgsCircularStringV2: public QgsCurveV2
@return rotation in radians, clockwise from north*/
double vertexAngle( const QgsVertexId& vertex ) const;

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

private:
void segmentize( const QgsPointV2& p1, const QgsPointV2& p2, const QgsPointV2& p3, QList<QgsPointV2>& points ) const;
};
@@ -65,4 +65,7 @@ class QgsCompoundCurveV2: public QgsCurveV2
@param vertex the vertex id
@return rotation in radians, clockwise from north*/
double vertexAngle( const QgsVertexId& vertex ) const;

virtual bool addZValue( double zValue = 0 );
virtual bool addMValue( double mValue = 0 );
};
@@ -70,4 +70,7 @@ class QgsCurvePolygonV2: public QgsSurfaceV2
virtual int vertexCount(int part = 0, int ring = 0) const;
virtual int ringCount(int part = 0) const;
virtual int partCount() const;

virtual bool addZValue( double zValue = 0 );
virtual bool addMValue( double mValue = 0 );
};
@@ -70,4 +70,7 @@ class QgsGeometryCollectionV2: public QgsAbstractGeometryV2
virtual int ringCount(int part = 0) const;
virtual int partCount() const;
virtual QgsPointV2 vertexAt( const QgsVertexId& id ) const;

virtual bool addZValue( double zValue = 0 );
virtual bool addMValue( double mValue = 0 );
};
@@ -60,4 +60,7 @@ class QgsLineStringV2: public QgsCurveV2
@param vertex the vertex id
@return rotation in radians, clockwise from north*/
double vertexAngle( const QgsVertexId& vertex ) const;

virtual bool addZValue( double zValue = 0 );
virtual bool addMValue( double mValue = 0 );
};
@@ -66,4 +66,7 @@ class QgsPointV2: public QgsAbstractGeometryV2
virtual int ringCount(int part = 0) const;
virtual int partCount() const;
virtual QgsPointV2 vertexAt( const QgsVertexId& id ) const;

virtual bool addZValue( double zValue = 0 );
virtual bool addMValue( double mValue = 0 );
};
@@ -294,6 +294,22 @@ class CORE_EXPORT QgsAbstractGeometryV2
virtual int ringCount( int part = 0 ) const = 0;
virtual int partCount() const = 0;

/** Adds a z-dimension to the geometry, initialized to a preset value.
* @param zValue initial z-value for all nodes
* @returns true on success
* @note added in QGIS 2.12
* @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
*/
virtual bool addMValue( double mValue = 0 ) = 0;

protected:
QgsWKBTypes::Type mWkbType;
mutable QgsRectangle mBoundingBox;
@@ -1008,3 +1008,37 @@ double QgsCircularStringV2::vertexAngle( const QgsVertexId& vId ) const
}
return 0.0;
}

bool QgsCircularStringV2::addZValue( double zValue )
{
if ( QgsWKBTypes::hasZ( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::addZ( mWkbType );

int nPoints = numPoints();
mZ.clear();
mZ.reserve( nPoints );
for ( int i = 0; i < nPoints; ++i )
{
mZ << zValue;
}
return true;
}

bool QgsCircularStringV2::addMValue( double mValue )
{
if ( QgsWKBTypes::hasM( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::addM( mWkbType );

int nPoints = numPoints();
mM.clear();
mM.reserve( nPoints );
for ( int i = 0; i < nPoints; ++i )
{
mM << mValue;
}
return true;
}
@@ -125,6 +125,9 @@ class CORE_EXPORT QgsCircularStringV2: public QgsCurveV2
@return rotation in radians, clockwise from north*/
double vertexAngle( const QgsVertexId& vertex ) const override;

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

private:
QVector<double> mX;
QVector<double> mY;
@@ -608,3 +608,31 @@ double QgsCompoundCurveV2::vertexAngle( const QgsVertexId& vertex ) const
}
}

bool QgsCompoundCurveV2::addZValue( double zValue )
{
if ( QgsWKBTypes::hasZ( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::addZ( mWkbType );

Q_FOREACH ( QgsCurveV2* curve, mCurves )
{
curve->addZValue( zValue );
}
return true;
}

bool QgsCompoundCurveV2::addMValue( double mValue )
{
if ( QgsWKBTypes::hasM( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::addM( mWkbType );

Q_FOREACH ( QgsCurveV2* curve, mCurves )
{
curve->addMValue( mValue );
}
return true;
}

@@ -109,6 +109,9 @@ class CORE_EXPORT QgsCompoundCurveV2: public QgsCurveV2
@return rotation in radians, clockwise from north*/
double vertexAngle( const QgsVertexId& vertex ) const override;

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

private:
QList< QgsCurveV2* > mCurves;
/** Turns a vertex id for the compound curve into one or more ids for the subcurves
@@ -700,3 +700,35 @@ QgsPointV2 QgsCurvePolygonV2::vertexAt( const QgsVertexId& id ) const
{
return id.ring == 0 ? mExteriorRing->vertexAt( id ) : mInteriorRings[id.ring - 1]->vertexAt( id );
}

bool QgsCurvePolygonV2::addZValue( double zValue )
{
if ( QgsWKBTypes::hasZ( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::addZ( mWkbType );

if ( mExteriorRing )
mExteriorRing->addZValue( zValue );
Q_FOREACH ( QgsCurveV2* curve, mInteriorRings )
{
curve->addZValue( zValue );
}
return true;
}

bool QgsCurvePolygonV2::addMValue( double mValue )
{
if ( QgsWKBTypes::hasM( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::addM( mWkbType );

if ( mExteriorRing )
mExteriorRing->addMValue( mValue );
Q_FOREACH ( QgsCurveV2* curve, mInteriorRings )
{
curve->addMValue( mValue );
}
return true;
}
@@ -103,6 +103,9 @@ class CORE_EXPORT QgsCurvePolygonV2: public QgsSurfaceV2
virtual int partCount() const override { return ringCount() > 0 ? 1 : 0; }
virtual QgsPointV2 vertexAt( const QgsVertexId& id ) const override;

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

protected:

QgsCurveV2* mExteriorRing;
@@ -537,3 +537,31 @@ double QgsGeometryCollectionV2::vertexAngle( const QgsVertexId& vertex ) const

return geom->vertexAngle( vertex );
}

bool QgsGeometryCollectionV2::addZValue( double zValue )
{
if ( QgsWKBTypes::hasZ( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::addZ( mWkbType );

Q_FOREACH ( QgsAbstractGeometryV2* geom, mGeometries )
{
geom->addZValue( zValue );
}
return true;
}

bool QgsGeometryCollectionV2::addMValue( double mValue )
{
if ( QgsWKBTypes::hasM( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::addM( mWkbType );

Q_FOREACH ( QgsAbstractGeometryV2* geom, mGeometries )
{
geom->addMValue( mValue );
}
return true;
}
@@ -119,6 +119,9 @@ class CORE_EXPORT QgsGeometryCollectionV2: public QgsAbstractGeometryV2
virtual int partCount() const override { return mGeometries.size(); }
virtual QgsPointV2 vertexAt( const QgsVertexId& id ) const override { return mGeometries[id.part]->vertexAt( id ); }

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

protected:
QVector< QgsAbstractGeometryV2* > mGeometries;

@@ -531,3 +531,37 @@ double QgsLineStringV2::vertexAngle( const QgsVertexId& vertex ) const
return QgsGeometryUtils::averageAngle( previous.x(), previous.y(), current.x(), current.y(), after.x(), after.y() );
}
}

bool QgsLineStringV2::addZValue( double zValue )
{
if ( QgsWKBTypes::hasZ( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::addZ( mWkbType );

mZ.clear();
int nPoints = numPoints();
mZ.reserve( nPoints );
for ( int i = 0; i < nPoints; ++i )
{
mZ << zValue;
}
return true;
}

bool QgsLineStringV2::addMValue( double mValue )
{
if ( QgsWKBTypes::hasM( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::addM( mWkbType );

mM.clear();
int nPoints = numPoints();
mM.reserve( nPoints );
for ( int i = 0; i < nPoints; ++i )
{
mM << mValue;
}
return true;
}
@@ -95,6 +95,9 @@ class CORE_EXPORT QgsLineStringV2: public QgsCurveV2
@return rotation in radians, clockwise from north*/
double vertexAngle( const QgsVertexId& vertex ) const override;

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

private:
QPolygonF mCoords;
QVector<double> mZ;
@@ -244,6 +244,26 @@ bool QgsPointV2::nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const
}
}

bool QgsPointV2::addZValue( double zValue )
{
if ( QgsWKBTypes::hasZ( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::addZ( mWkbType );
mZ = zValue;
return true;
}

bool QgsPointV2::addMValue( double mValue )
{
if ( QgsWKBTypes::hasM( mWkbType ) )
return false;

mWkbType = QgsWKBTypes::addM( mWkbType );
mM = mValue;
return true;
}

void QgsPointV2::transform( const QTransform& t )
{
qreal x, y;
@@ -96,6 +96,9 @@ class CORE_EXPORT QgsPointV2: public QgsAbstractGeometryV2
virtual int partCount() const override { return 1; }
virtual QgsPointV2 vertexAt( const QgsVertexId& /*id*/ ) const override { return *this; }

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

private:
double mX;
double mY;

0 comments on commit a333fc8

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