@@ -71,7 +71,8 @@ bool QgsMapToPixelSimplifier::equalSnapToGrid( double x1, double y1, double x2,
71
71
static QgsGeometry generalizeWkbGeometryByBoundingBox (
72
72
QgsWkbTypes::Type wkbType,
73
73
const QgsAbstractGeometry &geometry,
74
- const QgsRectangle &envelope )
74
+ const QgsRectangle &envelope,
75
+ bool isRing )
75
76
{
76
77
unsigned int geometryType = QgsWkbTypes::singleType ( QgsWkbTypes::flatType ( wkbType ) );
77
78
@@ -89,31 +90,48 @@ static QgsGeometry generalizeWkbGeometryByBoundingBox(
89
90
const double y2 = envelope.yMaximum ();
90
91
91
92
// Write the generalized geometry
92
- if ( geometryType == QgsWkbTypes::LineString )
93
+ if ( geometryType == QgsWkbTypes::LineString && !isRing )
93
94
{
94
95
return QgsGeometry ( qgis::make_unique< QgsLineString >( QVector<double >() << x1 << x2, QVector<double >() << y1 << y2 ) );
95
96
}
96
97
else
97
98
{
98
- return QgsGeometry::fromRect ( envelope );
99
+ std::unique_ptr< QgsLineString > ext = qgis::make_unique< QgsLineString >(
100
+ QVector< double >() << x1
101
+ << x2
102
+ << x2
103
+ << x1
104
+ << x1,
105
+ QVector< double >() << y1
106
+ << y1
107
+ << y2
108
+ << y2
109
+ << y1 );
110
+ if ( geometryType == QgsWkbTypes::LineString )
111
+ return QgsGeometry ( std::move ( ext ) );
112
+ else
113
+ {
114
+ std::unique_ptr< QgsPolygon > polygon = qgis::make_unique< QgsPolygon >();
115
+ polygon->setExteriorRing ( ext.release () );
116
+ return QgsGeometry ( std::move ( polygon ) );
117
+ }
99
118
}
100
119
}
101
120
102
- QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry (
103
- int simplifyFlags,
104
- SimplifyAlgorithm simplifyAlgorithm,
105
- QgsWkbTypes::Type wkbType,
106
- const QgsAbstractGeometry &geometry,
107
- const QgsRectangle &envelope, double map2pixelTol,
108
- bool isaLinearRing )
121
+ QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry ( int simplifyFlags,
122
+ SimplifyAlgorithm simplifyAlgorithm,
123
+ const QgsAbstractGeometry &geometry, double map2pixelTol,
124
+ bool isaLinearRing )
109
125
{
110
126
bool isGeneralizable = true ;
127
+ QgsWkbTypes::Type wkbType = geometry.wkbType ();
111
128
112
129
// Can replace the geometry by its BBOX ?
130
+ QgsRectangle envelope = geometry.boundingBox ();
113
131
if ( ( simplifyFlags & QgsMapToPixelSimplifier::SimplifyEnvelope ) &&
114
132
isGeneralizableByMapBoundingBox ( envelope, map2pixelTol ) )
115
133
{
116
- return generalizeWkbGeometryByBoundingBox ( wkbType, geometry, envelope );
134
+ return generalizeWkbGeometryByBoundingBox ( wkbType, geometry, envelope, isaLinearRing );
117
135
}
118
136
119
137
if ( !( simplifyFlags & QgsMapToPixelSimplifier::SimplifyGeometry ) )
@@ -267,7 +285,7 @@ QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry(
267
285
{
268
286
// approximate the geometry's shape by its bounding box
269
287
// (rect for linear ring / one segment for line string)
270
- return generalizeWkbGeometryByBoundingBox ( wkbType, geometry, r );
288
+ return generalizeWkbGeometryByBoundingBox ( wkbType, geometry, r, isaLinearRing );
271
289
}
272
290
else
273
291
{
@@ -293,11 +311,12 @@ QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry(
293
311
{
294
312
const QgsPolygon &srcPolygon = dynamic_cast <const QgsPolygon &>( geometry );
295
313
std::unique_ptr<QgsPolygon> polygon ( new QgsPolygon () );
296
- polygon->setExteriorRing ( qgsgeometry_cast<QgsCurve *>( simplifyGeometry ( simplifyFlags, simplifyAlgorithm, srcPolygon. exteriorRing ()-> wkbType (), *srcPolygon.exteriorRing (), envelope , map2pixelTol, true ).constGet ()->clone () ) );
314
+ polygon->setExteriorRing ( qgsgeometry_cast<QgsCurve *>( simplifyGeometry ( simplifyFlags, simplifyAlgorithm, *srcPolygon.exteriorRing (), map2pixelTol, true ).constGet ()->clone () ) );
297
315
for ( int i = 0 ; i < srcPolygon.numInteriorRings (); ++i )
298
316
{
299
317
const QgsCurve *sub = srcPolygon.interiorRing ( i );
300
- polygon->addInteriorRing ( qgsgeometry_cast<QgsCurve *>( simplifyGeometry ( simplifyFlags, simplifyAlgorithm, sub->wkbType (), *sub, envelope, map2pixelTol, true ).constGet ()->clone () ) );
318
+ std::unique_ptr< QgsCurve > ring ( qgsgeometry_cast<QgsCurve *>( simplifyGeometry ( simplifyFlags, simplifyAlgorithm, *sub, map2pixelTol, true ).constGet ()->clone () ) );
319
+ polygon->addInteriorRing ( ring.release () );
301
320
}
302
321
return QgsGeometry ( polygon.release () );
303
322
}
@@ -309,7 +328,7 @@ QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry(
309
328
for ( int i = 0 ; i < numGeoms; ++i )
310
329
{
311
330
const QgsAbstractGeometry *sub = srcCollection.geometryN ( i );
312
- collection->addGeometry ( simplifyGeometry ( simplifyFlags, simplifyAlgorithm, sub-> wkbType (), *sub, envelope , map2pixelTol, false ).constGet ()->clone () );
331
+ collection->addGeometry ( simplifyGeometry ( simplifyFlags, simplifyAlgorithm, *sub, map2pixelTol, false ).constGet ()->clone () );
313
332
}
314
333
return QgsGeometry ( collection.release () );
315
334
}
@@ -359,5 +378,5 @@ QgsGeometry QgsMapToPixelSimplifier::simplify( const QgsGeometry &geometry ) con
359
378
return geometry;
360
379
}
361
380
362
- return simplifyGeometry ( mSimplifyFlags , mSimplifyAlgorithm , geometry. wkbType (), *geometry.constGet (), envelope , mTolerance , false );
381
+ return simplifyGeometry ( mSimplifyFlags , mSimplifyAlgorithm , *geometry.constGet (), mTolerance , false );
363
382
}
0 commit comments