Skip to content
Permalink
Browse files
wms server: improve inverted axis handling for WMS 1.3
  • Loading branch information
jef-n committed Mar 25, 2012
1 parent be42f37 commit dcd8685d3903fa478fd881eb879570e862321e99
@@ -2,7 +2,7 @@
/*! \class QgsRectangle
* \brief A rectangle specified with double values.
*
* QgsRectangle is used to store a rectangle when double values are required.
* QgsRectangle is used to store a rectangle when double values are required.
* Examples are storing a layer extent or the current view extent of a map
*/
class QgsRectangle
@@ -21,10 +21,10 @@ class QgsRectangle
//! Destructor
~QgsRectangle();
//! Set the rectangle from two QgsPoints. The rectangle is
//normalised after construction.
//normalised after construction.
void set(const QgsPoint& p1, const QgsPoint& p2);
//! Set the rectangle from four points. The rectangle is
// normalised after construction.
// normalised after construction.
void set(double xmin, double ymin, double xmax, double ymax);
//! Set the minimum x value
void setXMinimum(double x);
@@ -79,7 +79,7 @@ class QgsRectangle
QString toString(bool automaticPrecision = false) const;
//! overloaded toString that allows precision of numbers to be set
QString toString(int thePrecision) const;
//! returns rectangle s a polygon
//! returns rectangle as a polygon
QString asPolygon() const;
/*! Comparison operator
@return True if rectangles are equal
@@ -89,10 +89,9 @@ class QgsRectangle
@return False if rectangles are equal
*/
bool operator!=(const QgsRectangle &r1) const;

/** updates rectangle to include passed argument */
//! updates rectangle to include passed argument
void unionRect(const QgsRectangle& rect);


//! swap x/y
//! @note added in 1.9
void invert();
};

@@ -323,3 +323,10 @@ bool QgsRectangle::isFinite() const
}
return true;
}

void QgsRectangle::invert()
{
double tmp;
tmp = xmin; xmin = ymin; ymin = tmp;
tmp = xmax; xmax = ymax; ymax = tmp;
}
@@ -123,6 +123,10 @@ class CORE_EXPORT QgsRectangle
return false if any of the rectangle boundaries are NaN or Inf. */
bool isFinite() const;

//! swap x/y
//! @note added in 1.9
void invert();

protected:

// These are protected instead of private so that things like
@@ -144,10 +144,16 @@ void QgsConfigParser::appendLayerBoundingBoxes( QDomElement& layerElem,
bBoxElement.setAttribute( version == "1.1.1" ? "SRS" : "CRS", layerCRS.authid() );
}

bBoxElement.setAttribute( "minx", QString::number( layerExtent.xMinimum() ) );
bBoxElement.setAttribute( "miny", QString::number( layerExtent.yMinimum() ) );
bBoxElement.setAttribute( "maxx", QString::number( layerExtent.xMaximum() ) );
bBoxElement.setAttribute( "maxy", QString::number( layerExtent.yMaximum() ) );
QgsRectangle r( layerExtent );
if ( version == "1.3.0" && layerCRS.axisInverted() )
{
r.invert();
}

bBoxElement.setAttribute( "minx", QString::number( r.xMinimum() ) );
bBoxElement.setAttribute( "miny", QString::number( r.yMinimum() ) );
bBoxElement.setAttribute( "maxx", QString::number( r.xMaximum() ) );
bBoxElement.setAttribute( "maxy", QString::number( r.yMaximum() ) );

QDomElement lastCRSElem = layerElem.lastChildElement( version == "1.1.1" ? "SRS" : "CRS" );
if ( !lastCRSElem.isNull() )
@@ -444,21 +450,15 @@ QgsComposition* QgsConfigParser::createPrintComposition( const QString& composer
c->removeItem( currentMap ); delete currentMap; continue;
}

QgsRectangle r( xmin, ymin, xmax, ymax );

//Change x- and y- of extent for WMS 1.3.0 if axis inverted
QString version = parameterMap.value( "VERSION" );
if ( !version.isEmpty() )
if ( version == "1.3.0" && mapRenderer && mapRenderer->destinationCrs().axisInverted() )
{
if ( mapRenderer && version == "1.3.0" && mapRenderer->destinationCrs().axisInverted() )
{
//switch coordinates of extent
double tmp;
tmp = xmin;
xmin = ymin; ymin = tmp;
tmp = xmax;
xmax = ymax; ymax = tmp;
}
r.invert();
}
currentMap->setNewExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
currentMap->setNewExtent( r );

//scale
QString scaleString = parameterMap.value( mapId + ":SCALE" );
@@ -359,7 +359,7 @@ void QgsProjectParser::combineExtentAndCrsOfGroupChildren( QDomElement& groupEle
if ( childElem.tagName() != "Layer" )
continue;

QgsRectangle bbox = layerBoundingBoxInProjectCRS( childElem );
QgsRectangle bbox = layerBoundingBoxInProjectCRS( childElem, doc );
if ( !bbox.isEmpty() )
{
if ( firstBBox )
@@ -1556,7 +1556,7 @@ const QgsCoordinateReferenceSystem& QgsProjectParser::projectCRS() const
return QgsCRSCache::instance()->crsByEpsgId( GEO_EPSG_CRS_ID );
}

QgsRectangle QgsProjectParser::layerBoundingBoxInProjectCRS( const QDomElement& layerElem ) const
QgsRectangle QgsProjectParser::layerBoundingBoxInProjectCRS( const QDomElement& layerElem, const QDomDocument &doc ) const
{
QgsRectangle BBox;
if ( layerElem.isNull() )
@@ -1594,18 +1594,28 @@ QgsRectangle QgsProjectParser::layerBoundingBoxInProjectCRS( const QDomElement&
return BBox;
}


QString version = doc.documentElement().attribute( "version" );

//create layer crs
const QgsCoordinateReferenceSystem& layerCrs = QgsCRSCache::instance()->crsByAuthId( boundingBoxElem.attribute( "CRS" ) );
const QgsCoordinateReferenceSystem& layerCrs = QgsCRSCache::instance()->crsByAuthId( boundingBoxElem.attribute( version == "1.1.1" ? "SRS" : "CRS" ) );
if ( !layerCrs.isValid() )
{
return BBox;
}

BBox.set( minx, miny, maxx, maxy );

if ( version == "1.3.0" && layerCrs.axisInverted() )
{
BBox.invert();
}

//get project crs
const QgsCoordinateReferenceSystem& projectCrs = projectCRS();
QgsCoordinateTransform t( layerCrs, projectCrs );

//transform
BBox = t.transformBoundingBox( QgsRectangle( minx, miny, maxx, maxy ) );
BBox = t.transformBoundingBox( BBox );
return BBox;
}
@@ -163,7 +163,7 @@ class QgsProjectParser: public QgsConfigParser
const QgsCoordinateReferenceSystem& projectCRS() const;

/**Returns bbox of layer in project CRS (or empty rectangle in case of error)*/
QgsRectangle layerBoundingBoxInProjectCRS( const QDomElement& layerElem ) const;
QgsRectangle layerBoundingBoxInProjectCRS( const QDomElement& layerElem, const QDomDocument& doc ) const;

/**Reads selection color from project and sets it to QgsConfigParser::mSelectionColor*/
void setSelectionColor();

0 comments on commit dcd8685

Please sign in to comment.