@@ -41,7 +41,7 @@ float QgsMapToPixelSimplifier::calculateLengthSquared2D( double x1, double y1, d
41
41
}
42
42
43
43
// ! Returns the BBOX of the specified WKB-point stream
44
- inline static QgsRectangle calculateBoundingBox ( QGis::WkbType wkbType, unsigned char * wkb, size_t numPoints )
44
+ inline static QgsRectangle calculateBoundingBox ( QGis::WkbType wkbType, const unsigned char * wkb, size_t numPoints )
45
45
{
46
46
double x, y;
47
47
QgsRectangle r;
@@ -63,7 +63,7 @@ inline static QgsRectangle calculateBoundingBox( QGis::WkbType wkbType, unsigned
63
63
// ! Generalize the WKB-geometry using the BBOX of the original geometry
64
64
static bool generalizeWkbGeometryByBoundingBox (
65
65
QGis::WkbType wkbType,
66
- unsigned char * sourceWkb, size_t sourceWkbSize,
66
+ const unsigned char * sourceWkb, size_t sourceWkbSize,
67
67
unsigned char * targetWkb, size_t & targetWkbSize,
68
68
const QgsRectangle& envelope, bool writeHeader )
69
69
{
@@ -151,7 +151,7 @@ static bool generalizeWkbGeometryByBoundingBox(
151
151
// ! Simplify the WKB-geometry using the specified tolerance
152
152
bool QgsMapToPixelSimplifier::simplifyWkbGeometry (
153
153
int simplifyFlags, QGis::WkbType wkbType,
154
- unsigned char * sourceWkb, size_t sourceWkbSize,
154
+ const unsigned char * sourceWkb, size_t sourceWkbSize,
155
155
unsigned char * targetWkb, size_t & targetWkbSize,
156
156
const QgsRectangle& envelope, double map2pixelTol,
157
157
bool writeHeader, bool isaLinearRing )
@@ -161,7 +161,7 @@ bool QgsMapToPixelSimplifier::simplifyWkbGeometry(
161
161
bool result = false ;
162
162
163
163
// Save initial WKB settings to use when the simplification creates invalid geometries
164
- unsigned char * sourcePrevWkb = sourceWkb;
164
+ const unsigned char * sourcePrevWkb = sourceWkb;
165
165
unsigned char * targetPrevWkb = targetWkb;
166
166
size_t targetWkbPrevSize = targetWkbSize;
167
167
@@ -194,7 +194,7 @@ bool QgsMapToPixelSimplifier::simplifyWkbGeometry(
194
194
targetWkbSize += 5 ;
195
195
}
196
196
197
- unsigned char * wkb1 = sourceWkb;
197
+ const unsigned char * wkb1 = sourceWkb;
198
198
unsigned char * wkb2 = targetWkb;
199
199
unsigned int flatType = QGis::flatType ( wkbType );
200
200
@@ -230,10 +230,10 @@ bool QgsMapToPixelSimplifier::simplifyWkbGeometry(
230
230
{
231
231
double x1, y1, x2, y2;
232
232
233
- unsigned char * startWkbX = sourceWkb;
234
- unsigned char * startWkbY = startWkbX + sizeOfDoubleX;
235
- unsigned char * finalWkbX = sourceWkb + ( numPoints - 1 ) * ( sizeOfDoubleX + sizeOfDoubleY );
236
- unsigned char * finalWkbY = finalWkbX + sizeOfDoubleX;
233
+ const unsigned char * startWkbX = sourceWkb;
234
+ const unsigned char * startWkbY = startWkbX + sizeOfDoubleX;
235
+ const unsigned char * finalWkbX = sourceWkb + ( numPoints - 1 ) * ( sizeOfDoubleX + sizeOfDoubleY );
236
+ const unsigned char * finalWkbY = finalWkbX + sizeOfDoubleX;
237
237
238
238
memcpy ( &x1, startWkbX, sizeof ( double ) );
239
239
memcpy ( &y1, startWkbY, sizeof ( double ) );
@@ -418,7 +418,7 @@ QgsGeometry* QgsMapToPixelSimplifier::simplify( QgsGeometry* geometry ) const
418
418
// ! Simplifies the geometry (Removing duplicated points) when is applied the specified map2pixel context
419
419
bool QgsMapToPixelSimplifier::simplifyGeometry ( QgsGeometry* geometry, int simplifyFlags, double tolerance )
420
420
{
421
- size_t targetWkbSize = 0 ;
421
+ size_t finalWkbSize = 0 ;
422
422
423
423
// Check whether the geometry can be simplified using the map2pixel context
424
424
QGis::GeometryType geometryType = geometry->type ();
@@ -428,17 +428,21 @@ bool QgsMapToPixelSimplifier::simplifyGeometry( QgsGeometry* geometry, int simpl
428
428
QgsRectangle envelope = geometry->boundingBox ();
429
429
QGis::WkbType wkbType = geometry->wkbType ();
430
430
431
- unsigned char * wkb = ( unsigned char * ) geometry->asWkb ();
431
+ const unsigned char * wkb = geometry->asWkb ();
432
432
size_t wkbSize = geometry->wkbSize ();
433
433
434
- // Simplify the geometry rewriting temporally its WKB-stream for saving calloc's.
435
- if ( simplifyWkbGeometry ( simplifyFlags, wkbType, wkb, wkbSize, wkb, targetWkbSize, envelope, tolerance ) )
434
+ unsigned char * targetWkb = new unsigned char [wkbSize];
435
+ memcpy ( targetWkb, wkb, wkbSize );
436
+
437
+ if ( simplifyWkbGeometry ( simplifyFlags, wkbType, wkb, wkbSize, targetWkb, finalWkbSize, envelope, tolerance ) )
436
438
{
437
- unsigned char * targetWkb = new unsigned char [targetWkbSize];
438
- memcpy ( targetWkb, wkb, targetWkbSize );
439
- geometry->fromWkb ( targetWkb, targetWkbSize );
439
+ unsigned char * finalWkb = new unsigned char [finalWkbSize];
440
+ memcpy ( finalWkb, targetWkb, finalWkbSize );
441
+ geometry->fromWkb ( finalWkb, finalWkbSize );
442
+ delete [] targetWkb;
440
443
return true ;
441
444
}
445
+ delete [] targetWkb;
442
446
return false ;
443
447
}
444
448
0 commit comments