Skip to content

Commit 9253228

Browse files
authored
Merge pull request #3434 from pvalsecc/lessWKB
Avoid back and forth with WKB in rendering
2 parents 235204f + db91330 commit 9253228

39 files changed

+452
-892
lines changed

doc/api_break.dox

+20
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ variant instead.</li>
295295
<li>GenericDataSourceURI has been renamed to GenericDataSourceUri</li>
296296
</ul>
297297

298+
\subsection qgis_api_break_3_0_QgsClipper QgsClipper
299+
300+
<ul>
301+
<li>clippedLineWKB has been renamed to clippedLine and it's signature has been changed to return a QPolygonF</li>
302+
</ul>
303+
298304
\subsection qgis_api_break_3_0_QgsColorBrewerColorRampDialog QgsColorBrewerColorRampDialog
299305

300306
<ul>
@@ -575,6 +581,12 @@ method to determine if a geometry is valid.</li>
575581
a QgsGeometry value rather than a pointer.</li>
576582
</ul>
577583

584+
\subsection qgis_api_break_3_0_QgsGeometrySimplifier QgsGeometrySimplifier
585+
586+
<ul>
587+
<li>simplifyGeometry() has been removed and simplify() must be used instead .</li>
588+
</ul>
589+
578590
\subsection qgis_api_break_3_0_QgsGradientColorRampDialog QgsGradientColorRampDialog
579591

580592
<ul>
@@ -699,6 +711,14 @@ be used instead of a null pointer if no transformation is required.</li>
699711
<li>drawOldLabeling(), drawNewLabeling() were removed. The method drawLabeling() should be used instead.</li>
700712
</ul>
701713

714+
\subsection qgis_api_break_3_0_QgsMapToPixelGeometrySimplifier QgsMapToPixelGeometrySimplifier
715+
716+
The whole class has been refactored to stop using WKB and to use QgsAbstractGeometry classes.
717+
<ul>
718+
<li>simplifyGeometry(), simplifyPoints(), isGeneralizableByMapBoundingBox(), _getLineString(), _getPolygon() methods have been removed.</li>
719+
<li>The signature of the static methods _getPoint(), _getLineString() and _getPolygon() have been changed.</li>
720+
</ul>
721+
702722
\subsection qgis_api_break_3_0_QgsMapSettings QgsMapSettings
703723

704724
<ul>

python/core/geometry/qgscircularstring.sip

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ class QgsCircularString: public QgsCurve
104104
virtual bool dropZValue();
105105
virtual bool dropMValue();
106106

107+
virtual double xAt( int index ) const;
108+
virtual double yAt( int index ) const;
109+
107110
protected:
108111

109112
virtual QgsRectangle calculateBoundingBox() const;

python/core/geometry/qgscompoundcurve.sip

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class QgsCompoundCurve: public QgsCurve
9595
virtual bool dropZValue();
9696
virtual bool dropMValue();
9797

98+
virtual double xAt( int index ) const;
99+
virtual double yAt( int index ) const;
100+
98101
protected:
99102

100103
virtual QgsRectangle calculateBoundingBox() const;

python/core/geometry/qgscurve.sip

+18
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,24 @@ class QgsCurve: public QgsAbstractGeometry
103103
*/
104104
virtual bool dropMValue() = 0;
105105

106+
/** Returns the x-coordinate of the specified node in the line string.
107+
* @param index index of node, where the first node in the line is 0
108+
* @returns x-coordinate of node, or 0.0 if index is out of bounds
109+
* @see setXAt()
110+
*/
111+
virtual double xAt( int index ) const = 0;
112+
113+
/** Returns the y-coordinate of the specified node in the line string.
114+
* @param index index of node, where the first node in the line is 0
115+
* @returns y-coordinate of node, or 0.0 if index is out of bounds
116+
* @see setYAt()
117+
*/
118+
virtual double yAt( int index ) const = 0;
119+
120+
/** Returns a QPolygonF representing the line string.
121+
*/
122+
QPolygonF asQPolygonF() const;
123+
106124
protected:
107125

108126
virtual void clearCache() const;

python/core/geometry/qgslinestring.sip

+3-18
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@ class QgsLineString: public QgsCurve
2121
*/
2222
QgsPointV2 pointN( int i ) const;
2323

24-
/** Returns the x-coordinate of the specified node in the line string.
25-
* @param index index of node, where the first node in the line is 0
26-
* @returns x-coordinate of node, or 0.0 if index is out of bounds
27-
* @see setXAt()
28-
*/
29-
double xAt( int index ) const;
30-
31-
/** Returns the y-coordinate of the specified node in the line string.
32-
* @param index index of node, where the first node in the line is 0
33-
* @returns y-coordinate of node, or 0.0 if index is out of bounds
34-
* @see setYAt()
35-
*/
36-
double yAt( int index ) const;
37-
3824
/** Returns the z-coordinate of the specified node in the line string.
3925
* @param index index of node, where the first node in the line is 0
4026
* @returns z-coordinate of node, or 0.0 if index is out of bounds or the line
@@ -102,10 +88,6 @@ class QgsLineString: public QgsCurve
10288
/** Closes the line string by appending the first point to the end of the line, if it is not already closed.*/
10389
void close();
10490

105-
/** Returns a QPolygonF representing the line string.
106-
*/
107-
QPolygonF asQPolygonF() const;
108-
10991
/** Returns the geometry converted to the more generic curve type QgsCompoundCurve
11092
@return the converted geometry. Caller takes ownership*/
11193
QgsAbstractGeometry* toCurveType() const /Factory/;
@@ -170,6 +152,9 @@ class QgsLineString: public QgsCurve
170152

171153
virtual bool convertTo( QgsWkbTypes::Type type );
172154

155+
virtual double xAt( int index ) const;
156+
virtual double yAt( int index ) const;
157+
173158
protected:
174159

175160
virtual QgsRectangle calculateBoundingBox() const;

python/core/qgsclipper.sip

+7-5
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ class QgsClipper
5252

5353
static void trimPolygon( QPolygonF& pts, const QgsRectangle& clipRect );
5454

55-
/** Reads a polyline from WKB and clips it to clipExtent
56-
@param wkb pointer to the start of the line wkb
57-
@param clipExtent clipping bounds
58-
@param line out: clipped line coordinates*/
59-
static QgsConstWkbPtr clippedLineWKB( QgsConstWkbPtr& wkb, const QgsRectangle& clipExtent, QPolygonF& line );
55+
/** Takes a linestring and clips it to clipExtent
56+
* @param curve the linestring
57+
* @param clipExtent clipping bounds
58+
* @return clipped line coordinates
59+
*/
60+
static QPolygonF clippedLine( const QgsCurve& curve, const QgsRectangle& clipExtent );
61+
6062
};

python/core/qgsgeometrysimplifier.sip

-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ class QgsAbstractGeometrySimplifier
1313

1414
//! Returns a simplified version the specified geometry
1515
virtual QgsGeometry simplify( const QgsGeometry& geometry ) const = 0;
16-
//! Simplifies the specified geometry
17-
virtual bool simplifyGeometry( QgsGeometry* geometry ) const = 0;
1816

1917
// MapToPixel simplification helper methods
2018
public:
@@ -42,6 +40,4 @@ class QgsTopologyPreservingSimplifier : QgsAbstractGeometrySimplifier
4240

4341
//! Returns a simplified version the specified geometry
4442
virtual QgsGeometry simplify( const QgsGeometry& geometry ) const;
45-
//! Simplifies the specified geometry
46-
virtual bool simplifyGeometry( QgsGeometry* geometry ) const;
4743
};

python/core/qgsmaptopixelgeometrysimplifier.sip

+2-17
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,12 @@ class QgsMapToPixelSimplifier : QgsAbstractGeometrySimplifier
4343
//! Sets the local simplification algorithm of the vector layer managed
4444
void setSimplifyAlgorithm( SimplifyAlgorithm simplifyAlgorithm );
4545

46-
//! Returns a simplified version the specified geometry
47-
virtual QgsGeometry simplify( const QgsGeometry& geometry ) const;
48-
//! Simplifies the specified geometry
49-
virtual bool simplifyGeometry( QgsGeometry* geometry ) const;
50-
51-
//! Simplifies the specified WKB-point array
52-
virtual bool simplifyPoints( QgsWkbTypes::Type wkbType, QgsConstWkbPtr& sourceWkbPtr, QPolygonF& targetPoints ) const;
46+
//! Sets the tolerance of the vector layer managed
47+
void setTolerance( double value );
5348

5449
// MapToPixel simplification helper methods
5550
public:
5651

5752
//! Returns whether the envelope can be replaced by its BBOX when is applied the specified map2pixel context
5853
static bool isGeneralizableByMapBoundingBox( const QgsRectangle& envelope, double map2pixelTol );
59-
60-
//! Returns whether the envelope can be replaced by its BBOX when is applied the specified map2pixel context
61-
bool isGeneralizableByMapBoundingBox( const QgsRectangle& envelope ) const;
62-
63-
//! Simplifies the geometry when is applied the specified map2pixel context
64-
static bool simplifyGeometry( QgsGeometry* geometry, int simplifyFlags, double tolerance, SimplifyAlgorithm simplifyAlgorithm = Distance );
65-
66-
//! Simplifies the WKB-point array when is applied the specified map2pixel context
67-
static bool simplifyPoints( QgsWkbTypes::Type wkbType, QgsConstWkbPtr& sourceWkbPtr, QPolygonF& targetPoints, int simplifyFlags, double tolerance, SimplifyAlgorithm simplifyAlgorithm = Distance );
68-
6954
};

python/core/symbology-ng/qgsrenderer.sip

+1-13
Original file line numberDiff line numberDiff line change
@@ -429,19 +429,7 @@ class QgsFeatureRenderer
429429
* Creates a point in screen coordinates from a wkb string in map
430430
* coordinates
431431
*/
432-
static QgsConstWkbPtr _getPoint( QPointF& pt, QgsRenderContext& context, QgsConstWkbPtr& wkb );
433-
434-
/**
435-
* Creates a line string in screen coordinates from a wkb string in map
436-
* coordinates
437-
*/
438-
static QgsConstWkbPtr _getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr& wkb, bool clipToExtent = true );
439-
440-
/**
441-
* Creates a polygon in screen coordinates from a wkb string in map
442-
* coordinates
443-
*/
444-
static QgsConstWkbPtr _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, QgsConstWkbPtr& wkb, bool clipToExtent = true );
432+
static QPointF _getPoint( QgsRenderContext& context, const QgsPointV2& point );
445433

446434
void setScaleMethodToSymbol( QgsSymbol* symbol, int scaleMethod );
447435

python/core/symbology-ng/qgssymbol.sip

+7-7
Original file line numberDiff line numberDiff line change
@@ -237,25 +237,25 @@ class QgsSymbol
237237
/**
238238
* Creates a point in screen coordinates from a QgsPointV2 in map coordinates
239239
*/
240-
static void _getPoint( QPointF& pt /Out/, QgsRenderContext& context, const QgsPointV2* point );
240+
static QPointF _getPoint( QgsRenderContext& context, const QgsPointV2& point );
241241

242242
/**
243-
* Creates a point in screen coordinates from a wkb string in map
243+
* Creates a line string in screen coordinates from a QgsCurve in map
244244
* coordinates
245245
*/
246-
static QgsConstWkbPtr _getPoint( QPointF& pt, QgsRenderContext& context, QgsConstWkbPtr& wkb );
246+
static QPolygonF _getLineString( QgsRenderContext& context, const QgsCurve& curve, bool clipToExtent = true );
247247

248248
/**
249-
* Creates a line string in screen coordinates from a wkb string in map
249+
* Creates a polygon ring in screen coordinates from a QgsCurve in map
250250
* coordinates
251251
*/
252-
static QgsConstWkbPtr _getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr& wkb, bool clipToExtent = true );
252+
static QPolygonF _getPolygonRing( QgsRenderContext& context, const QgsCurve& curve, bool clipToExtent );
253253

254254
/**
255-
* Creates a polygon in screen coordinates from a wkb string in map
255+
* Creates a polygon in screen coordinates from a QgsPolygonV2 in map
256256
* coordinates
257257
*/
258-
static QgsConstWkbPtr _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, QgsConstWkbPtr& wkb, bool clipToExtent = true );
258+
static void _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const QgsPolygonV2& polygon, bool clipToExtent = true );
259259

260260
/**
261261
* Retrieve a cloned list of all layers that make up this symbol.

src/core/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ SET(QGIS_CORE_SRCS
350350
geometry/qgspolygon.cpp
351351
geometry/qgswkbptr.cpp
352352
geometry/qgswkbtypes.cpp
353-
geometry/qgswkbsimplifierptr.cpp
354353

355354
${CMAKE_CURRENT_BINARY_DIR}/qgscontexthelp_texts.cpp
356355
${CMAKE_CURRENT_BINARY_DIR}/qgsexpression_texts.cpp
@@ -848,7 +847,6 @@ SET(QGIS_CORE_HDRS
848847
geometry/qgspolygon.h
849848
geometry/qgssurface.h
850849
geometry/qgswkbptr.h
851-
geometry/qgswkbsimplifierptr.h
852850
geometry/qgswkbtypes.h
853851
)
854852

src/core/geometry/qgsabstractgeometry.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ struct CORE_EXPORT QgsVertexId
409409
CurveVertex
410410
};
411411

412-
QgsVertexId( int _part = -1, int _ring = -1, int _vertex = -1, VertexType _type = SegmentVertex )
412+
explicit QgsVertexId( int _part = -1, int _ring = -1, int _vertex = -1, VertexType _type = SegmentVertex )
413413
: part( _part )
414414
, ring( _ring )
415415
, vertex( _vertex )

src/core/geometry/qgscircularstring.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,22 @@ QgsPointV2 QgsCircularString::pointN( int i ) const
408408
return QgsPointV2( t, x, y, z, m );
409409
}
410410

411+
double QgsCircularString::xAt( int index ) const
412+
{
413+
if ( index >= 0 && index < mX.size() )
414+
return mX.at( index );
415+
else
416+
return 0.0;
417+
}
418+
419+
double QgsCircularString::yAt( int index ) const
420+
{
421+
if ( index >= 0 && index < mY.size() )
422+
return mY.at( index );
423+
else
424+
return 0.0;
425+
}
426+
411427
void QgsCircularString::points( QgsPointSequence &pts ) const
412428
{
413429
pts.clear();

src/core/geometry/qgscircularstring.h

+3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ class CORE_EXPORT QgsCircularString: public QgsCurve
129129
virtual bool dropZValue() override;
130130
virtual bool dropMValue() override;
131131

132+
double xAt( int index ) const override;
133+
double yAt( int index ) const override;
134+
132135
protected:
133136

134137
virtual QgsRectangle calculateBoundingBox() const override;

src/core/geometry/qgscompoundcurve.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,36 @@ bool QgsCompoundCurve::pointAt( int node, QgsPointV2& point, QgsVertexId::Vertex
679679
return false;
680680
}
681681

682+
double QgsCompoundCurve::xAt( int index ) const
683+
{
684+
int currentVertexId = 0;
685+
for ( int j = 0; j < mCurves.size(); ++j )
686+
{
687+
int nCurvePoints = mCurves.at( j )->numPoints();
688+
if (( index - currentVertexId ) < nCurvePoints )
689+
{
690+
return mCurves.at( j )->xAt( index - currentVertexId );
691+
}
692+
currentVertexId += ( nCurvePoints - 1 );
693+
}
694+
return 0.0;
695+
}
696+
697+
double QgsCompoundCurve::yAt( int index ) const
698+
{
699+
int currentVertexId = 0;
700+
for ( int j = 0; j < mCurves.size(); ++j )
701+
{
702+
int nCurvePoints = mCurves.at( j )->numPoints();
703+
if (( index - currentVertexId ) < nCurvePoints )
704+
{
705+
return mCurves.at( j )->yAt( index - currentVertexId );
706+
}
707+
currentVertexId += ( nCurvePoints - 1 );
708+
}
709+
return 0.0;
710+
}
711+
682712
void QgsCompoundCurve::sumUpArea( double& sum ) const
683713
{
684714
QList< QgsCurve* >::const_iterator curveIt = mCurves.constBegin();

src/core/geometry/qgscompoundcurve.h

+3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ class CORE_EXPORT QgsCompoundCurve: public QgsCurve
119119
virtual bool dropZValue() override;
120120
virtual bool dropMValue() override;
121121

122+
double xAt( int index ) const override;
123+
double yAt( int index ) const override;
124+
122125
protected:
123126

124127
virtual QgsRectangle calculateBoundingBox() const override;

src/core/geometry/qgscurve.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,15 @@ QgsRectangle QgsCurve::boundingBox() const
117117
return mBoundingBox;
118118
}
119119

120+
QPolygonF QgsCurve::asQPolygonF() const
121+
{
122+
const int nb = numPoints();
123+
QPolygonF points;
124+
points.reserve( nb );
125+
for ( int i = 0; i < nb; ++i )
126+
{
127+
points << QPointF( xAt( i ), yAt( i ) );
128+
}
129+
return points;
130+
}
131+

src/core/geometry/qgscurve.h

+19
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,25 @@ class CORE_EXPORT QgsCurve: public QgsAbstractGeometry
116116

117117
virtual QgsRectangle boundingBox() const override;
118118

119+
/** Returns the x-coordinate of the specified node in the line string.
120+
* @param index index of node, where the first node in the line is 0
121+
* @returns x-coordinate of node, or 0.0 if index is out of bounds
122+
* @see setXAt()
123+
*/
124+
virtual double xAt( int index ) const = 0;
125+
126+
/** Returns the y-coordinate of the specified node in the line string.
127+
* @param index index of node, where the first node in the line is 0
128+
* @returns y-coordinate of node, or 0.0 if index is out of bounds
129+
* @see setYAt()
130+
*/
131+
virtual double yAt( int index ) const = 0;
132+
133+
/** Returns a QPolygonF representing the points.
134+
*/
135+
QPolygonF asQPolygonF() const;
136+
137+
119138
protected:
120139

121140
virtual void clearCache() const override { mBoundingBox = QgsRectangle(); mCoordinateSequence.clear(); QgsAbstractGeometry::clearCache(); }

0 commit comments

Comments
 (0)