@@ -70,17 +70,7 @@ bool QgsMapToPixelSimplifier::equalSnapToGrid( double x1, double y1, double x2,
70
70
// https://github.com/postgis/postgis/blob/svn-trunk/liblwgeom/effectivearea.h
71
71
// https://github.com/postgis/postgis/blob/svn-trunk/liblwgeom/effectivearea.c
72
72
73
- #define LWDEBUG //
74
- #define LWDEBUGF //
75
- #define FP_MAX qMax
76
- #define FLAGS_GET_Z ( flags ) ( ( flags ) & 0x01 )
77
- #define LW_MSG_MAXLEN 256
78
- #define lwalloc qgsMalloc
79
- #define lwfree qgsFree
80
- #define lwerror qWarning
81
-
82
73
#include " simplify/effectivearea.h"
83
- #include " simplify/effectivearea.c"
84
74
85
75
// ////////////////////////////////////////////////////////////////////////////////////////////
86
76
@@ -175,75 +165,80 @@ QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry(
175
165
}
176
166
177
167
// Process each vertex...
178
- if ( simplifyAlgorithm == SnapToGrid )
168
+ switch ( simplifyAlgorithm )
179
169
{
180
- double gridOriginX = envelope.xMinimum ();
181
- double gridOriginY = envelope.yMinimum ();
182
-
183
- // Use a factor for the maximum displacement distance for simplification, similar as GeoServer does
184
- float gridInverseSizeXY = map2pixelTol != 0 ? ( float )( 1 .0f / ( 0.8 * map2pixelTol ) ) : 0 .0f ;
185
-
186
- for ( int i = 0 ; i < numPoints; ++i )
170
+ case SnapToGrid:
187
171
{
188
- x = srcCurve. xAt ( i );
189
- y = srcCurve. yAt ( i );
172
+ double gridOriginX = envelope. xMinimum ( );
173
+ double gridOriginY = envelope. yMinimum ( );
190
174
191
- if ( i == 0 ||
192
- !isGeneralizable ||
193
- ! equalSnapToGrid ( x, y, lastX, lastY, gridOriginX, gridOriginY, gridInverseSizeXY ) ||
194
- ( !isaLinearRing && ( i == 1 || i >= numPoints - 2 ) ) )
175
+ // Use a factor for the maximum displacement distance for simplification, similar as GeoServer does
176
+ float gridInverseSizeXY = map2pixelTol != 0 ? ( float )( 1 . 0f / ( 0.8 * map2pixelTol ) ) : 0 . 0f ;
177
+
178
+ for ( int i = 0 ; i < numPoints; ++i )
195
179
{
196
- output->insertVertex ( QgsVertexId ( 0 , 0 , output->numPoints () ), QgsPointV2 ( x, y ) );
197
- lastX = x;
198
- lastY = y;
180
+ x = srcCurve.xAt ( i );
181
+ y = srcCurve.yAt ( i );
182
+
183
+ if ( i == 0 ||
184
+ !isGeneralizable ||
185
+ !equalSnapToGrid ( x, y, lastX, lastY, gridOriginX, gridOriginY, gridInverseSizeXY ) ||
186
+ ( !isaLinearRing && ( i == 1 || i >= numPoints - 2 ) ) )
187
+ {
188
+ output->insertVertex ( QgsVertexId ( 0 , 0 , output->numPoints () ), QgsPointV2 ( x, y ) );
189
+ lastX = x;
190
+ lastY = y;
191
+ }
192
+
193
+ r.combineExtentWith ( x, y );
199
194
}
200
-
201
- r.combineExtentWith ( x, y );
195
+ break ;
202
196
}
203
- }
204
- else if ( simplifyAlgorithm == Visvalingam )
205
- {
206
- map2pixelTol *= map2pixelTol; // -> Use mappixelTol for 'Area' calculations.
207
197
208
- EFFECTIVE_AREAS* ea;
209
- ea = initiate_effectivearea ( srcCurve );
198
+ case Visvalingam:
199
+ {
200
+ map2pixelTol *= map2pixelTol; // -> Use mappixelTol for 'Area' calculations.
210
201
211
- int set_area = 0 ;
212
- ptarray_calc_areas ( ea, isaLinearRing ? 4 : 2 , set_area, map2pixelTol );
202
+ EFFECTIVE_AREAS ea ( srcCurve );
213
203
214
- for ( int i = 0 ; i < numPoints; ++i )
215
- {
216
- if ( ea->res_arealist [ i ] > map2pixelTol )
204
+ int set_area = 0 ;
205
+ ptarray_calc_areas ( &ea, isaLinearRing ? 4 : 2 , set_area, map2pixelTol );
206
+
207
+ for ( int i = 0 ; i < numPoints; ++i )
217
208
{
218
- output->insertVertex ( QgsVertexId ( 0 , 0 , output->numPoints () ), ea->inpts .at ( i ) );
209
+ if ( ea.res_arealist [ i ] > map2pixelTol )
210
+ {
211
+ output->insertVertex ( QgsVertexId ( 0 , 0 , output->numPoints () ), ea.inpts .at ( i ) );
212
+ }
219
213
}
214
+ break ;
220
215
}
221
- destroy_effectivearea ( ea );
222
- }
223
- else
224
- {
225
- map2pixelTol *= map2pixelTol; // -> Use mappixelTol for 'LengthSquare' calculations.
226
216
227
- for ( int i = 0 ; i < numPoints; ++i )
217
+ case Distance:
228
218
{
229
- x = srcCurve.xAt ( i );
230
- y = srcCurve.yAt ( i );
231
-
232
- isLongSegment = false ;
219
+ map2pixelTol *= map2pixelTol; // -> Use mappixelTol for 'LengthSquare' calculations.
233
220
234
- if ( i == 0 ||
235
- !isGeneralizable ||
236
- ( isLongSegment = ( calculateLengthSquared2D ( x, y, lastX, lastY ) > map2pixelTol ) ) ||
237
- ( !isaLinearRing && ( i == 1 || i >= numPoints - 2 ) ) )
221
+ for ( int i = 0 ; i < numPoints; ++i )
238
222
{
239
- output->insertVertex ( QgsVertexId ( 0 , 0 , output->numPoints () ), QgsPointV2 ( x, y ) );
240
- lastX = x;
241
- lastY = y;
223
+ x = srcCurve.xAt ( i );
224
+ y = srcCurve.yAt ( i );
242
225
243
- hasLongSegments |= isLongSegment;
244
- }
226
+ isLongSegment = false ;
227
+
228
+ if ( i == 0 ||
229
+ !isGeneralizable ||
230
+ ( isLongSegment = ( calculateLengthSquared2D ( x, y, lastX, lastY ) > map2pixelTol ) ) ||
231
+ ( !isaLinearRing && ( i == 1 || i >= numPoints - 2 ) ) )
232
+ {
233
+ output->insertVertex ( QgsVertexId ( 0 , 0 , output->numPoints () ), QgsPointV2 ( x, y ) );
234
+ lastX = x;
235
+ lastY = y;
245
236
246
- r.combineExtentWith ( x, y );
237
+ hasLongSegments |= isLongSegment;
238
+ }
239
+
240
+ r.combineExtentWith ( x, y );
241
+ }
247
242
}
248
243
}
249
244
0 commit comments