Skip to content

Commit

Permalink
Add method to geometries for adding z/m dimension, initialized
Browse files Browse the repository at this point in the history
to a specified value
  • Loading branch information
nyalldawson committed Oct 13, 2015
1 parent 6653796 commit a333fc8
Show file tree
Hide file tree
Showing 21 changed files with 346 additions and 0 deletions.
16 changes: 16 additions & 0 deletions python/core/geometry/qgsabstractgeometryv2.sip
Expand Up @@ -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;
};
3 changes: 3 additions & 0 deletions python/core/geometry/qgscircularstringv2.sip
Expand Up @@ -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;
};
3 changes: 3 additions & 0 deletions python/core/geometry/qgscompoundcurvev2.sip
Expand Up @@ -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 );
};
3 changes: 3 additions & 0 deletions python/core/geometry/qgscurvepolygonv2.sip
Expand Up @@ -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 );
};
3 changes: 3 additions & 0 deletions python/core/geometry/qgsgeometrycollectionv2.sip
Expand Up @@ -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 );
};
3 changes: 3 additions & 0 deletions python/core/geometry/qgslinestringv2.sip
Expand Up @@ -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 );
};
3 changes: 3 additions & 0 deletions python/core/geometry/qgspointv2.sip
Expand Up @@ -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 );
};
16 changes: 16 additions & 0 deletions src/core/geometry/qgsabstractgeometryv2.h
Expand Up @@ -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;
Expand Down
34 changes: 34 additions & 0 deletions src/core/geometry/qgscircularstringv2.cpp
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions src/core/geometry/qgscircularstringv2.h
Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions src/core/geometry/qgscompoundcurvev2.cpp
Expand Up @@ -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;
}

3 changes: 3 additions & 0 deletions src/core/geometry/qgscompoundcurvev2.h
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions src/core/geometry/qgscurvepolygonv2.cpp
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions src/core/geometry/qgscurvepolygonv2.h
Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions src/core/geometry/qgsgeometrycollectionv2.cpp
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions src/core/geometry/qgsgeometrycollectionv2.h
Expand Up @@ -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;

Expand Down
34 changes: 34 additions & 0 deletions src/core/geometry/qgslinestringv2.cpp
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions src/core/geometry/qgslinestringv2.h
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions src/core/geometry/qgspointv2.cpp
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/core/geometry/qgspointv2.h
Expand Up @@ -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;
Expand Down

0 comments on commit a333fc8

Please sign in to comment.