Skip to content

Commit

Permalink
wms server: improve inverted axis handling for WMS 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Mar 25, 2012
1 parent be42f37 commit dcd8685
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 29 deletions.
17 changes: 8 additions & 9 deletions python/core/qgsrect.sip
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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();
};

7 changes: 7 additions & 0 deletions src/core/qgsrectangle.cpp
Expand Up @@ -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;
}
4 changes: 4 additions & 0 deletions src/core/qgsrectangle.h
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions src/mapserver/qgsconfigparser.cpp
Expand Up @@ -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() )
Expand Down Expand Up @@ -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" );
Expand Down
18 changes: 14 additions & 4 deletions src/mapserver/qgsprojectparser.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/mapserver/qgsprojectparser.h
Expand Up @@ -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();
Expand Down

0 comments on commit dcd8685

Please sign in to comment.