@@ -225,7 +225,7 @@ inline static float calculateViewPixelTolerance( const QgsRectangle& boundingRec
225
225
double mapUnitsFactor = 1 ;
226
226
227
227
// Calculate one aprox factor of the size of the BBOX from the source CoordinateSystem to the target CoordinateSystem.
228
- if (ct && !((QgsCoordinateTransform*)ct)->isShortCircuited ())
228
+ if ( ct && !((QgsCoordinateTransform*)ct)->isShortCircuited () )
229
229
{
230
230
QgsRectangle sourceRect = boundingRect;
231
231
QgsRectangle targetRect = ct->transform (sourceRect);
@@ -252,7 +252,7 @@ inline static QgsRectangle calculateBoundingBox( const QVector<QPointF>& points
252
252
double xmax = -std::numeric_limits<double >::max ();
253
253
double ymax = -std::numeric_limits<double >::max ();
254
254
255
- for (int i = 0 , numPoints = points.size (); i < numPoints; ++i)
255
+ for ( int i = 0 , numPoints = points.size (); i < numPoints; ++i )
256
256
{
257
257
x = points[i].x ();
258
258
y = points[i].y ();
@@ -278,10 +278,10 @@ inline static QgsRectangle calculateBoundingBox( QGis::WkbType wkbType, unsigned
278
278
int sizeOfDoubleX = sizeof (double );
279
279
int sizeOfDoubleY = QGis::wkbDimensions (wkbType)==3 /* hasZValue*/ ? 2 *sizeof (double ) : sizeof (double );
280
280
281
- for (size_t i = 0 ; i < numPoints; ++i)
281
+ for ( size_t i = 0 ; i < numPoints; ++i )
282
282
{
283
- x = *(( double * ) wkb ); wkb += sizeOfDoubleX;
284
- y = *(( double * ) wkb ); wkb += sizeOfDoubleY;
283
+ memcpy ( &x, wkb, sizeof ( double ) ); wkb += sizeOfDoubleX;
284
+ memcpy ( &y, wkb, sizeof ( double ) ); wkb += sizeOfDoubleY;
285
285
286
286
if (xmin>x) xmin = x;
287
287
if (ymin>y) ymin = y;
@@ -303,7 +303,7 @@ inline static bool generalizeGeometry( QGis::WkbType wkbType, unsigned char* sou
303
303
int sizeOfDoubleY = QGis::wkbDimensions (wkbType)==3 /* hasZValue*/ ? 2 *sizeof (double ) : sizeof (double );
304
304
305
305
// Skip the unnecesary generalization because of is a very single geometry
306
- size_t minimumSize = (geometryType==QGis::WKBLineString ? 4 + 2 *(sizeOfDoubleX+sizeOfDoubleY) : 8 + 5 *(sizeOfDoubleX+sizeOfDoubleY) );
306
+ size_t minimumSize = ( geometryType==QGis::WKBLineString ? 4 + 2 *(sizeOfDoubleX+sizeOfDoubleY) : 8 + 5 *(sizeOfDoubleX+sizeOfDoubleY) );
307
307
if ( writeHeader ) minimumSize += 5 ;
308
308
if ( sourceWkbSize <= minimumSize )
309
309
{
@@ -320,40 +320,48 @@ inline static bool generalizeGeometry( QGis::WkbType wkbType, unsigned char* sou
320
320
if ( writeHeader )
321
321
{
322
322
char byteOrder = QgsApplication::endian (); // byteOrder
323
- *targetWkb = byteOrder;
323
+ memcpy ( targetWkb, & byteOrder, 1 ) ;
324
324
targetWkb += 1 ;
325
325
326
- *(( int *) targetWkb) = geometryType; // type
326
+ memcpy ( targetWkb, & geometryType, 4 ) ; // type
327
327
targetWkb += 4 ;
328
328
329
- if (geometryType==QGis::WKBPolygon) { *((int *)targetWkb) = 1 ; targetWkb += 4 ; } // numRings
329
+ if ( geometryType == QGis::WKBPolygon ) // numRings
330
+ {
331
+ int numRings = 1 ;
332
+ memcpy ( targetWkb, &numRings, 4 );
333
+ targetWkb += 4 ;
334
+ }
330
335
}
331
336
332
337
// Write the generalized geometry
333
- if (geometryType== QGis::WKBLineString)
338
+ if ( geometryType == QGis::WKBLineString )
334
339
{
335
- *((int *)targetWkb) = 2 ; // numPoints;
336
- targetWkb += 4 ;
337
-
338
- double * ptr = (double *)targetWkb;
339
- targetWkb += 32 ;
340
+ int numPoints = 2 ;
341
+ memcpy ( targetWkb, &numPoints, 4 ); // numPoints;
342
+ targetWkb += 4 ;
340
343
341
- *ptr = x1; ptr++; *ptr = y1; ptr++;
342
- *ptr = x2; ptr++; *ptr = y2; ptr++;
344
+ memcpy ( targetWkb, &x1, sizeof ( double ) ); targetWkb += sizeof ( double );
345
+ memcpy ( targetWkb, &y1, sizeof ( double ) ); targetWkb += sizeof ( double );
346
+ memcpy ( targetWkb, &x2, sizeof ( double ) ); targetWkb += sizeof ( double );
347
+ memcpy ( targetWkb, &y2, sizeof ( double ) ); targetWkb += sizeof ( double );
343
348
}
344
349
else
345
350
{
346
- *((int *)targetWkb) = 5 ; // numPoints;
351
+ int numPoints = 5 ;
352
+ memcpy ( targetWkb, &numPoints, 4 ); // numPoints;
347
353
targetWkb += 4 ;
348
354
349
- double * ptr = (double *)targetWkb;
350
- targetWkb += 80 ;
351
-
352
- *ptr = x1; ptr++; *ptr = y1; ptr++;
353
- *ptr = x2; ptr++; *ptr = y1; ptr++;
354
- *ptr = x2; ptr++; *ptr = y2; ptr++;
355
- *ptr = x1; ptr++; *ptr = y2; ptr++;
356
- *ptr = x1; ptr++; *ptr = y1; ptr++;
355
+ memcpy ( targetWkb, &x1, sizeof ( double ) ); targetWkb += sizeof ( double );
356
+ memcpy ( targetWkb, &y1, sizeof ( double ) ); targetWkb += sizeof ( double );
357
+ memcpy ( targetWkb, &x2, sizeof ( double ) ); targetWkb += sizeof ( double );
358
+ memcpy ( targetWkb, &y1, sizeof ( double ) ); targetWkb += sizeof ( double );
359
+ memcpy ( targetWkb, &x2, sizeof ( double ) ); targetWkb += sizeof ( double );
360
+ memcpy ( targetWkb, &y2, sizeof ( double ) ); targetWkb += sizeof ( double );
361
+ memcpy ( targetWkb, &x1, sizeof ( double ) ); targetWkb += sizeof ( double );
362
+ memcpy ( targetWkb, &y2, sizeof ( double ) ); targetWkb += sizeof ( double );
363
+ memcpy ( targetWkb, &x1, sizeof ( double ) ); targetWkb += sizeof ( double );
364
+ memcpy ( targetWkb, &y1, sizeof ( double ) ); targetWkb += sizeof ( double );
357
365
}
358
366
targetWkbSize += targetWkb - wkb2;
359
367
targetWkb = wkb2;
@@ -377,11 +385,14 @@ inline static bool simplifyWkbGeometry( QGis::WkbType wkbType, unsigned char* so
377
385
// Write the main header of the geometry
378
386
if ( writeHeader )
379
387
{
380
- *targetWkb = * sourceWkb; // byteOrder
388
+ memcpy ( targetWkb, sourceWkb, 1 ) ; // byteOrder
381
389
sourceWkb += 1 ;
382
390
targetWkb += 1 ;
383
391
384
- *((int *)targetWkb) = QGis::flatType ( (QGis::WkbType) *((int *)sourceWkb) ); // type
392
+ int geometryType;
393
+ memcpy ( &geometryType, sourceWkb, 4 );
394
+ int flatType = QGis::flatType ( (QGis::WkbType)geometryType );
395
+ memcpy ( targetWkb, &flatType, 4 ); // type
385
396
sourceWkb += 4 ;
386
397
targetWkb += 4 ;
387
398
@@ -393,35 +404,36 @@ inline static bool simplifyWkbGeometry( QGis::WkbType wkbType, unsigned char* so
393
404
unsigned int flatType = QGis::flatType ( wkbType );
394
405
395
406
// Write the geometry
396
- if (flatType== QGis::WKBLineString || isaLinearRing)
407
+ if ( flatType == QGis::WKBLineString || isaLinearRing )
397
408
{
398
409
double x,y, lastX=0 ,lastY=0 ;
399
410
400
411
int sizeOfDoubleX = sizeof (double );
401
412
int sizeOfDoubleY = QGis::wkbDimensions (wkbType)==3 /* hasZValue*/ ? 2 *sizeof (double ) : sizeof (double );
402
413
403
- int numPoints = *((int *)sourceWkb);
414
+ int numPoints;
415
+ memcpy ( &numPoints, sourceWkb, 4 );
404
416
sourceWkb += 4 ;
405
417
if (numPoints <= (isaLinearRing ? 5 : 2 )) canbeGeneralizable = false ;
406
418
407
419
int numTargetPoints = 0 ;
408
- *(( int *) targetWkb) = numTargetPoints;
420
+ memcpy ( targetWkb, & numTargetPoints, 4 ) ;
409
421
targetWkb += 4 ;
410
422
targetWkbSize += 4 ;
411
423
412
424
double * ptr = (double *)targetWkb;
413
425
map2pixelTol *= map2pixelTol; // -> Use mappixelTol for 'LengthSquare' calculations.
414
426
415
427
// Process each vertex...
416
- for (int i = 0 , numPoints_i = (isaLinearRing ? numPoints-1 : numPoints); i < numPoints_i; ++i)
428
+ for ( int i = 0 , numPoints_i = (isaLinearRing ? numPoints-1 : numPoints); i < numPoints_i; ++i )
417
429
{
418
- x = *(( double *)sourceWkb ); sourceWkb += sizeOfDoubleX;
419
- y = *(( double *)sourceWkb ); sourceWkb += sizeOfDoubleY;
430
+ memcpy ( &x, sourceWkb, sizeof ( double ) ); sourceWkb += sizeOfDoubleX;
431
+ memcpy ( &y, sourceWkb, sizeof ( double ) ); sourceWkb += sizeOfDoubleY;
420
432
421
433
if ( i==0 || !canbeGeneralizable || calculateLengthSquared2D (x,y,lastX,lastY)>map2pixelTol )
422
434
{
423
- * ptr = lastX = x; ptr++;
424
- * ptr = lastY = y; ptr++;
435
+ memcpy ( ptr, &x, sizeof ( double ) ); lastX = x; ptr++;
436
+ memcpy ( ptr, &y, sizeof ( double ) ); lastY = y; ptr++;
425
437
numTargetPoints++;
426
438
}
427
439
}
@@ -430,29 +442,33 @@ inline static bool simplifyWkbGeometry( QGis::WkbType wkbType, unsigned char* so
430
442
// Fix the topology of the geometry
431
443
if ( isaLinearRing )
432
444
{
433
- *ptr = x = *((double *)(targetWkb+0 )); ptr++;
434
- *ptr = y = *((double *)(targetWkb+8 )); ptr++;
445
+ memcpy ( &x, targetWkb+0 , sizeof ( double ) );
446
+ memcpy ( &y, targetWkb+8 , sizeof ( double ) );
447
+ memcpy ( ptr, &x, sizeof ( double ) ); ptr++;
448
+ memcpy ( ptr, &y, sizeof ( double ) ); ptr++;
435
449
numTargetPoints++;
436
450
}
437
451
targetWkbSize += numTargetPoints * 16 ;
438
452
targetWkb = wkb2;
439
453
440
- *(( int *) targetWkb) = numTargetPoints;
454
+ memcpy ( targetWkb, & numTargetPoints, 4 ) ;
441
455
result = numPoints!=numTargetPoints;
442
456
}
443
457
else
444
- if (flatType== QGis::WKBPolygon)
458
+ if ( flatType == QGis::WKBPolygon )
445
459
{
446
- int numRings = *((int *)sourceWkb);
460
+ int numRings;
461
+ memcpy ( &numRings, sourceWkb, 4 );
447
462
sourceWkb += 4 ;
448
463
449
- *(( int *) targetWkb) = numRings;
464
+ memcpy ( targetWkb, & numRings, 4 ) ;
450
465
targetWkb += 4 ;
451
466
targetWkbSize += 4 ;
452
467
453
- for (int i = 0 ; i < numRings; ++i)
468
+ for ( int i = 0 ; i < numRings; ++i )
454
469
{
455
- int numPoints_i = *((int *)sourceWkb);
470
+ int numPoints_i;
471
+ memcpy ( &numPoints_i, sourceWkb, 4 );
456
472
QgsRectangle envelope_i = numRings==1 ? envelope : calculateBoundingBox ( wkbType, sourceWkb+4 , numPoints_i );
457
473
458
474
size_t sourceWkbSize_i = 4 + numPoints_i * (hasZValue ? 3 : 2 ) * sizeof (double );
@@ -466,39 +482,43 @@ inline static bool simplifyWkbGeometry( QGis::WkbType wkbType, unsigned char* so
466
482
}
467
483
}
468
484
else
469
- if (flatType== QGis::WKBMultiLineString || flatType== QGis::WKBMultiPolygon)
485
+ if ( flatType == QGis::WKBMultiLineString || flatType == QGis::WKBMultiPolygon )
470
486
{
471
- int numGeoms = *((int *)sourceWkb);
487
+ int numGeoms;
488
+ memcpy ( &numGeoms, sourceWkb, 4 );
472
489
sourceWkb += 4 ;
473
490
wkb1 += 4 ;
474
491
475
- *(( int *) targetWkb) = numGeoms;
492
+ memcpy ( targetWkb, & numGeoms, 4 ) ;
476
493
targetWkb += 4 ;
477
494
targetWkbSize += 4 ;
478
495
479
- for (int i = 0 ; i < numGeoms; ++i)
496
+ for ( int i = 0 ; i < numGeoms; ++i )
480
497
{
481
498
size_t sourceWkbSize_i = 0 ;
482
499
size_t targetWkbSize_i = 0 ;
483
500
484
501
// ... calculate the wkb-size of the current child complex geometry
485
- if (flatType== QGis::WKBMultiLineString)
502
+ if ( flatType == QGis::WKBMultiLineString )
486
503
{
487
- int numPoints_i = *((int *)(wkb1+5 ));
504
+ int numPoints_i;
505
+ memcpy ( &numPoints_i, wkb1+5 , 4 );
488
506
int wkbSize_i = 4 + numPoints_i * (hasZValue ? 3 : 2 ) * sizeof (double );
489
507
490
508
sourceWkbSize_i += 5 + wkbSize_i;
491
509
wkb1 += 5 + wkbSize_i;
492
510
}
493
511
else
494
512
{
495
- int numPrings_i = *((int *)(wkb1+5 ));
513
+ int numPrings_i;
514
+ memcpy ( &numPrings_i, wkb1+5 , 4 );
496
515
sourceWkbSize_i = 9 ;
497
516
wkb1 += 9 ;
498
517
499
518
for (int j = 0 ; j < numPrings_i; ++j)
500
519
{
501
- int numPoints_i = *((int *)(wkb1));
520
+ int numPoints_i;
521
+ memcpy ( &numPoints_i, wkb1, 4 );
502
522
int wkbSize_i = 4 + numPoints_i * (hasZValue ? 3 : 2 ) * sizeof (double );
503
523
504
524
sourceWkbSize_i += wkbSize_i;
@@ -549,7 +569,7 @@ bool QgsFeatureRequest::simplifyGeometry( QgsGeometry* geometry, const QgsCoordi
549
569
550
570
// Check whether the geometry can be simplified using the map2pixel context
551
571
QGis::GeometryType geometryType = geometry->type ();
552
- if (!(geometryType==QGis::Line || geometryType==QGis::Polygon)) return false ;
572
+ if ( !(geometryType==QGis::Line || geometryType==QGis::Polygon) ) return false ;
553
573
554
574
QgsRectangle envelope = geometry->boundingBox ();
555
575
QGis::WkbType wkbType = geometry->wkbType ();
@@ -573,7 +593,7 @@ bool QgsFeatureRequest::simplifyGeometry( QgsGeometry* geometry, const QgsCoordi
573
593
bool QgsFeatureRequest::simplifyGeometry ( QGis::GeometryType geometryType, const QgsRectangle& envelope, double * xptr, int xStride, double * yptr, int yStride, int pointCount, int & pointSimplifiedCount, const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mtp, float mapToPixelTol )
574
594
{
575
595
pointSimplifiedCount = pointCount;
576
- if (geometryType== QGis::Point || geometryType== QGis::UnknownGeometry) return false ;
596
+ if ( geometryType == QGis::Point || geometryType == QGis::UnknownGeometry ) return false ;
577
597
pointSimplifiedCount = 0 ;
578
598
579
599
double map2pixelTol = mapToPixelTol * calculateViewPixelTolerance ( envelope, coordinateTransform, mtp );
@@ -587,20 +607,20 @@ bool QgsFeatureRequest::simplifyGeometry( QGis::GeometryType geometryType, const
587
607
588
608
for ( int i = 0 , numPoints = geometryType==QGis::Polygon ? pointCount-1 : pointCount; i < numPoints; ++i )
589
609
{
590
- x = *(( double *)xsourcePtr ); xsourcePtr += xStride;
591
- y = *(( double *)ysourcePtr ); ysourcePtr += yStride;
610
+ memcpy ( &x, xsourcePtr, sizeof ( double ) ); xsourcePtr += xStride;
611
+ memcpy ( &y, ysourcePtr, sizeof ( double ) ); ysourcePtr += yStride;
592
612
593
613
if ( i==0 || calculateLengthSquared2D (x,y,lastX,lastY)>map2pixelTol )
594
614
{
595
- *(( double *)xtargetPtr) = lastX = x; xtargetPtr += xStride;
596
- *(( double *)ytargetPtr) = lastY = y; ytargetPtr += yStride;
615
+ memcpy ( xtargetPtr, &x, sizeof ( double ) ); lastX = x; xtargetPtr += xStride;
616
+ memcpy ( ytargetPtr, &y, sizeof ( double ) ); lastY = y; ytargetPtr += yStride;
597
617
pointSimplifiedCount++;
598
618
}
599
619
}
600
- if ( geometryType== QGis::Polygon )
620
+ if ( geometryType == QGis::Polygon )
601
621
{
602
- *(( double *)xtargetPtr) = *xptr ;
603
- *(( double *)ytargetPtr) = *yptr ;
622
+ memcpy ( xtargetPtr, xptr, sizeof ( double ) ) ;
623
+ memcpy ( ytargetPtr, yptr, sizeof ( double ) ) ;
604
624
pointSimplifiedCount++;
605
625
}
606
626
return pointSimplifiedCount!=pointCount;
0 commit comments