Skip to content

Commit 8611543

Browse files
committed
Merge pull request #2290 from mhugent/geometry_marker
Geometry marker
2 parents cb5054f + 557701c commit 8611543

30 files changed

+592
-79
lines changed

python/core/geometry/qgsabstractgeometryv2.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,8 @@ class QgsAbstractGeometryV2
116116
virtual bool hasCurvedSegments() const;
117117
/** Returns a geometry without curves. Caller takes ownership*/
118118
virtual QgsAbstractGeometryV2* segmentize() const /Factory/;
119+
120+
/** Returns approximate rotation angle for a vertex. Usually average angle between adjacent segments.
121+
@return rotation in radians, clockwise from north*/
122+
virtual double vertexAngle( const QgsVertexId& vertex ) const = 0;
119123
};

python/core/geometry/qgscircularstringv2.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ class QgsCircularStringV2: public QgsCurveV2
5555

5656
bool hasCurvedSegments() const;
5757

58+
/** Returns approximate rotation angle for a vertex. Usually average angle between adjacent segments.
59+
@param vertex the vertex id
60+
@return rotation in radians, clockwise from north*/
61+
double vertexAngle( const QgsVertexId& vertex ) const;
62+
5863
private:
5964
void segmentize( const QgsPointV2& p1, const QgsPointV2& p2, const QgsPointV2& p3, QList<QgsPointV2>& points ) const;
6065
};

python/core/geometry/qgscompoundcurvev2.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,9 @@ class QgsCompoundCurveV2: public QgsCurveV2
6060
void sumUpArea( double& sum ) const;
6161

6262
bool hasCurvedSegments() const;
63+
64+
/** Returns approximate rotation angle for a vertex. Usually average angle between adjacent segments.
65+
@param vertex the vertex id
66+
@return rotation in radians, clockwise from north*/
67+
double vertexAngle( const QgsVertexId& vertex ) const;
6368
};

python/core/geometry/qgscurvepolygonv2.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,9 @@ class QgsCurvePolygonV2: public QgsSurfaceV2
6262

6363
bool hasCurvedSegments() const;
6464
QgsAbstractGeometryV2* segmentize() const /Factory/;
65+
66+
/** Returns approximate rotation angle for a vertex. Usually average angle between adjacent segments.
67+
@param vertex the vertex id
68+
@return rotation in radians, clockwise from north*/
69+
double vertexAngle( const QgsVertexId& vertex ) const;
6570
};

python/core/geometry/qgsgeometrycollectionv2.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ class QgsGeometryCollectionV2: public QgsAbstractGeometryV2
5151
virtual double area() const;
5252

5353
bool hasCurvedSegments() const;
54+
55+
/** Returns approximate rotation angle for a vertex. Usually average angle between adjacent segments.
56+
@param vertex the vertex id
57+
@return rotation in radians, clockwise from north*/
58+
double vertexAngle( const QgsVertexId& vertex ) const;
5459
};

python/core/geometry/qgslinestringv2.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ class QgsLineStringV2: public QgsCurveV2
5555
bool pointAt( int i, QgsPointV2& vertex, QgsVertexId::VertexType& type ) const;
5656

5757
void sumUpArea( double& sum ) const;
58+
59+
/** Returns approximate rotation angle for a vertex. Usually average angle between adjacent segments.
60+
@param vertex the vertex id
61+
@return rotation in radians, clockwise from north*/
62+
double vertexAngle( const QgsVertexId& vertex ) const;
5863
};

python/core/geometry/qgspointv2.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ class QgsPointV2: public QgsAbstractGeometryV2
5555

5656
double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const;
5757
bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const;
58+
59+
/** Angle undefined. Always returns 0.0
60+
@param vertex the vertex id
61+
@return 0.0*/
62+
double vertexAngle( const QgsVertexId& vertex ) const;
5863
};

python/core/qgsrendercontext.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,11 @@ class QgsRenderContext
8585
//! Added in QGIS v2.4
8686
const QgsVectorSimplifyMethod& vectorSimplifyMethod() const;
8787
void setVectorSimplifyMethod( const QgsVectorSimplifyMethod& simplifyMethod );
88+
89+
/** Returns pointer to the unsegmentized geometry
90+
@return the geometry*/
91+
const QgsAbstractGeometryV2* geometry() const;
92+
/** Sets pointer to original (unsegmentized) geometry
93+
@geometry the geometry*/
94+
void setGeometry( const QgsAbstractGeometryV2* geometry );
8895
};

src/core/geometry/qgsabstractgeometryv2.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ class CORE_EXPORT QgsAbstractGeometryV2
317317
*/
318318
virtual QgsAbstractGeometryV2* segmentize() const { return clone(); }
319319

320+
/** Returns approximate rotation angle for a vertex. Usually average angle between adjacent segments.
321+
@param vertex the vertex id
322+
@return rotation in radians, clockwise from north*/
323+
virtual double vertexAngle( const QgsVertexId& vertex ) const = 0;
324+
320325
protected:
321326
QgsWKBTypes::Type mWkbType;
322327
mutable QgsRectangle mBoundingBox;

src/core/geometry/qgscircularstringv2.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,3 +953,58 @@ void QgsCircularStringV2::insertVertexBetween( int after, int before, int pointO
953953
mM.insert( before, ( mM[after] + mM[before] ) / 2.0 );
954954
}
955955
}
956+
957+
double QgsCircularStringV2::vertexAngle( const QgsVertexId& vId ) const
958+
{
959+
int before = vId.vertex - 1;
960+
int vertex = vId.vertex;
961+
int after = vId.vertex + 1;
962+
963+
if ( vId.vertex % 2 != 0 ) // a curve vertex
964+
{
965+
if ( vId.vertex >= 1 && vId.vertex < numPoints() - 1 )
966+
{
967+
return QgsGeometryUtils::circleTangentDirection( QgsPointV2( mX[vertex], mY[vertex] ), QgsPointV2( mX[before], mY[before] ),
968+
QgsPointV2( mX[vertex], mY[vertex] ), QgsPointV2( mX[after], mY[after] ) );
969+
}
970+
}
971+
else //a point vertex
972+
{
973+
if ( vId.vertex == 0 )
974+
{
975+
return QgsGeometryUtils::circleTangentDirection( QgsPointV2( mX[0], mY[0] ), QgsPointV2( mX[0], mY[0] ),
976+
QgsPointV2( mX[1], mY[1] ), QgsPointV2( mX[2], mY[2] ) );
977+
}
978+
if ( vId.vertex >= numPoints() - 1 )
979+
{
980+
if ( numPoints() < 3 )
981+
{
982+
return 0.0;
983+
}
984+
int a = numPoints() - 3;
985+
int b = numPoints() - 2;
986+
int c = numPoints() - 1;
987+
return QgsGeometryUtils::circleTangentDirection( QgsPointV2( mX[c], mY[c] ), QgsPointV2( mX[a], mY[a] ),
988+
QgsPointV2( mX[b], mY[b] ), QgsPointV2( mX[c], mY[c] ) );
989+
}
990+
else
991+
{
992+
if ( vId.vertex + 2 > numPoints() - 1 )
993+
{
994+
return 0.0;
995+
}
996+
997+
int vertex1 = vId.vertex - 2;
998+
int vertex2 = vId.vertex - 1;
999+
int vertex3 = vId.vertex;
1000+
double angle1 = QgsGeometryUtils::circleTangentDirection( QgsPointV2( mX[vertex3], mY[vertex3] ),
1001+
QgsPointV2( mX[vertex1], mY[vertex1] ), QgsPointV2( mX[vertex2], mY[vertex2] ), QgsPointV2( mX[vertex3], mY[vertex3] ) );
1002+
int vertex4 = vId.vertex + 1;
1003+
int vertex5 = vId.vertex + 2;
1004+
double angle2 = QgsGeometryUtils::circleTangentDirection( QgsPointV2( mX[vertex3], mY[vertex3] ),
1005+
QgsPointV2( mX[vertex3], mY[vertex3] ), QgsPointV2( mX[vertex4], mY[vertex4] ), QgsPointV2( mX[vertex5], mY[vertex5] ) );
1006+
return QgsGeometryUtils::averageAngle( angle1, angle2 );
1007+
}
1008+
}
1009+
return 0.0;
1010+
}

0 commit comments

Comments
 (0)