Package: qgis / 2.4.0-1

0001-Bug-10974-QGIS-WFS-Server-provides-too-much-precisio.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
From 27ebd9657db57a1925f7f0172a697363a63844b3 Mon Sep 17 00:00:00 2001
From: rldhont <rldhont@gmail.com>
Date: Tue, 29 Jul 2014 17:11:42 +0200
Subject: Bug #10974 QGIS WFS Server provides too much precision
Origin: https://github.com/qgis/QGIS/commit/27ebd9657db57a1925f7f0172a697363a63844b3
Bug: http://hub.qgis.org/issues/10974

In the GetFeature request QGIS WFS Server uses the static method: QgsDoubleToString. This method returns double with a precision fixed to 17.

We do not need that much precision for coordinates. Firstly because we are not able to measure a position on earth with a lower micron precision. Secondly because it unnecessarily overload response.

I propose to add the ability to specify the precision in the QgsDoubleToString method.

--- a/python/core/qgsgeometry.sip
+++ b/python/core/qgsgeometry.sip
@@ -369,12 +369,13 @@ class QgsGeometry
      */
     QString exportToWkt() const;
 
-    /** Exports the geometry to mGeoJSON
-     *  @return true in case of success and false else
+    /** Exports the geometry to GeoJSON
+     *  @return a QString representing the geometry as GeoJSON
      *  @note added in 1.8
      *  @note python binding added in 1.9
+     *  @note precision parameter added in 2.4
      */
-    QString exportToGeoJSON() const;
+    QString exportToGeoJSON( const int &precision = 17 ) const;
 
     /** try to convert the geometry to the requested type
      * @param destType the geometry type to be converted to
--- a/python/core/qgsogcutils.sip
+++ b/python/core/qgsogcutils.sip
@@ -28,22 +28,22 @@ class QgsOgcUtils
     /** Exports the geometry to GML2 or GML3
         @return QDomElement
      */
-    static QDomElement geometryToGML( QgsGeometry* geometry, QDomDocument& doc, QString format );
+    static QDomElement geometryToGML( QgsGeometry* geometry, QDomDocument& doc, QString format, const int &precision = 17 );
 
     /** Exports the geometry to GML2
         @return QDomElement
      */
-    static QDomElement geometryToGML( QgsGeometry* geometry, QDomDocument& doc );
+    static QDomElement geometryToGML( QgsGeometry* geometry, QDomDocument& doc, const int &precision = 17 );
 
     /** Exports the rectangle to GML2 Box
         @return QDomElement
      */
-    static QDomElement rectangleToGMLBox( QgsRectangle* box, QDomDocument& doc );
+    static QDomElement rectangleToGMLBox( QgsRectangle* box, QDomDocument& doc, const int &precision = 17 );
 
     /** Exports the rectangle to GML2 Envelope
         @return QDomElement
      */
-    static QDomElement rectangleToGMLEnvelope( QgsRectangle* env, QDomDocument& doc );
+    static QDomElement rectangleToGMLEnvelope( QgsRectangle* env, QDomDocument& doc, const int &precision = 17 );
 
 
     /** Parse XML with OGC fill into QColor */
--- a/src/core/qgis.h
+++ b/src/core/qgis.h
@@ -313,9 +313,9 @@ inline void ( *cast_to_fptr( void *p ) )
 //
 // return a string representation of a double
 //
-inline QString qgsDoubleToString( const double &a )
+inline QString qgsDoubleToString( const double &a, const int &precision = 17 )
 {
-  return QString::number( a, 'f', 17 ).remove( QRegExp( "\\.?0+$" ) );
+  return QString::number( a, 'f', precision ).remove( QRegExp( "\\.?0+$" ) );
 }
 
 //
--- a/src/core/qgsgeometry.cpp
+++ b/src/core/qgsgeometry.cpp
@@ -3745,7 +3745,7 @@ QString QgsGeometry::exportToWkt() const
   }
 }
 
-QString QgsGeometry::exportToGeoJSON() const
+QString QgsGeometry::exportToGeoJSON( const int &precision ) const
 {
   QgsDebugMsg( "entered." );
 
@@ -3776,8 +3776,8 @@ QString QgsGeometry::exportToGeoJSON() c
       wkbPtr >> x >> y;
 
       wkt += "{ \"type\": \"Point\", \"coordinates\": ["
-             + qgsDoubleToString( x ) + ", "
-             + qgsDoubleToString( y )
+             + qgsDoubleToString( x, precision ) + ", "
+             + qgsDoubleToString( y, precision )
              + "] }";
       return wkt;
     }
@@ -3801,7 +3801,7 @@ QString QgsGeometry::exportToGeoJSON() c
         if ( hasZValue )
           wkbPtr += sizeof( double );
 
-        wkt += "[" + qgsDoubleToString( x ) + ", " + qgsDoubleToString( y ) + "]";
+        wkt += "[" + qgsDoubleToString( x, precision ) + ", " + qgsDoubleToString( y, precision ) + "]";
       }
       wkt += " ] }";
       return wkt;
@@ -3839,7 +3839,7 @@ QString QgsGeometry::exportToGeoJSON() c
           if ( hasZValue )
             wkbPtr += sizeof( double );
 
-          wkt += "[" + qgsDoubleToString( x ) + ", " + qgsDoubleToString( y ) + "]";
+          wkt += "[" + qgsDoubleToString( x, precision ) + ", " + qgsDoubleToString( y, precision ) + "]";
         }
         wkt += " ]";
       }
@@ -3865,7 +3865,7 @@ QString QgsGeometry::exportToGeoJSON() c
         if ( hasZValue )
           wkbPtr += sizeof( double );
 
-        wkt += "[" + qgsDoubleToString( x ) + ", " + qgsDoubleToString( y ) + "]";
+        wkt += "[" + qgsDoubleToString( x, precision ) + ", " + qgsDoubleToString( y, precision ) + "]";
       }
       wkt += " ] }";
       return wkt;
@@ -3899,7 +3899,7 @@ QString QgsGeometry::exportToGeoJSON() c
           if ( hasZValue )
             wkbPtr += sizeof( double );
 
-          wkt += "[" + qgsDoubleToString( x ) + ", " + qgsDoubleToString( y ) + "]";
+          wkt += "[" + qgsDoubleToString( x, precision ) + ", " + qgsDoubleToString( y, precision ) + "]";
         }
         wkt += " ]";
       }
@@ -3946,7 +3946,7 @@ QString QgsGeometry::exportToGeoJSON() c
             if ( hasZValue )
               wkbPtr += sizeof( double );
 
-            wkt += "[" + qgsDoubleToString( x ) + ", " + qgsDoubleToString( y ) + "]";
+            wkt += "[" + qgsDoubleToString( x, precision ) + ", " + qgsDoubleToString( y, precision ) + "]";
           }
           wkt += " ]";
         }
--- a/src/core/qgsgeometry.h
+++ b/src/core/qgsgeometry.h
@@ -411,12 +411,13 @@ class CORE_EXPORT QgsGeometry
      */
     QString exportToWkt() const;
 
-    /** Exports the geometry to mGeoJSON
-     *  @return true in case of success and false else
+    /** Exports the geometry to GeoJSON
+     *  @return a QString representing the geometry as GeoJSON
      *  @note added in 1.8
      *  @note python binding added in 1.9
+     *  @note precision parameter added in 2.4
      */
-    QString exportToGeoJSON() const;
+    QString exportToGeoJSON( const int &precision = 17 ) const;
 
     /** try to convert the geometry to the requested type
      * @param destType the geometry type to be converted to
--- a/src/core/qgsogcutils.cpp
+++ b/src/core/qgsogcutils.cpp
@@ -993,7 +993,7 @@ QgsRectangle QgsOgcUtils::rectangleFromG
   return rect;
 }
 
-QDomElement QgsOgcUtils::rectangleToGMLBox( QgsRectangle* box, QDomDocument& doc )
+QDomElement QgsOgcUtils::rectangleToGMLBox( QgsRectangle* box, QDomDocument& doc, const int &precision )
 {
   if ( !box )
   {
@@ -1006,13 +1006,13 @@ QDomElement QgsOgcUtils::rectangleToGMLB
   coordElem.setAttribute( "ts", " " );
 
   QString coordString;
-  coordString += qgsDoubleToString( box->xMinimum() );
+  coordString += qgsDoubleToString( box->xMinimum(), precision );
   coordString += ",";
-  coordString += qgsDoubleToString( box->yMinimum() );
+  coordString += qgsDoubleToString( box->yMinimum(), precision );
   coordString += " ";
-  coordString += qgsDoubleToString( box->xMaximum() );
+  coordString += qgsDoubleToString( box->xMaximum(), precision );
   coordString += ",";
-  coordString += qgsDoubleToString( box->yMaximum() );
+  coordString += qgsDoubleToString( box->yMaximum(), precision );
 
   QDomText coordText = doc.createTextNode( coordString );
   coordElem.appendChild( coordText );
@@ -1021,7 +1021,7 @@ QDomElement QgsOgcUtils::rectangleToGMLB
   return boxElem;
 }
 
-QDomElement QgsOgcUtils::rectangleToGMLEnvelope( QgsRectangle* env, QDomDocument& doc )
+QDomElement QgsOgcUtils::rectangleToGMLEnvelope( QgsRectangle* env, QDomDocument& doc, const int &precision )
 {
   if ( !env )
   {
@@ -1032,17 +1032,17 @@ QDomElement QgsOgcUtils::rectangleToGMLE
   QString posList;
 
   QDomElement lowerCornerElem = doc.createElement( "gml:lowerCorner" );
-  posList = qgsDoubleToString( env->xMinimum() );
+  posList = qgsDoubleToString( env->xMinimum(), precision );
   posList += " ";
-  posList += qgsDoubleToString( env->yMinimum() );
+  posList += qgsDoubleToString( env->yMinimum(), precision );
   QDomText lowerCornerText = doc.createTextNode( posList );
   lowerCornerElem.appendChild( lowerCornerText );
   envElem.appendChild( lowerCornerElem );
 
   QDomElement upperCornerElem = doc.createElement( "gml:upperCorner" );
-  posList = qgsDoubleToString( env->xMaximum() );
+  posList = qgsDoubleToString( env->xMaximum(), precision );
   posList += " ";
-  posList += qgsDoubleToString( env->yMaximum() );
+  posList += qgsDoubleToString( env->yMaximum(), precision );
   QDomText upperCornerText = doc.createTextNode( posList );
   upperCornerElem.appendChild( upperCornerText );
   envElem.appendChild( upperCornerElem );
@@ -1050,7 +1050,7 @@ QDomElement QgsOgcUtils::rectangleToGMLE
   return envElem;
 }
 
-QDomElement QgsOgcUtils::geometryToGML( QgsGeometry* geometry, QDomDocument& doc, QString format )
+QDomElement QgsOgcUtils::geometryToGML( QgsGeometry* geometry, QDomDocument& doc, QString format, const int &precision )
 {
   if ( !geometry || !geometry->asWkb() )
     return QDomElement();
@@ -1100,7 +1100,7 @@ QDomElement QgsOgcUtils::geometryToGML(
 
       double x, y;
       wkbPtr >> x >> y;
-      QDomText coordText = doc.createTextNode( qgsDoubleToString( x ) + cs + qgsDoubleToString( y ) );
+      QDomText coordText = doc.createTextNode( qgsDoubleToString( x, precision ) + cs + qgsDoubleToString( y, precision ) );
 
       coordElem.appendChild( coordText );
       pointElem.appendChild( coordElem );
@@ -1124,7 +1124,7 @@ QDomElement QgsOgcUtils::geometryToGML(
 
         double x, y;
         wkbPtr >> x >> y;
-        QDomText coordText = doc.createTextNode( qgsDoubleToString( x ) + cs + qgsDoubleToString( y ) );
+        QDomText coordText = doc.createTextNode( qgsDoubleToString( x, precision ) + cs + qgsDoubleToString( y, precision ) );
 
         coordElem.appendChild( coordText );
         pointElem.appendChild( coordElem );
@@ -1159,7 +1159,7 @@ QDomElement QgsOgcUtils::geometryToGML(
 
         double x, y;
         wkbPtr >> x >> y;
-        coordString += qgsDoubleToString( x ) + cs + qgsDoubleToString( y );
+        coordString += qgsDoubleToString( x, precision ) + cs + qgsDoubleToString( y, precision );
 
         if ( hasZValue )
         {
@@ -1201,7 +1201,7 @@ QDomElement QgsOgcUtils::geometryToGML(
           double x, y;
           wkbPtr >> x >> y;
 
-          coordString += qgsDoubleToString( x ) + cs + qgsDoubleToString( y );
+          coordString += qgsDoubleToString( x, precision ) + cs + qgsDoubleToString( y, precision );
 
           if ( hasZValue )
           {
@@ -1257,7 +1257,7 @@ QDomElement QgsOgcUtils::geometryToGML(
           double x, y;
           wkbPtr >> x >> y;
 
-          coordString += qgsDoubleToString( x ) + cs + qgsDoubleToString( y );
+          coordString += qgsDoubleToString( x, precision ) + cs + qgsDoubleToString( y, precision );
           if ( hasZValue )
           {
             wkbPtr += sizeof( double );
@@ -1316,7 +1316,7 @@ QDomElement QgsOgcUtils::geometryToGML(
             double x, y;
             wkbPtr >> x >> y;
 
-            coordString += qgsDoubleToString( x ) + cs + qgsDoubleToString( y );
+            coordString += qgsDoubleToString( x, precision ) + cs + qgsDoubleToString( y, precision );
 
             if ( hasZValue )
             {
@@ -1339,9 +1339,9 @@ QDomElement QgsOgcUtils::geometryToGML(
   }
 }
 
-QDomElement QgsOgcUtils::geometryToGML( QgsGeometry *geometry, QDomDocument &doc )
+QDomElement QgsOgcUtils::geometryToGML( QgsGeometry *geometry, QDomDocument &doc, const int &precision )
 {
-  return geometryToGML( geometry, doc, "GML2" );
+  return geometryToGML( geometry, doc, "GML2", precision );
 }
 
 QDomElement QgsOgcUtils::createGMLCoordinates( const QgsPolyline &points, QDomDocument &doc )
--- a/src/core/qgsogcutils.h
+++ b/src/core/qgsogcutils.h
@@ -51,22 +51,22 @@ class CORE_EXPORT QgsOgcUtils
     /** Exports the geometry to GML2 or GML3
         @return QDomElement
      */
-    static QDomElement geometryToGML( QgsGeometry* geometry, QDomDocument& doc, QString format );
+    static QDomElement geometryToGML( QgsGeometry* geometry, QDomDocument& doc, QString format, const int &precision = 17 );
 
     /** Exports the geometry to GML2
         @return QDomElement
      */
-    static QDomElement geometryToGML( QgsGeometry* geometry, QDomDocument& doc );
+    static QDomElement geometryToGML( QgsGeometry* geometry, QDomDocument& doc, const int &precision = 17 );
 
     /** Exports the rectangle to GML2 Box
         @return QDomElement
      */
-    static QDomElement rectangleToGMLBox( QgsRectangle* box, QDomDocument& doc );
+    static QDomElement rectangleToGMLBox( QgsRectangle* box, QDomDocument& doc, const int &precision = 17 );
 
     /** Exports the rectangle to GML2 Envelope
         @return QDomElement
      */
-    static QDomElement rectangleToGMLEnvelope( QgsRectangle* env, QDomDocument& doc );
+    static QDomElement rectangleToGMLEnvelope( QgsRectangle* env, QDomDocument& doc, const int &precision = 17 );
 
 
     /** Parse XML with OGC fill into QColor */
--- a/src/mapserver/qgswfsserver.cpp
+++ b/src/mapserver/qgswfsserver.cpp
@@ -1074,7 +1074,7 @@ void QgsWFSServer::startGetFeature( QgsR
   if ( format == "GeoJSON" )
   {
     fcString = "{\"type\": \"FeatureCollection\",\n";
-    fcString += " \"bbox\": [ " + QString::number( rect->xMinimum(), 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) ) + ", " + QString::number( rect->yMinimum(), 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) ) + ", " + QString::number( rect->xMaximum(), 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) ) + ", " + QString::number( rect->yMaximum(), 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) ) + "],\n";
+    fcString += " \"bbox\": [ " + qgsDoubleToString( rect->xMinimum(), 8 ) + ", " + qgsDoubleToString( rect->yMinimum(), 8 ) + ", " + qgsDoubleToString( rect->xMaximum(), 8 ) + ", " + qgsDoubleToString( rect->yMaximum(), 8 ) + "],\n";
     fcString += " \"features\": [\n";
     result = fcString.toUtf8();
     request.startGetFeatureResponse( &result, format );
@@ -1167,7 +1167,7 @@ void QgsWFSServer::startGetFeature( QgsR
     QDomElement bbElem = doc.createElement( "gml:boundedBy" );
     if ( format == "GML3" )
     {
-      QDomElement envElem = QgsOgcUtils::rectangleToGMLEnvelope( rect, doc );
+      QDomElement envElem = QgsOgcUtils::rectangleToGMLEnvelope( rect, doc, 8 );
       if ( !envElem.isNull() )
       {
         if ( crs.isValid() )
@@ -1180,7 +1180,7 @@ void QgsWFSServer::startGetFeature( QgsR
     }
     else
     {
-      QDomElement boxElem = QgsOgcUtils::rectangleToGMLBox( rect, doc );
+      QDomElement boxElem = QgsOgcUtils::rectangleToGMLBox( rect, doc, 8 );
       if ( !boxElem.isNull() )
       {
         if ( crs.isValid() )
@@ -1691,10 +1691,10 @@ QString QgsWFSServer::createFeatureGeoJS
   {
     QgsRectangle box = geom->boundingBox();
 
-    fStr += " \"bbox\": [ " + QString::number( box.xMinimum(), 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) ) + ", " + QString::number( box.yMinimum(), 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) ) + ", " + QString::number( box.xMaximum(), 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) ) + ", " + QString::number( box.yMaximum(), 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) ) + "],\n";
+    fStr += " \"bbox\": [ " + qgsDoubleToString( box.xMinimum(), 8 ) + ", " + qgsDoubleToString( box.yMinimum(), 8 ) + ", " + qgsDoubleToString( box.xMaximum(), 8 ) + ", " + qgsDoubleToString( box.yMaximum(), 8 ) + "],\n";
 
     fStr += "  \"geometry\": ";
-    fStr += geom->exportToGeoJSON();
+    fStr += geom->exportToGeoJSON( 8 );
     fStr += ",\n";
   }
 
@@ -1757,12 +1757,12 @@ QDomElement QgsWFSServer::createFeatureG
     QgsGeometry* geom = feat->geometry();
 
     QDomElement geomElem = doc.createElement( "qgs:geometry" );
-    QDomElement gmlElem = QgsOgcUtils::geometryToGML( geom, doc );
+    QDomElement gmlElem = QgsOgcUtils::geometryToGML( geom, doc, 8 );
     if ( !gmlElem.isNull() )
     {
       QgsRectangle box = geom->boundingBox();
       QDomElement bbElem = doc.createElement( "gml:boundedBy" );
-      QDomElement boxElem = QgsOgcUtils::rectangleToGMLBox( &box, doc );
+      QDomElement boxElem = QgsOgcUtils::rectangleToGMLBox( &box, doc, 8 );
 
       if ( crs.isValid() )
       {
@@ -1816,12 +1816,12 @@ QDomElement QgsWFSServer::createFeatureG
     QgsGeometry* geom = feat->geometry();
 
     QDomElement geomElem = doc.createElement( "qgs:geometry" );
-    QDomElement gmlElem = QgsOgcUtils::geometryToGML( geom, doc, "GML3" );
+    QDomElement gmlElem = QgsOgcUtils::geometryToGML( geom, doc, "GML3", 8 );
     if ( !gmlElem.isNull() )
     {
       QgsRectangle box = geom->boundingBox();
       QDomElement bbElem = doc.createElement( "gml:boundedBy" );
-      QDomElement boxElem = QgsOgcUtils::rectangleToGMLEnvelope( &box, doc );
+      QDomElement boxElem = QgsOgcUtils::rectangleToGMLEnvelope( &box, doc, 8 );
 
       if ( crs.isValid() )
       {