@@ -232,7 +232,7 @@ inline static float calculateViewPixelTolerance( const QgsRectangle& boundingRec
232
232
double mapUnitsFactor = 1 ;
233
233
234
234
// Calculate one aprox factor of the size of the BBOX from the source CoordinateSystem to the target CoordinateSystem.
235
- if (ct && !((QgsCoordinateTransform*)ct)->isShortCircuited ())
235
+ if ( ct && !((QgsCoordinateTransform*)ct)->isShortCircuited () )
236
236
{
237
237
QgsRectangle sourceRect = boundingRect;
238
238
QgsRectangle targetRect = ct->transform (sourceRect);
@@ -259,7 +259,7 @@ inline static QgsRectangle calculateBoundingBox( const QVector<QPointF>& points
259
259
double xmax = -std::numeric_limits<double >::max ();
260
260
double ymax = -std::numeric_limits<double >::max ();
261
261
262
- for (int i = 0 , numPoints = points.size (); i < numPoints; ++i)
262
+ for ( int i = 0 , numPoints = points.size (); i < numPoints; ++i )
263
263
{
264
264
x = points[i].x ();
265
265
y = points[i].y ();
@@ -285,10 +285,10 @@ inline static QgsRectangle calculateBoundingBox( QGis::WkbType wkbType, unsigned
285
285
int sizeOfDoubleX = sizeof (double );
286
286
int sizeOfDoubleY = QGis::wkbDimensions (wkbType)==3 /* hasZValue*/ ? 2 *sizeof (double ) : sizeof (double );
287
287
288
- for (size_t i = 0 ; i < numPoints; ++i)
288
+ for ( size_t i = 0 ; i < numPoints; ++i )
289
289
{
290
- x = *(( double * ) wkb ); wkb += sizeOfDoubleX;
291
- y = *(( double * ) wkb ); wkb += sizeOfDoubleY;
290
+ memcpy ( &x, wkb, sizeof ( double ) ); wkb += sizeOfDoubleX;
291
+ memcpy ( &y, wkb, sizeof ( double ) ); wkb += sizeOfDoubleY;
292
292
293
293
if (xmin>x) xmin = x;
294
294
if (ymin>y) ymin = y;
@@ -310,7 +310,7 @@ inline static bool generalizeGeometry( QGis::WkbType wkbType, unsigned char* sou
310
310
int sizeOfDoubleY = QGis::wkbDimensions (wkbType)==3 /* hasZValue*/ ? 2 *sizeof (double ) : sizeof (double );
311
311
312
312
// Skip the unnecesary generalization because of is a very single geometry
313
- size_t minimumSize = (geometryType==QGis::WKBLineString ? 4 + 2 *(sizeOfDoubleX+sizeOfDoubleY) : 8 + 5 *(sizeOfDoubleX+sizeOfDoubleY) );
313
+ size_t minimumSize = ( geometryType==QGis::WKBLineString ? 4 + 2 *(sizeOfDoubleX+sizeOfDoubleY) : 8 + 5 *(sizeOfDoubleX+sizeOfDoubleY) );
314
314
if ( writeHeader ) minimumSize += 5 ;
315
315
if ( sourceWkbSize <= minimumSize )
316
316
{
@@ -327,40 +327,48 @@ inline static bool generalizeGeometry( QGis::WkbType wkbType, unsigned char* sou
327
327
if ( writeHeader )
328
328
{
329
329
char byteOrder = QgsApplication::endian (); // byteOrder
330
- *targetWkb = byteOrder;
330
+ memcpy ( targetWkb, & byteOrder, 1 ) ;
331
331
targetWkb += 1 ;
332
332
333
- *(( int *) targetWkb) = geometryType; // type
333
+ memcpy ( targetWkb, & geometryType, 4 ) ; // type
334
334
targetWkb += 4 ;
335
335
336
- if (geometryType==QGis::WKBPolygon) { *((int *)targetWkb) = 1 ; targetWkb += 4 ; } // numRings
336
+ if ( geometryType == QGis::WKBPolygon ) // numRings
337
+ {
338
+ int numRings = 1 ;
339
+ memcpy ( targetWkb, &numRings, 4 );
340
+ targetWkb += 4 ;
341
+ }
337
342
}
338
343
339
344
// Write the generalized geometry
340
- if (geometryType== QGis::WKBLineString)
345
+ if ( geometryType == QGis::WKBLineString )
341
346
{
342
- *((int *)targetWkb) = 2 ; // numPoints;
343
- targetWkb += 4 ;
344
-
345
- double * ptr = (double *)targetWkb;
346
- targetWkb += 32 ;
347
+ int numPoints = 2 ;
348
+ memcpy ( targetWkb, &numPoints, 4 ); // numPoints;
349
+ targetWkb += 4 ;
347
350
348
- *ptr = x1; ptr++; *ptr = y1 ; ptr++;
349
- *ptr = x2; ptr++; *ptr = y2; ptr++;
351
+ memcpy ( targetWkb, &x1, sizeof ( double ) ); targetWkb += sizeof ( double );
352
+ memcpy ( targetWkb, &y1 , sizeof ( double ) ); targetWkb += sizeof ( double );
353
+ memcpy ( targetWkb, &x2, sizeof ( double ) ); targetWkb += sizeof ( double );
354
+ memcpy ( targetWkb, &y2, sizeof ( double ) ); targetWkb += sizeof ( double );
350
355
}
351
356
else
352
357
{
353
- *((int *)targetWkb) = 5 ; // numPoints;
358
+ int numPoints = 5 ;
359
+ memcpy ( targetWkb, &numPoints, 4 ); // numPoints;
354
360
targetWkb += 4 ;
355
361
356
- double * ptr = (double *)targetWkb;
357
- targetWkb += 80 ;
358
-
359
- *ptr = x1; ptr++; *ptr = y1 ; ptr++;
360
- *ptr = x2; ptr++; *ptr = y1 ; ptr++;
361
- *ptr = x2; ptr++; *ptr = y2; ptr++;
362
- *ptr = x1; ptr++; *ptr = y2; ptr++;
363
- *ptr = x1; ptr++; *ptr = y1 ; ptr++;
362
+ memcpy ( targetWkb, &x1, sizeof ( double ) ); targetWkb += sizeof ( double );
363
+ memcpy ( targetWkb, &y1 , sizeof ( double ) ); targetWkb += sizeof ( double );
364
+ memcpy ( targetWkb, &x2, sizeof ( double ) ); targetWkb += sizeof ( double );
365
+ memcpy ( targetWkb, &y1 , sizeof ( double ) ); targetWkb += sizeof ( double );
366
+ memcpy ( targetWkb, &x2, sizeof ( double ) ); targetWkb += sizeof ( double );
367
+ memcpy ( targetWkb, &y2, sizeof ( double ) ); targetWkb += sizeof ( double );
368
+ memcpy ( targetWkb, &x1, sizeof ( double ) ); targetWkb += sizeof ( double );
369
+ memcpy ( targetWkb, &y2, sizeof ( double ) ); targetWkb += sizeof ( double );
370
+ memcpy ( targetWkb, &x1, sizeof ( double ) ); targetWkb += sizeof ( double );
371
+ memcpy ( targetWkb, &y1 , sizeof ( double ) ); targetWkb += sizeof ( double );
364
372
}
365
373
targetWkbSize += targetWkb - wkb2;
366
374
targetWkb = wkb2;
@@ -384,11 +392,14 @@ inline static bool simplifyWkbGeometry( QGis::WkbType wkbType, unsigned char* so
384
392
// Write the main header of the geometry
385
393
if ( writeHeader )
386
394
{
387
- *targetWkb = * sourceWkb; // byteOrder
395
+ memcpy ( targetWkb, sourceWkb, 1 ) ; // byteOrder
388
396
sourceWkb += 1 ;
389
397
targetWkb += 1 ;
390
398
391
- *((int *)targetWkb) = QGis::flatType ( (QGis::WkbType) *((int *)sourceWkb) ); // type
399
+ int geometryType;
400
+ memcpy ( &geometryType, sourceWkb, 4 );
401
+ int flatType = QGis::flatType ( (QGis::WkbType)geometryType );
402
+ memcpy ( targetWkb, &flatType, 4 ); // type
392
403
sourceWkb += 4 ;
393
404
targetWkb += 4 ;
394
405
@@ -400,35 +411,36 @@ inline static bool simplifyWkbGeometry( QGis::WkbType wkbType, unsigned char* so
400
411
unsigned int flatType = QGis::flatType ( wkbType );
401
412
402
413
// Write the geometry
403
- if (flatType== QGis::WKBLineString || isaLinearRing)
414
+ if ( flatType == QGis::WKBLineString || isaLinearRing )
404
415
{
405
416
double x,y, lastX=0 ,lastY=0 ;
406
417
407
418
int sizeOfDoubleX = sizeof (double );
408
419
int sizeOfDoubleY = QGis::wkbDimensions (wkbType)==3 /* hasZValue*/ ? 2 *sizeof (double ) : sizeof (double );
409
420
410
- int numPoints = *((int *)sourceWkb);
421
+ int numPoints;
422
+ memcpy ( &numPoints, sourceWkb, 4 );
411
423
sourceWkb += 4 ;
412
424
if (numPoints <= (isaLinearRing ? 5 : 2 )) canbeGeneralizable = false ;
413
425
414
426
int numTargetPoints = 0 ;
415
- *(( int *) targetWkb) = numTargetPoints;
427
+ memcpy ( targetWkb, & numTargetPoints, 4 ) ;
416
428
targetWkb += 4 ;
417
429
targetWkbSize += 4 ;
418
430
419
431
double * ptr = (double *)targetWkb;
420
432
map2pixelTol *= map2pixelTol; // -> Use mappixelTol for 'LengthSquare' calculations.
421
433
422
434
// Process each vertex...
423
- for (int i = 0 , numPoints_i = (isaLinearRing ? numPoints-1 : numPoints); i < numPoints_i; ++i)
435
+ for ( int i = 0 , numPoints_i = (isaLinearRing ? numPoints-1 : numPoints); i < numPoints_i; ++i )
424
436
{
425
- x = *(( double *)sourceWkb ); sourceWkb += sizeOfDoubleX;
426
- y = *(( double *)sourceWkb ); sourceWkb += sizeOfDoubleY;
437
+ memcpy ( &x, sourceWkb, sizeof ( double ) ); sourceWkb += sizeOfDoubleX;
438
+ memcpy ( &y, sourceWkb, sizeof ( double ) ); sourceWkb += sizeOfDoubleY;
427
439
428
440
if ( i==0 || !canbeGeneralizable || calculateLengthSquared2D (x,y,lastX,lastY)>map2pixelTol )
429
441
{
430
- * ptr = lastX = x; ptr++;
431
- * ptr = lastY = y; ptr++;
442
+ memcpy ( ptr, &x, sizeof ( double ) ); lastX = x; ptr++;
443
+ memcpy ( ptr, &y, sizeof ( double ) ); lastY = y; ptr++;
432
444
numTargetPoints++;
433
445
}
434
446
}
@@ -437,29 +449,33 @@ inline static bool simplifyWkbGeometry( QGis::WkbType wkbType, unsigned char* so
437
449
// Fix the topology of the geometry
438
450
if ( isaLinearRing )
439
451
{
440
- *ptr = x = *((double *)(targetWkb+0 )); ptr++;
441
- *ptr = y = *((double *)(targetWkb+8 )); ptr++;
452
+ memcpy ( &x, targetWkb+0 , sizeof ( double ) );
453
+ memcpy ( &y, targetWkb+8 , sizeof ( double ) );
454
+ memcpy ( ptr, &x, sizeof ( double ) ); ptr++;
455
+ memcpy ( ptr, &y, sizeof ( double ) ); ptr++;
442
456
numTargetPoints++;
443
457
}
444
458
targetWkbSize += numTargetPoints * 16 ;
445
459
targetWkb = wkb2;
446
460
447
- *(( int *) targetWkb) = numTargetPoints;
461
+ memcpy ( targetWkb, & numTargetPoints, 4 ) ;
448
462
result = numPoints!=numTargetPoints;
449
463
}
450
464
else
451
- if (flatType== QGis::WKBPolygon)
465
+ if ( flatType == QGis::WKBPolygon )
452
466
{
453
- int numRings = *((int *)sourceWkb);
467
+ int numRings;
468
+ memcpy ( &numRings, sourceWkb, 4 );
454
469
sourceWkb += 4 ;
455
470
456
- *(( int *) targetWkb) = numRings;
471
+ memcpy ( targetWkb, & numRings, 4 ) ;
457
472
targetWkb += 4 ;
458
473
targetWkbSize += 4 ;
459
474
460
- for (int i = 0 ; i < numRings; ++i)
475
+ for ( int i = 0 ; i < numRings; ++i )
461
476
{
462
- int numPoints_i = *((int *)sourceWkb);
477
+ int numPoints_i;
478
+ memcpy ( &numPoints_i, sourceWkb, 4 );
463
479
QgsRectangle envelope_i = numRings==1 ? envelope : calculateBoundingBox ( wkbType, sourceWkb+4 , numPoints_i );
464
480
465
481
size_t sourceWkbSize_i = 4 + numPoints_i * (hasZValue ? 3 : 2 ) * sizeof (double );
@@ -473,39 +489,43 @@ inline static bool simplifyWkbGeometry( QGis::WkbType wkbType, unsigned char* so
473
489
}
474
490
}
475
491
else
476
- if (flatType== QGis::WKBMultiLineString || flatType== QGis::WKBMultiPolygon)
492
+ if ( flatType == QGis::WKBMultiLineString || flatType == QGis::WKBMultiPolygon )
477
493
{
478
- int numGeoms = *((int *)sourceWkb);
494
+ int numGeoms;
495
+ memcpy ( &numGeoms, sourceWkb, 4 );
479
496
sourceWkb += 4 ;
480
497
wkb1 += 4 ;
481
498
482
- *(( int *) targetWkb) = numGeoms;
499
+ memcpy ( targetWkb, & numGeoms, 4 ) ;
483
500
targetWkb += 4 ;
484
501
targetWkbSize += 4 ;
485
502
486
- for (int i = 0 ; i < numGeoms; ++i)
503
+ for ( int i = 0 ; i < numGeoms; ++i )
487
504
{
488
505
size_t sourceWkbSize_i = 0 ;
489
506
size_t targetWkbSize_i = 0 ;
490
507
491
508
// ... calculate the wkb-size of the current child complex geometry
492
- if (flatType== QGis::WKBMultiLineString)
509
+ if ( flatType == QGis::WKBMultiLineString )
493
510
{
494
- int numPoints_i = *((int *)(wkb1+5 ));
511
+ int numPoints_i;
512
+ memcpy ( &numPoints_i, wkb1+5 , 4 );
495
513
int wkbSize_i = 4 + numPoints_i * (hasZValue ? 3 : 2 ) * sizeof (double );
496
514
497
515
sourceWkbSize_i += 5 + wkbSize_i;
498
516
wkb1 += 5 + wkbSize_i;
499
517
}
500
518
else
501
519
{
502
- int numPrings_i = *((int *)(wkb1+5 ));
520
+ int numPrings_i;
521
+ memcpy ( &numPrings_i, wkb1+5 , 4 );
503
522
sourceWkbSize_i = 9 ;
504
523
wkb1 += 9 ;
505
524
506
525
for (int j = 0 ; j < numPrings_i; ++j)
507
526
{
508
- int numPoints_i = *((int *)(wkb1));
527
+ int numPoints_i;
528
+ memcpy ( &numPoints_i, wkb1, 4 );
509
529
int wkbSize_i = 4 + numPoints_i * (hasZValue ? 3 : 2 ) * sizeof (double );
510
530
511
531
sourceWkbSize_i += wkbSize_i;
@@ -556,7 +576,7 @@ bool QgsFeatureRequest::simplifyGeometry( QgsGeometry* geometry, const QgsCoordi
556
576
557
577
// Check whether the geometry can be simplified using the map2pixel context
558
578
QGis::GeometryType geometryType = geometry->type ();
559
- if (!(geometryType==QGis::Line || geometryType==QGis::Polygon)) return false ;
579
+ if ( !(geometryType==QGis::Line || geometryType==QGis::Polygon) ) return false ;
560
580
561
581
QgsRectangle envelope = geometry->boundingBox ();
562
582
QGis::WkbType wkbType = geometry->wkbType ();
@@ -580,7 +600,7 @@ bool QgsFeatureRequest::simplifyGeometry( QgsGeometry* geometry, const QgsCoordi
580
600
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 )
581
601
{
582
602
pointSimplifiedCount = pointCount;
583
- if (geometryType== QGis::Point || geometryType== QGis::UnknownGeometry) return false ;
603
+ if ( geometryType == QGis::Point || geometryType == QGis::UnknownGeometry ) return false ;
584
604
pointSimplifiedCount = 0 ;
585
605
586
606
double map2pixelTol = mapToPixelTol * calculateViewPixelTolerance ( envelope, coordinateTransform, mtp );
@@ -594,20 +614,20 @@ bool QgsFeatureRequest::simplifyGeometry( QGis::GeometryType geometryType, const
594
614
595
615
for ( int i = 0 , numPoints = geometryType==QGis::Polygon ? pointCount-1 : pointCount; i < numPoints; ++i )
596
616
{
597
- x = *(( double *)xsourcePtr ); xsourcePtr += xStride;
598
- y = *(( double *)ysourcePtr ); ysourcePtr += yStride;
617
+ memcpy ( &x, xsourcePtr, sizeof ( double ) ); xsourcePtr += xStride;
618
+ memcpy ( &y, ysourcePtr, sizeof ( double ) ); ysourcePtr += yStride;
599
619
600
620
if ( i==0 || calculateLengthSquared2D (x,y,lastX,lastY)>map2pixelTol )
601
621
{
602
- *(( double *)xtargetPtr) = lastX = x; xtargetPtr += xStride;
603
- *(( double *)ytargetPtr) = lastY = y; ytargetPtr += yStride;
622
+ memcpy ( xtargetPtr, &x, sizeof ( double ) ); lastX = x; xtargetPtr += xStride;
623
+ memcpy ( ytargetPtr, &y, sizeof ( double ) ); lastY = y; ytargetPtr += yStride;
604
624
pointSimplifiedCount++;
605
625
}
606
626
}
607
- if ( geometryType== QGis::Polygon )
627
+ if ( geometryType == QGis::Polygon )
608
628
{
609
- *(( double *)xtargetPtr) = *xptr ;
610
- *(( double *)ytargetPtr) = *yptr ;
629
+ memcpy ( xtargetPtr, xptr, sizeof ( double ) ) ;
630
+ memcpy ( ytargetPtr, yptr, sizeof ( double ) ) ;
611
631
pointSimplifiedCount++;
612
632
}
613
633
return pointSimplifiedCount!=pointCount;
0 commit comments