Skip to content
Permalink
Browse files

Add reversed method to QgsCurveV2

Also clean up and add missing docs for QgsLineStringV2
  • Loading branch information
nyalldawson committed Nov 18, 2015
1 parent 8783fe2 commit 86c1ffa0aac21d950a910d3cd662a186ced54adf
@@ -60,6 +60,8 @@ class QgsCircularStringV2: public QgsCurveV2
@return rotation in radians, clockwise from north*/
double vertexAngle( const QgsVertexId& vertex ) const;

virtual QgsCircularStringV2* reversed() const /Factory/;

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

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

virtual QgsCompoundCurveV2* reversed() const /Factory/;

virtual bool addZValue( double zValue = 0 );
virtual bool addMValue( double mValue = 0 );
};
@@ -23,6 +23,11 @@ class QgsCurveV2: public QgsAbstractGeometryV2
virtual bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const;
virtual bool pointAt( int i, QgsPointV2& vertex, QgsVertexId::VertexType& type ) const = 0;

/** Returns a reversed copy of the curve, where the direction of the curve has been flipped.
* @note added in QGIS 2.14
*/
virtual QgsCurveV2* reversed() const = 0 /Factory/;

/** Returns a geometry without curves. Caller takes ownership*/
QgsAbstractGeometryV2* segmentize() const /Factory/;

@@ -1,3 +1,9 @@
/** \ingroup core
* \class QgsLineStringV2
* \brief Line string geometry type, with support for z-dimension and m-values.
* \note added in QGIS 2.10
*/

class QgsLineStringV2: public QgsCurveV2
{
%TypeHeaderCode
@@ -8,13 +14,49 @@ class QgsLineStringV2: public QgsCurveV2
QgsLineStringV2();
~QgsLineStringV2();

/** Resets the line string to match the line string in a WKB geometry.
* @param type WKB type
* @param wkb WKB representation of line geometry
* @note not available in Python bindings
*/
//void fromWkbPoints( QgsWKBTypes::Type type, const QgsConstWkbPtr& wkb );

/** Returns the specified point from inside the line string.
* @param i index of point, starting at 0 for the first point
*/
QgsPointV2 pointN( int i ) const;

/** Resets the line string to match the specified list of points.
* @param points new points for line string. If empty, line string will be cleared.
*/
void setPoints( const QList<QgsPointV2>& points );

/** Appends the contents of another line string to the end of this line string.
* @param line line to append. Ownership is not transferred.
*/
void append( const QgsLineStringV2* line );

/** Adds a new vertex to the end of the line string.
* @param pt vertex to add
*/
void addVertex( const QgsPointV2& pt );

/** Closes the line string by appending the first point to the end of the line, if it is not already closed.*/
void close();

virtual QgsLineStringV2* reversed() const /Factory/;

/** Returns a QPolygonF representing the line string.
*/
QPolygonF asQPolygonF() const;

//reimplemented methods

virtual QString geometryType() const;
virtual int dimension() const;
virtual QgsLineStringV2* clone() const;
virtual void clear();
virtual QgsLineStringV2* clone() const /Factory/;

virtual bool fromWkb( const unsigned char* wkb );
//void fromWkbPoints( QgsWKBTypes::Type type, const QgsConstWkbPtr& wkb );
virtual bool fromWkt( const QString& wkt );

int wkbSize() const;
@@ -28,39 +70,30 @@ class QgsLineStringV2: public QgsCurveV2
virtual double length() const;
virtual QgsPointV2 startPoint() const;
virtual QgsPointV2 endPoint() const;
virtual QgsLineStringV2* curveToLine() const;
virtual QgsLineStringV2* curveToLine() const /Factory/;

int numPoints() const;
QgsPointV2 pointN( int i ) const;
void points( QList<QgsPointV2>& pt ) const;

void setPoints( const QList<QgsPointV2>& points );
void append( const QgsLineStringV2* line );

void draw( QPainter& p ) const;

void transform( const QgsCoordinateTransform& ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform );
void transform( const QTransform& t );

void addToPainterPath( QPainterPath& path ) const;
void drawAsPolygon( QPainter& p ) const;

const QPolygonF& qPolygonF() const;

virtual bool insertVertex( const QgsVertexId& position, const QgsPointV2& vertex );
virtual bool moveVertex( const QgsVertexId& position, const QgsPointV2& newPos );
virtual bool deleteVertex( const QgsVertexId& position );
void addVertex( const QgsPointV2& pt );

double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const;
bool pointAt( int i, QgsPointV2& vertex, QgsVertexId::VertexType& type ) const;

void sumUpArea( double& sum ) const;

/** Returns approximate rotation angle for a vertex. Usually average angle between adjacent segments.
@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 );

};
@@ -22,4 +22,9 @@ class QgsMultiCurveV2: public QgsGeometryCollectionV2
virtual bool addGeometry( QgsAbstractGeometryV2* g );
/** Returns a geometry without curves. Caller takes ownership*/
QgsAbstractGeometryV2* segmentize() const /Factory/;

/** Returns a copy of the multi curve, where each component curve has had its line direction reversed.
* @note added in QGIS 2.14
*/
QgsMultiCurveV2* reversed() const /Factory/;
};
@@ -117,7 +117,7 @@ class QgsPointV2: public QgsAbstractGeometryV2
//implementation of inherited methods
virtual QString geometryType() const;
virtual int dimension() const;
virtual QgsPointV2* clone() const;
virtual QgsPointV2* clone() const /Factory/;
void clear();
virtual bool fromWkb( const unsigned char* wkb );
virtual bool fromWkt( const QString& wkt );
@@ -1009,6 +1009,22 @@ double QgsCircularStringV2::vertexAngle( const QgsVertexId& vId ) const
return 0.0;
}

QgsCircularStringV2* QgsCircularStringV2::reversed() const
{
QgsCircularStringV2* copy = clone();
std::reverse( copy->mX.begin(), copy->mX.end() );
std::reverse( copy->mY.begin(), copy->mY.end() );
if ( is3D() )
{
std::reverse( copy->mZ.begin(), copy->mZ.end() );
}
if ( isMeasure() )
{
std::reverse( copy->mM.begin(), copy->mM.end() );
}
return copy;
}

bool QgsCircularStringV2::addZValue( double zValue )
{
if ( QgsWKBTypes::hasZ( mWkbType ) )
@@ -125,6 +125,8 @@ class CORE_EXPORT QgsCircularStringV2: public QgsCurveV2
@return rotation in radians, clockwise from north*/
double vertexAngle( const QgsVertexId& vertex ) const override;

virtual QgsCircularStringV2* reversed() const override;

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

@@ -625,6 +625,17 @@ double QgsCompoundCurveV2::vertexAngle( const QgsVertexId& vertex ) const
}
}

QgsCompoundCurveV2* QgsCompoundCurveV2::reversed() const
{
QgsCompoundCurveV2* clone = new QgsCompoundCurveV2();
Q_FOREACH ( QgsCurveV2* curve, mCurves )
{
QgsCurveV2* reversedCurve = curve->reversed();
clone->addCurve( reversedCurve );
}
return clone;
}

bool QgsCompoundCurveV2::addZValue( double zValue )
{
if ( QgsWKBTypes::hasZ( mWkbType ) )
@@ -109,6 +109,8 @@ class CORE_EXPORT QgsCompoundCurveV2: public QgsCurveV2
@return rotation in radians, clockwise from north*/
double vertexAngle( const QgsVertexId& vertex ) const override;

virtual QgsCompoundCurveV2* reversed() const override;

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

@@ -87,6 +87,11 @@ class CORE_EXPORT QgsCurveV2: public QgsAbstractGeometryV2
*/
virtual bool pointAt( int i, QgsPointV2& vertex, QgsVertexId::VertexType& type ) const = 0;

/** Returns a reversed copy of the curve, where the direction of the curve has been flipped.
* @note added in QGIS 2.14
*/
virtual QgsCurveV2* reversed() const = 0;

QgsAbstractGeometryV2* segmentize() const override;

virtual int vertexCount( int /*part*/ = 0, int /*ring*/ = 0 ) const override { return numPoints(); }
@@ -191,7 +191,7 @@ int QgsLineStringV2::numPoints() const

QgsPointV2 QgsLineStringV2::pointN( int i ) const
{
if ( mX.size() <= i )
if ( i < 0 || i >= mX.size() )
{
return QgsPointV2();
}
@@ -240,7 +240,9 @@ void QgsLineStringV2::points( QList<QgsPointV2>& pts ) const

void QgsLineStringV2::setPoints( const QList<QgsPointV2>& points )
{
if ( points.size() < 1 )
mBoundingBox = QgsRectangle(); //set bounding box invalid

if ( points.isEmpty() )
{
mWkbType = QgsWKBTypes::Unknown;
mX.clear();
@@ -307,11 +309,29 @@ void QgsLineStringV2::append( const QgsLineStringV2* line )
mY += line->mY;
mZ += line->mZ;
mM += line->mM;

mBoundingBox = QgsRectangle(); //set bounding box invalid
}

QgsLineStringV2* QgsLineStringV2::reversed() const
{
QgsLineStringV2* copy = clone();
std::reverse( copy->mX.begin(), copy->mX.end() );
std::reverse( copy->mY.begin(), copy->mY.end() );
if ( copy->is3D() )
{
std::reverse( copy->mZ.begin(), copy->mZ.end() );
}
if ( copy->isMeasure() )
{
std::reverse( copy->mM.begin(), copy->mM.end() );
}
return copy;
}

void QgsLineStringV2::draw( QPainter& p ) const
{
p.drawPolyline( qPolygonF() );
p.drawPolyline( asQPolygonF() );
}

void QgsLineStringV2::addToPainterPath( QPainterPath& path ) const
@@ -335,10 +355,10 @@ void QgsLineStringV2::addToPainterPath( QPainterPath& path ) const

void QgsLineStringV2::drawAsPolygon( QPainter& p ) const
{
p.drawPolygon( qPolygonF() );
p.drawPolygon( asQPolygonF() );
}

QPolygonF QgsLineStringV2::qPolygonF() const
QPolygonF QgsLineStringV2::asQPolygonF() const
{
QPolygonF points;
for ( int i = 0; i < mX.count(); ++i )
@@ -534,6 +554,7 @@ void QgsLineStringV2::importVerticesFromWkb( const QgsConstWkbPtr& wkb )
wkb >> mM[i];
}
}
mBoundingBox = QgsRectangle(); //set bounding box invalid
}

void QgsLineStringV2::close()

0 comments on commit 86c1ffa

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