Skip to content

Commit 324826e

Browse files
rldhontmhugent
authored andcommittedAug 22, 2014
Bug #9797 Add a precision setting for GetFeatureInfo geometry attributes
Add precision to QgsGeometry method exportToWKT and use it in GetFeatureInfo
1 parent 75f5968 commit 324826e

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed
 

‎python/core/qgsgeometry.sip

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,11 @@ class QgsGeometry
364364
/** Returns a Geometry representing the points making up this Geometry that do not make up other. */
365365
QgsGeometry* symDifference( QgsGeometry* geometry ) /Factory/;
366366

367-
/** Exports the geometry to mWkt
367+
/** Exports the geometry to WKT
368+
* @note precision parameter added in 2.4
368369
* @return true in case of success and false else
369370
*/
370-
QString exportToWkt() const;
371+
QString exportToWkt( const int &precision = 17 ) const;
371372

372373
/** Exports the geometry to GeoJSON
373374
* @return a QString representing the geometry as GeoJSON

‎src/core/qgsgeometry.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3536,7 +3536,7 @@ bool QgsGeometry::crosses( const QgsGeometry* geometry ) const
35363536
return geosRelOp( GEOSCrosses, this, geometry );
35373537
}
35383538

3539-
QString QgsGeometry::exportToWkt() const
3539+
QString QgsGeometry::exportToWkt( const int &precision ) const
35403540
{
35413541
QgsDebugMsg( "entered." );
35423542

@@ -3566,7 +3566,7 @@ QString QgsGeometry::exportToWkt() const
35663566
{
35673567
double x, y;
35683568
wkbPtr >> x >> y;
3569-
wkt += "POINT(" + qgsDoubleToString( x ) + " " + qgsDoubleToString( y ) + ")";
3569+
wkt += "POINT(" + qgsDoubleToString( x, precision ) + " " + qgsDoubleToString( y, precision ) + ")";
35703570
return wkt;
35713571
}
35723572

@@ -3589,7 +3589,7 @@ QString QgsGeometry::exportToWkt() const
35893589
if ( idx != 0 )
35903590
wkt += ", ";
35913591

3592-
wkt += qgsDoubleToString( x ) + " " + qgsDoubleToString( y );
3592+
wkt += qgsDoubleToString( x, precision ) + " " + qgsDoubleToString( y, precision );
35933593
}
35943594
wkt += ")";
35953595
return wkt;
@@ -3626,7 +3626,7 @@ QString QgsGeometry::exportToWkt() const
36263626
if ( hasZValue )
36273627
wkbPtr += sizeof( double );
36283628

3629-
wkt += qgsDoubleToString( x ) + " " + qgsDoubleToString( y );
3629+
wkt += qgsDoubleToString( x, precision ) + " " + qgsDoubleToString( y, precision );
36303630
}
36313631
wkt += ")";
36323632
}
@@ -3653,7 +3653,7 @@ QString QgsGeometry::exportToWkt() const
36533653
if ( hasZValue )
36543654
wkbPtr += sizeof( double );
36553655

3656-
wkt += qgsDoubleToString( x ) + " " + qgsDoubleToString( y );
3656+
wkt += qgsDoubleToString( x, precision ) + " " + qgsDoubleToString( y, precision );
36573657
}
36583658
wkt += ")";
36593659
return wkt;
@@ -3686,7 +3686,7 @@ QString QgsGeometry::exportToWkt() const
36863686
if ( hasZValue )
36873687
wkbPtr += sizeof( double );
36883688

3689-
wkt += qgsDoubleToString( x ) + " " + qgsDoubleToString( y );
3689+
wkt += qgsDoubleToString( x, precision ) + " " + qgsDoubleToString( y, precision );
36903690
}
36913691
wkt += ")";
36923692
}
@@ -3729,7 +3729,7 @@ QString QgsGeometry::exportToWkt() const
37293729
if ( hasZValue )
37303730
wkbPtr += sizeof( double );
37313731

3732-
wkt += qgsDoubleToString( x ) + " " + qgsDoubleToString( y );
3732+
wkt += qgsDoubleToString( x, precision ) + " " + qgsDoubleToString( y, precision );
37333733
}
37343734
wkt += ")";
37353735
}

‎src/core/qgsgeometry.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,11 @@ class CORE_EXPORT QgsGeometry
406406
/** Returns a Geometry representing the points making up this Geometry that do not make up other. */
407407
QgsGeometry* symDifference( QgsGeometry* geometry );
408408

409-
/** Exports the geometry to mWkt
409+
/** Exports the geometry to WKT
410+
* @note precision parameter added in 2.4
410411
* @return true in case of success and false else
411412
*/
412-
QString exportToWkt() const;
413+
QString exportToWkt( const int &precision = 17 ) const;
413414

414415
/** Exports the geometry to GeoJSON
415416
* @return a QString representing the geometry as GeoJSON

‎src/mapserver/qgswmsserver.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,11 +1286,11 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
12861286
int gmlVersion = infoFormat.startsWith( "application/vnd.ogc.gml/3" ) ? 3 : 2;
12871287
if ( gmlVersion < 3 )
12881288
{
1289-
boxElem = QgsOgcUtils::rectangleToGMLBox( featuresRect, result );
1289+
boxElem = QgsOgcUtils::rectangleToGMLBox( featuresRect, result, 8 );
12901290
}
12911291
else
12921292
{
1293-
boxElem = QgsOgcUtils::rectangleToGMLEnvelope( featuresRect, result );
1293+
boxElem = QgsOgcUtils::rectangleToGMLEnvelope( featuresRect, result, 8 );
12941294
}
12951295

12961296
QgsCoordinateReferenceSystem crs = mMapRenderer->destinationCrs();
@@ -1305,10 +1305,10 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
13051305
{
13061306
QDomElement bBoxElem = result.createElement( "BoundingBox" );
13071307
bBoxElem.setAttribute( "CRS", mMapRenderer->destinationCrs().authid() );
1308-
bBoxElem.setAttribute( "minx", QString::number( featuresRect->xMinimum() ) );
1309-
bBoxElem.setAttribute( "maxx", QString::number( featuresRect->xMaximum() ) );
1310-
bBoxElem.setAttribute( "miny", QString::number( featuresRect->yMinimum() ) );
1311-
bBoxElem.setAttribute( "maxy", QString::number( featuresRect->yMaximum() ) );
1308+
bBoxElem.setAttribute( "minx", qgsDoubleToString( featuresRect->xMinimum(), 8 ) );
1309+
bBoxElem.setAttribute( "maxx", qgsDoubleToString( featuresRect->xMaximum(), 8 ) );
1310+
bBoxElem.setAttribute( "miny", qgsDoubleToString( featuresRect->yMinimum(), 8 ) );
1311+
bBoxElem.setAttribute( "maxy", qgsDoubleToString( featuresRect->yMaximum(), 8 ) );
13121312
getFeatureInfoElement.insertBefore( bBoxElem, QDomNode() ); //insert as first child
13131313
}
13141314
}
@@ -1830,10 +1830,10 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
18301830
{
18311831
QDomElement bBoxElem = infoDocument.createElement( "BoundingBox" );
18321832
bBoxElem.setAttribute( version == "1.1.1" ? "SRS" : "CRS", outputCrs.authid() );
1833-
bBoxElem.setAttribute( "minx", QString::number( box.xMinimum() ) );
1834-
bBoxElem.setAttribute( "maxx", QString::number( box.xMaximum() ) );
1835-
bBoxElem.setAttribute( "miny", QString::number( box.yMinimum() ) );
1836-
bBoxElem.setAttribute( "maxy", QString::number( box.yMaximum() ) );
1833+
bBoxElem.setAttribute( "minx", qgsDoubleToString( box.xMinimum(), 8 ) );
1834+
bBoxElem.setAttribute( "maxx", qgsDoubleToString( box.xMaximum(), 8 ) );
1835+
bBoxElem.setAttribute( "miny", qgsDoubleToString( box.yMinimum(), 8 ) );
1836+
bBoxElem.setAttribute( "maxy", qgsDoubleToString( box.yMaximum(), 8 ) );
18371837
featureElement.appendChild( bBoxElem );
18381838
}
18391839

@@ -1851,7 +1851,7 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
18511851
}
18521852
QDomElement geometryElement = infoDocument.createElement( "Attribute" );
18531853
geometryElement.setAttribute( "name", "geometry" );
1854-
geometryElement.setAttribute( "value", geom->exportToWkt() );
1854+
geometryElement.setAttribute( "value", geom->exportToWkt( 8 ) );
18551855
geometryElement.setAttribute( "type", "derived" );
18561856
featureElement.appendChild( geometryElement );
18571857
}
@@ -2836,11 +2836,11 @@ QDomElement QgsWMSServer::createFeatureGML(
28362836
QDomElement boxElem;
28372837
if ( version < 3 )
28382838
{
2839-
boxElem = QgsOgcUtils::rectangleToGMLBox( &box, doc );
2839+
boxElem = QgsOgcUtils::rectangleToGMLBox( &box, doc, 8 );
28402840
}
28412841
else
28422842
{
2843-
boxElem = QgsOgcUtils::rectangleToGMLEnvelope( &box, doc );
2843+
boxElem = QgsOgcUtils::rectangleToGMLEnvelope( &box, doc, 8 );
28442844
}
28452845

28462846
if ( crs.isValid() )
@@ -2864,11 +2864,11 @@ QDomElement QgsWMSServer::createFeatureGML(
28642864
QDomElement gmlElem;
28652865
if ( version < 3 )
28662866
{
2867-
gmlElem = QgsOgcUtils::geometryToGML( geom, doc );
2867+
gmlElem = QgsOgcUtils::geometryToGML( geom, doc, 8 );
28682868
}
28692869
else
28702870
{
2871-
gmlElem = QgsOgcUtils::geometryToGML( geom, doc, "GML3" );
2871+
gmlElem = QgsOgcUtils::geometryToGML( geom, doc, "GML3", 8 );
28722872
}
28732873

28742874
if ( !gmlElem.isNull() )

0 commit comments

Comments
 (0)
Please sign in to comment.