@@ -2993,6 +2993,132 @@ int QgsGeometry::translate( double dx, double dy )
2993
2993
return 0 ;
2994
2994
}
2995
2995
2996
+ int QgsGeometry::transform ( QgsCoordinateTransform& ct )
2997
+ {
2998
+ if ( mDirtyWkb )
2999
+ {
3000
+ exportGeosToWkb ();
3001
+ }
3002
+
3003
+ if ( !mGeometry )
3004
+ {
3005
+ QgsDebugMsg ( " WKB geometry not available!" );
3006
+ return 1 ;
3007
+ }
3008
+
3009
+ QGis::WKBTYPE wkbType;
3010
+ memcpy ( &wkbType, &( mGeometry [1 ] ), sizeof ( int ) );
3011
+ bool hasZValue = false ;
3012
+ int wkbPosition = 5 ;
3013
+
3014
+ switch ( wkbType )
3015
+ {
3016
+ case QGis::WKBPoint25D:
3017
+ case QGis::WKBPoint:
3018
+ {
3019
+ transformVertex ( wkbPosition, ct, hasZValue );
3020
+ }
3021
+ break ;
3022
+
3023
+ case QGis::WKBLineString25D:
3024
+ hasZValue = true ;
3025
+ case QGis::WKBLineString:
3026
+ {
3027
+ int * npoints = ( int * )( &mGeometry [wkbPosition] );
3028
+ wkbPosition += sizeof ( int );
3029
+ for ( int index = 0 ;index < *npoints;++index )
3030
+ {
3031
+ transformVertex ( wkbPosition, ct, hasZValue );
3032
+ }
3033
+ break ;
3034
+ }
3035
+
3036
+ case QGis::WKBPolygon25D:
3037
+ hasZValue = true ;
3038
+ case QGis::WKBPolygon:
3039
+ {
3040
+ int * nrings = ( int * )( &( mGeometry [wkbPosition] ) );
3041
+ wkbPosition += sizeof ( int );
3042
+ int * npoints;
3043
+
3044
+ for ( int index = 0 ;index < *nrings;++index )
3045
+ {
3046
+ npoints = ( int * )( &( mGeometry [wkbPosition] ) );
3047
+ wkbPosition += sizeof ( int );
3048
+ for ( int index2 = 0 ;index2 < *npoints;++index2 )
3049
+ {
3050
+ transformVertex ( wkbPosition, ct, hasZValue );
3051
+ }
3052
+ }
3053
+ break ;
3054
+ }
3055
+
3056
+ case QGis::WKBMultiPoint25D:
3057
+ hasZValue = true ;
3058
+ case QGis::WKBMultiPoint:
3059
+ {
3060
+ int * npoints = ( int * )( &( mGeometry [wkbPosition] ) );
3061
+ wkbPosition += sizeof ( int );
3062
+ for ( int index = 0 ;index < *npoints;++index )
3063
+ {
3064
+ wkbPosition += ( sizeof ( int ) + 1 );
3065
+ transformVertex ( wkbPosition, ct, hasZValue );
3066
+ }
3067
+ break ;
3068
+ }
3069
+
3070
+ case QGis::WKBMultiLineString25D:
3071
+ hasZValue = true ;
3072
+ case QGis::WKBMultiLineString:
3073
+ {
3074
+ int * nlines = ( int * )( &( mGeometry [wkbPosition] ) );
3075
+ int * npoints = 0 ;
3076
+ wkbPosition += sizeof ( int );
3077
+ for ( int index = 0 ;index < *nlines;++index )
3078
+ {
3079
+ wkbPosition += ( sizeof ( int ) + 1 );
3080
+ npoints = ( int * )( &( mGeometry [wkbPosition] ) );
3081
+ wkbPosition += sizeof ( int );
3082
+ for ( int index2 = 0 ; index2 < *npoints; ++index2 )
3083
+ {
3084
+ transformVertex ( wkbPosition, ct, hasZValue );
3085
+ }
3086
+ }
3087
+ break ;
3088
+ }
3089
+
3090
+ case QGis::WKBMultiPolygon25D:
3091
+ hasZValue = true ;
3092
+ case QGis::WKBMultiPolygon:
3093
+ {
3094
+ int * npolys = ( int * )( &( mGeometry [wkbPosition] ) );
3095
+ int * nrings;
3096
+ int * npoints;
3097
+ wkbPosition += sizeof ( int );
3098
+ for ( int index = 0 ;index < *npolys;++index )
3099
+ {
3100
+ wkbPosition += ( 1 + sizeof ( int ) ); // skip endian and polygon type
3101
+ nrings = ( int * )( &( mGeometry [wkbPosition] ) );
3102
+ wkbPosition += sizeof ( int );
3103
+ for ( int index2 = 0 ;index2 < *nrings;++index2 )
3104
+ {
3105
+ npoints = ( int * )( &( mGeometry [wkbPosition] ) );
3106
+ wkbPosition += sizeof ( int );
3107
+ for ( int index3 = 0 ;index3 < *npoints;++index3 )
3108
+ {
3109
+ transformVertex ( wkbPosition, ct, hasZValue );
3110
+ }
3111
+ }
3112
+ }
3113
+ }
3114
+
3115
+ default :
3116
+ break ;
3117
+ }
3118
+ mDirtyGeos = true ;
3119
+ return 0 ;
3120
+ }
3121
+
2996
3122
int QgsGeometry::splitGeometry ( const QList<QgsPoint>& splitLine, QList<QgsGeometry*>& newGeometries )
2997
3123
{
2998
3124
int returnCode = 0 ;
@@ -4569,6 +4695,31 @@ void QgsGeometry::translateVertex( int& wkbPosition, double dx, double dy, bool
4569
4695
}
4570
4696
}
4571
4697
4698
+ void QgsGeometry::transformVertex ( int & wkbPosition, QgsCoordinateTransform& ct, bool hasZValue )
4699
+ {
4700
+ double x, y, z;
4701
+
4702
+
4703
+ x = *(( double * )( &( mGeometry [wkbPosition] ) ) );
4704
+ y = *(( double * )( &( mGeometry [wkbPosition + sizeof ( double )] ) ) );
4705
+ z = 0.0 ; // Ignore Z for now.
4706
+
4707
+ ct.transformInPlace ( x, y, z);
4708
+
4709
+ // new x-coordinate
4710
+ memcpy ( &( mGeometry [wkbPosition] ), &x, sizeof ( double ) );
4711
+ wkbPosition += sizeof ( double );
4712
+
4713
+ // new y-coordinate
4714
+ memcpy ( &( mGeometry [wkbPosition] ), &y, sizeof ( double ) );
4715
+ wkbPosition += sizeof ( double );
4716
+
4717
+ if ( hasZValue )
4718
+ {
4719
+ wkbPosition += sizeof ( double );
4720
+ }
4721
+ }
4722
+
4572
4723
int QgsGeometry::splitLinearGeometry ( GEOSGeometry *splitLine, QList<QgsGeometry*>& newGeometries )
4573
4724
{
4574
4725
if ( !splitLine )
0 commit comments