Skip to content
Permalink
Browse files

Better writing of coordinate (WKT, GeoJSON, GML2) and using of search…

…Rect
  • Loading branch information
rldhont committed Sep 29, 2012
1 parent fe8385e commit 0c29b4bef5196db21dc1fea0451b4c2a7b50e6b2
Showing with 33 additions and 28 deletions.
  1. +24 −24 src/core/qgsgeometry.cpp
  2. +9 −4 src/mapserver/qgswfsserver.cpp
@@ -3946,10 +3946,10 @@ QString QgsGeometry::exportToWkt()
{
mWkt += "POINT(";
x = ( double * )( mGeometry + 5 );
mWkt += QString::number( *x, 'f', 6 );
mWkt += QString::number( *x, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
mWkt += " ";
y = ( double * )( mGeometry + 5 + sizeof( double ) );
mWkt += QString::number( *y, 'f', 6 );
mWkt += QString::number( *y, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
mWkt += ")";
return mWkt;
}
@@ -3975,11 +3975,11 @@ QString QgsGeometry::exportToWkt()
mWkt += ", ";
}
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 6 );
mWkt += QString::number( *x, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
mWkt += " ";
ptr += sizeof( double );
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 6 );
mWkt += QString::number( *y, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4030,11 +4030,11 @@ QString QgsGeometry::exportToWkt()
mWkt += ",";
}
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 6 );
mWkt += QString::number( *x, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
mWkt += " ";
ptr += sizeof( double );
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 6 );
mWkt += QString::number( *y, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4068,11 +4068,11 @@ QString QgsGeometry::exportToWkt()
mWkt += ", ";
}
x = ( double * )( ptr );
mWkt += QString::number( *x, 'f', 6 );
mWkt += QString::number( *x, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
mWkt += " ";
ptr += sizeof( double );
y = ( double * )( ptr );
mWkt += QString::number( *y, 'f', 6 );
mWkt += QString::number( *y, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4112,11 +4112,11 @@ QString QgsGeometry::exportToWkt()
mWkt += ", ";
}
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 6 );
mWkt += QString::number( *x, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
ptr += sizeof( double );
mWkt += " ";
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 6 );
mWkt += QString::number( *y, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4168,11 +4168,11 @@ QString QgsGeometry::exportToWkt()
mWkt += ",";
}
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 6 );
mWkt += QString::number( *x, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
ptr += sizeof( double );
mWkt += " ";
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 6 );
mWkt += QString::number( *y, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4226,10 +4226,10 @@ QString QgsGeometry::exportToGeoJSON()
{
mWkt += "{ \"type\": \"Point\", \"coordinates\": [";
x = ( double * )( mGeometry + 5 );
mWkt += QString::number( *x, 'f' );
mWkt += QString::number( *x, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
mWkt += ", ";
y = ( double * )( mGeometry + 5 + sizeof( double ) );
mWkt += QString::number( *y, 'f' );
mWkt += QString::number( *y, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
mWkt += "] }";
return mWkt;
}
@@ -4256,11 +4256,11 @@ QString QgsGeometry::exportToGeoJSON()
}
mWkt += "[";
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f' );
mWkt += QString::number( *x, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
mWkt += ", ";
ptr += sizeof( double );
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f' );
mWkt += QString::number( *y, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4313,11 +4313,11 @@ QString QgsGeometry::exportToGeoJSON()
}
mWkt += "[";
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f' );
mWkt += QString::number( *x, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
mWkt += ", ";
ptr += sizeof( double );
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f' );
mWkt += QString::number( *y, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4353,11 +4353,11 @@ QString QgsGeometry::exportToGeoJSON()
}
mWkt += "[";
x = ( double * )( ptr );
mWkt += QString::number( *x, 'f' );
mWkt += QString::number( *x, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
mWkt += ", ";
ptr += sizeof( double );
y = ( double * )( ptr );
mWkt += QString::number( *y, 'f' );
mWkt += QString::number( *y, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4399,11 +4399,11 @@ QString QgsGeometry::exportToGeoJSON()
}
mWkt += "[";
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f' );
mWkt += QString::number( *x, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
ptr += sizeof( double );
mWkt += ", ";
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f' );
mWkt += QString::number( *y, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -4457,11 +4457,11 @@ QString QgsGeometry::exportToGeoJSON()
}
mWkt += "[";
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f' );
mWkt += QString::number( *x, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
ptr += sizeof( double );
mWkt += ", ";
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f' );
mWkt += QString::number( *y, 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
ptr += sizeof( double );
if ( hasZValue )
{
@@ -441,6 +441,11 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format

if ( bboxOk )
searchRect.set( minx, miny, maxx, maxy );
else
searchRect.set( searchRect.xMinimum()-0.000001
, searchRect.yMinimum()-0.000001
, searchRect.xMaximum()+0.000001
, searchRect.yMaximum()+0.000001 );
QgsCoordinateReferenceSystem layerCrs = layer->crs();

startGetFeature( request, format, layerCrs, &searchRect );
@@ -511,7 +516,7 @@ void QgsWFSServer::startGetFeature( QgsRequestHandler& request, const QString& f
if ( format == "GeoJSON" )
{
fcString = "{\"type\": \"FeatureCollection\",\n";
fcString += " \"bbox\": [ " + QString::number( rect->xMinimum(), 'f' ) + ", " + QString::number( rect->yMinimum(), 'f' ) + ", " + QString::number( rect->xMaximum(), 'f' ) + ", " + QString::number( rect->yMaximum(), 'f' ) + "],\n";
fcString += " \"bbox\": [ " + QString::number( rect->xMinimum(), 'f', 6 ).remove( QRegExp("[0]{1,5}$") ) + ", " + QString::number( rect->yMinimum(), 'f', 6 ).remove( QRegExp("[0]{1,5}$") ) + ", " + QString::number( rect->xMaximum(), 'f', 6 ).remove( QRegExp("[0]{1,5}$") ) + ", " + QString::number( rect->yMaximum(), 'f', 6 ).remove( QRegExp("[0]{1,5}$") ) + "],\n";
fcString += " \"features\": [\n";
result = fcString.toUtf8();
request.startGetFeatureResponse( &result, format );
@@ -691,7 +696,7 @@ QString QgsWFSServer::createFeatureGeoJSON( QgsFeature* feat, QgsCoordinateRefer
{
QgsRectangle box = geom->boundingBox();

fStr += " \"bbox\": [ " + QString::number( box.xMinimum(), 'f' ) + ", " + QString::number( box.yMinimum(), 'f' ) + ", " + QString::number( box.xMaximum(), 'f' ) + ", " + QString::number( box.yMaximum(), 'f' ) + "],\n";
fStr += " \"bbox\": [ " + QString::number( box.xMinimum(), 'f', 6 ).remove( QRegExp("[0]{1,5}$") ) + ", " + QString::number( box.yMinimum(), 'f', 6 ).remove( QRegExp("[0]{1,5}$") ) + ", " + QString::number( box.xMaximum(), 'f', 6 ).remove( QRegExp("[0]{1,5}$") ) + ", " + QString::number( box.yMaximum(), 'f', 6 ).remove( QRegExp("[0]{1,5}$") ) + "],\n";

fStr += " \"geometry\": ";
fStr += geom->exportToGeoJSON();
@@ -1020,9 +1025,9 @@ QDomElement QgsWFSServer::createCoordinateElem( const QVector<QgsPoint> points,
{
coordString += " ";
}
coordString += QString::number( pointIt->x(), 'f' );
coordString += QString::number( pointIt->x(), 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
coordString += ",";
coordString += QString::number( pointIt->y(), 'f' );
coordString += QString::number( pointIt->y(), 'f', 6 ).remove( QRegExp("[0]{1,5}$") );
}

QDomText coordText = doc.createTextNode( coordString );

0 comments on commit 0c29b4b

Please sign in to comment.
You can’t perform that action at this time.