Skip to content

Commit

Permalink
Bug #9797 Add a precision setting for GetFeatureInfo geometry attributes
Browse files Browse the repository at this point in the history
Add precision to QgsGeometry method exportToWKT and use it in GetFeatureInfo
  • Loading branch information
rldhont authored and mhugent committed Aug 22, 2014
1 parent 75f5968 commit 324826e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
5 changes: 3 additions & 2 deletions python/core/qgsgeometry.sip
Expand Up @@ -364,10 +364,11 @@ class QgsGeometry
/** Returns a Geometry representing the points making up this Geometry that do not make up other. */
QgsGeometry* symDifference( QgsGeometry* geometry ) /Factory/;

/** Exports the geometry to mWkt
/** Exports the geometry to WKT
* @note precision parameter added in 2.4
* @return true in case of success and false else
*/
QString exportToWkt() const;
QString exportToWkt( const int &precision = 17 ) const;

/** Exports the geometry to GeoJSON
* @return a QString representing the geometry as GeoJSON
Expand Down
14 changes: 7 additions & 7 deletions src/core/qgsgeometry.cpp
Expand Up @@ -3536,7 +3536,7 @@ bool QgsGeometry::crosses( const QgsGeometry* geometry ) const
return geosRelOp( GEOSCrosses, this, geometry );
}

QString QgsGeometry::exportToWkt() const
QString QgsGeometry::exportToWkt( const int &precision ) const
{
QgsDebugMsg( "entered." );

Expand Down Expand Up @@ -3566,7 +3566,7 @@ QString QgsGeometry::exportToWkt() const
{
double x, y;
wkbPtr >> x >> y;
wkt += "POINT(" + qgsDoubleToString( x ) + " " + qgsDoubleToString( y ) + ")";
wkt += "POINT(" + qgsDoubleToString( x, precision ) + " " + qgsDoubleToString( y, precision ) + ")";
return wkt;
}

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

wkt += qgsDoubleToString( x ) + " " + qgsDoubleToString( y );
wkt += qgsDoubleToString( x, precision ) + " " + qgsDoubleToString( y, precision );
}
wkt += ")";
return wkt;
Expand Down Expand Up @@ -3626,7 +3626,7 @@ QString QgsGeometry::exportToWkt() const
if ( hasZValue )
wkbPtr += sizeof( double );

wkt += qgsDoubleToString( x ) + " " + qgsDoubleToString( y );
wkt += qgsDoubleToString( x, precision ) + " " + qgsDoubleToString( y, precision );
}
wkt += ")";
}
Expand All @@ -3653,7 +3653,7 @@ QString QgsGeometry::exportToWkt() const
if ( hasZValue )
wkbPtr += sizeof( double );

wkt += qgsDoubleToString( x ) + " " + qgsDoubleToString( y );
wkt += qgsDoubleToString( x, precision ) + " " + qgsDoubleToString( y, precision );
}
wkt += ")";
return wkt;
Expand Down Expand Up @@ -3686,7 +3686,7 @@ QString QgsGeometry::exportToWkt() const
if ( hasZValue )
wkbPtr += sizeof( double );

wkt += qgsDoubleToString( x ) + " " + qgsDoubleToString( y );
wkt += qgsDoubleToString( x, precision ) + " " + qgsDoubleToString( y, precision );
}
wkt += ")";
}
Expand Down Expand Up @@ -3729,7 +3729,7 @@ QString QgsGeometry::exportToWkt() const
if ( hasZValue )
wkbPtr += sizeof( double );

wkt += qgsDoubleToString( x ) + " " + qgsDoubleToString( y );
wkt += qgsDoubleToString( x, precision ) + " " + qgsDoubleToString( y, precision );
}
wkt += ")";
}
Expand Down
5 changes: 3 additions & 2 deletions src/core/qgsgeometry.h
Expand Up @@ -406,10 +406,11 @@ class CORE_EXPORT QgsGeometry
/** Returns a Geometry representing the points making up this Geometry that do not make up other. */
QgsGeometry* symDifference( QgsGeometry* geometry );

/** Exports the geometry to mWkt
/** Exports the geometry to WKT
* @note precision parameter added in 2.4
* @return true in case of success and false else
*/
QString exportToWkt() const;
QString exportToWkt( const int &precision = 17 ) const;

/** Exports the geometry to GeoJSON
* @return a QString representing the geometry as GeoJSON
Expand Down
30 changes: 15 additions & 15 deletions src/mapserver/qgswmsserver.cpp
Expand Up @@ -1286,11 +1286,11 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
int gmlVersion = infoFormat.startsWith( "application/vnd.ogc.gml/3" ) ? 3 : 2;
if ( gmlVersion < 3 )
{
boxElem = QgsOgcUtils::rectangleToGMLBox( featuresRect, result );
boxElem = QgsOgcUtils::rectangleToGMLBox( featuresRect, result, 8 );
}
else
{
boxElem = QgsOgcUtils::rectangleToGMLEnvelope( featuresRect, result );
boxElem = QgsOgcUtils::rectangleToGMLEnvelope( featuresRect, result, 8 );
}

QgsCoordinateReferenceSystem crs = mMapRenderer->destinationCrs();
Expand All @@ -1305,10 +1305,10 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
{
QDomElement bBoxElem = result.createElement( "BoundingBox" );
bBoxElem.setAttribute( "CRS", mMapRenderer->destinationCrs().authid() );
bBoxElem.setAttribute( "minx", QString::number( featuresRect->xMinimum() ) );
bBoxElem.setAttribute( "maxx", QString::number( featuresRect->xMaximum() ) );
bBoxElem.setAttribute( "miny", QString::number( featuresRect->yMinimum() ) );
bBoxElem.setAttribute( "maxy", QString::number( featuresRect->yMaximum() ) );
bBoxElem.setAttribute( "minx", qgsDoubleToString( featuresRect->xMinimum(), 8 ) );
bBoxElem.setAttribute( "maxx", qgsDoubleToString( featuresRect->xMaximum(), 8 ) );
bBoxElem.setAttribute( "miny", qgsDoubleToString( featuresRect->yMinimum(), 8 ) );
bBoxElem.setAttribute( "maxy", qgsDoubleToString( featuresRect->yMaximum(), 8 ) );
getFeatureInfoElement.insertBefore( bBoxElem, QDomNode() ); //insert as first child
}
}
Expand Down Expand Up @@ -1830,10 +1830,10 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
{
QDomElement bBoxElem = infoDocument.createElement( "BoundingBox" );
bBoxElem.setAttribute( version == "1.1.1" ? "SRS" : "CRS", outputCrs.authid() );
bBoxElem.setAttribute( "minx", QString::number( box.xMinimum() ) );
bBoxElem.setAttribute( "maxx", QString::number( box.xMaximum() ) );
bBoxElem.setAttribute( "miny", QString::number( box.yMinimum() ) );
bBoxElem.setAttribute( "maxy", QString::number( box.yMaximum() ) );
bBoxElem.setAttribute( "minx", qgsDoubleToString( box.xMinimum(), 8 ) );
bBoxElem.setAttribute( "maxx", qgsDoubleToString( box.xMaximum(), 8 ) );
bBoxElem.setAttribute( "miny", qgsDoubleToString( box.yMinimum(), 8 ) );
bBoxElem.setAttribute( "maxy", qgsDoubleToString( box.yMaximum(), 8 ) );
featureElement.appendChild( bBoxElem );
}

Expand All @@ -1851,7 +1851,7 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
}
QDomElement geometryElement = infoDocument.createElement( "Attribute" );
geometryElement.setAttribute( "name", "geometry" );
geometryElement.setAttribute( "value", geom->exportToWkt() );
geometryElement.setAttribute( "value", geom->exportToWkt( 8 ) );
geometryElement.setAttribute( "type", "derived" );
featureElement.appendChild( geometryElement );
}
Expand Down Expand Up @@ -2836,11 +2836,11 @@ QDomElement QgsWMSServer::createFeatureGML(
QDomElement boxElem;
if ( version < 3 )
{
boxElem = QgsOgcUtils::rectangleToGMLBox( &box, doc );
boxElem = QgsOgcUtils::rectangleToGMLBox( &box, doc, 8 );
}
else
{
boxElem = QgsOgcUtils::rectangleToGMLEnvelope( &box, doc );
boxElem = QgsOgcUtils::rectangleToGMLEnvelope( &box, doc, 8 );
}

if ( crs.isValid() )
Expand All @@ -2864,11 +2864,11 @@ QDomElement QgsWMSServer::createFeatureGML(
QDomElement gmlElem;
if ( version < 3 )
{
gmlElem = QgsOgcUtils::geometryToGML( geom, doc );
gmlElem = QgsOgcUtils::geometryToGML( geom, doc, 8 );
}
else
{
gmlElem = QgsOgcUtils::geometryToGML( geom, doc, "GML3" );
gmlElem = QgsOgcUtils::geometryToGML( geom, doc, "GML3", 8 );
}

if ( !gmlElem.isNull() )
Expand Down

0 comments on commit 324826e

Please sign in to comment.