22 : mSimplifyFlags( simplifyFlags )
23 , mTolerance( tolerance )
36 float vx = ( float )( x2 - x1 );
37 float vy = ( float )( y2 - y1 );
50 int sizeOfDoubleX =
sizeof( double );
51 int sizeOfDoubleY =
QGis::wkbDimensions( wkbType ) == 3 ? 2 *
sizeof( double ) :
sizeof(
double );
53 for (
size_t i = 0; i < numPoints; ++i )
55 memcpy( &x, wkb,
sizeof(
double ) ); wkb += sizeOfDoubleX;
56 memcpy( &y, wkb,
sizeof(
double ) ); wkb += sizeOfDoubleY;
58 if ( xmin > x ) xmin = x;
59 if ( ymin > y ) ymin = y;
60 if ( xmax < x ) xmax = x;
61 if ( ymax < y ) ymax = y;
70 Q_UNUSED( sourceWkb );
71 unsigned char* wkb2 = targetWkb;
74 int sizeOfDoubleX =
sizeof( double );
75 int sizeOfDoubleY =
QGis::wkbDimensions( wkbType ) == 3 ? 2 *
sizeof( double ) :
sizeof(
double );
78 size_t minimumSize = ( geometryType ==
QGis::WKBLineString ? 4 + 2 * ( sizeOfDoubleX + sizeOfDoubleY ) : 8 + 5 * ( sizeOfDoubleX + sizeOfDoubleY ) );
79 if ( writeHeader ) minimumSize += 5;
80 if ( sourceWkbSize <= minimumSize )
95 memcpy( targetWkb, &byteOrder, 1 );
98 memcpy( targetWkb, &geometryType, 4 );
104 memcpy( targetWkb, &numRings, 4 );
113 memcpy( targetWkb, &numPoints, 4 );
116 memcpy( targetWkb, &x1,
sizeof(
double ) ); targetWkb +=
sizeof( double );
117 memcpy( targetWkb, &y1,
sizeof(
double ) ); targetWkb +=
sizeof( double );
118 memcpy( targetWkb, &x2,
sizeof(
double ) ); targetWkb +=
sizeof( double );
119 memcpy( targetWkb, &y2,
sizeof(
double ) ); targetWkb +=
sizeof( double );
124 memcpy( targetWkb, &numPoints, 4 );
127 memcpy( targetWkb, &x1,
sizeof(
double ) ); targetWkb +=
sizeof( double );
128 memcpy( targetWkb, &y1,
sizeof(
double ) ); targetWkb +=
sizeof( double );
129 memcpy( targetWkb, &x2,
sizeof(
double ) ); targetWkb +=
sizeof( double );
130 memcpy( targetWkb, &y1,
sizeof(
double ) ); targetWkb +=
sizeof( double );
131 memcpy( targetWkb, &x2,
sizeof(
double ) ); targetWkb +=
sizeof( double );
132 memcpy( targetWkb, &y2,
sizeof(
double ) ); targetWkb +=
sizeof( double );
133 memcpy( targetWkb, &x1,
sizeof(
double ) ); targetWkb +=
sizeof( double );
134 memcpy( targetWkb, &y2,
sizeof(
double ) ); targetWkb +=
sizeof( double );
135 memcpy( targetWkb, &x1,
sizeof(
double ) ); targetWkb +=
sizeof( double );
136 memcpy( targetWkb, &y1,
sizeof(
double ) ); targetWkb +=
sizeof( double );
138 targetWkbSize += targetWkb - wkb2;
146 bool canbeGeneralizable =
true;
153 canbeGeneralizable =
generalizeWkbGeometry( wkbType, sourceWkb, sourceWkbSize, targetWkb, targetWkbSize, envelope, writeHeader );
154 if ( canbeGeneralizable )
return true;
161 memcpy( targetWkb, sourceWkb, 1 );
166 memcpy( &geometryType, sourceWkb, 4 );
168 memcpy( targetWkb, &flatType, 4 );
175 unsigned char* wkb1 = sourceWkb;
176 unsigned char* wkb2 = targetWkb;
182 double x, y, lastX = 0, lastY = 0;
184 int sizeOfDoubleX =
sizeof( double );
185 int sizeOfDoubleY =
QGis::wkbDimensions( wkbType ) == 3 ? 2 *
sizeof( double ) :
sizeof(
double );
188 memcpy( &numPoints, sourceWkb, 4 );
190 if ( numPoints <= ( isaLinearRing ? 5 : 2 ) ) canbeGeneralizable =
false;
192 int numTargetPoints = 0;
193 memcpy( targetWkb, &numTargetPoints, 4 );
197 double* ptr = (
double* )targetWkb;
198 map2pixelTol *= map2pixelTol;
201 for (
int i = 0, numPoints_i = ( isaLinearRing ? numPoints - 1 : numPoints ); i < numPoints_i; ++i )
203 memcpy( &x, sourceWkb,
sizeof(
double ) ); sourceWkb += sizeOfDoubleX;
204 memcpy( &y, sourceWkb,
sizeof(
double ) ); sourceWkb += sizeOfDoubleY;
208 memcpy( ptr, &x,
sizeof(
double ) ); lastX = x; ptr++;
209 memcpy( ptr, &y,
sizeof(
double ) ); lastY = y; ptr++;
213 targetWkb = wkb2 + 4;
218 memcpy( &x, targetWkb + 0,
sizeof(
double ) );
219 memcpy( &y, targetWkb + 8,
sizeof(
double ) );
220 memcpy( ptr, &x,
sizeof(
double ) ); ptr++;
221 memcpy( ptr, &y,
sizeof(
double ) ); ptr++;
224 targetWkbSize += numTargetPoints * 16;
227 memcpy( targetWkb, &numTargetPoints, 4 );
228 result = numPoints != numTargetPoints;
234 memcpy( &numRings, sourceWkb, 4 );
237 memcpy( targetWkb, &numRings, 4 );
241 for (
int i = 0; i < numRings; ++i )
244 memcpy( &numPoints_i, sourceWkb, 4 );
247 size_t sourceWkbSize_i = 4 + numPoints_i * ( hasZValue ? 3 : 2 ) *
sizeof(
double );
248 size_t targetWkbSize_i = 0;
250 result |=
simplifyWkbGeometry( simplifyFlags, wkbType, sourceWkb, sourceWkbSize_i, targetWkb, targetWkbSize_i, envelope_i, map2pixelTol,
false,
true );
251 sourceWkb += sourceWkbSize_i;
252 targetWkb += targetWkbSize_i;
254 targetWkbSize += targetWkbSize_i;
261 memcpy( &numGeoms, sourceWkb, 4 );
265 memcpy( targetWkb, &numGeoms, 4 );
269 for (
int i = 0; i < numGeoms; ++i )
271 size_t sourceWkbSize_i = 0;
272 size_t targetWkbSize_i = 0;
278 memcpy( &numPoints_i, wkb1 + 5, 4 );
279 int wkbSize_i = 4 + numPoints_i * ( hasZValue ? 3 : 2 ) *
sizeof(
double );
281 sourceWkbSize_i += 5 + wkbSize_i;
282 wkb1 += 5 + wkbSize_i;
287 memcpy( &numPrings_i, wkb1 + 5, 4 );
291 for (
int j = 0; j < numPrings_i; ++j )
294 memcpy( &numPoints_i, wkb1, 4 );
295 int wkbSize_i = 4 + numPoints_i * ( hasZValue ? 3 : 2 ) *
sizeof(
double );
297 sourceWkbSize_i += wkbSize_i;
302 sourceWkb += sourceWkbSize_i;
303 targetWkb += targetWkbSize_i;
305 targetWkbSize += targetWkbSize_i;
329 size_t wkbSize = geometry->
wkbSize();
330 unsigned char* wkb = (
unsigned char* )malloc( wkbSize );
331 memcpy( wkb, geometry->
asWkb(), wkbSize );
341 size_t targetWkbSize = 0;
350 unsigned char* wkb = (
unsigned char* )geometry->
asWkb( );
351 size_t wkbSize = geometry->
wkbSize( );
354 if (
simplifyWkbGeometry( simplifyFlags, wkbType, wkb, wkbSize, wkb, targetWkbSize, envelope, tolerance ) )
356 unsigned char* targetWkb = (
unsigned char* )malloc( targetWkbSize );
357 memcpy( targetWkb, wkb, targetWkbSize );
358 geometry->
fromWkb( targetWkb, targetWkbSize );