17 changes: 8 additions & 9 deletions python/core/qgsrect.sip
Original file line number Diff line number Diff line change
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();
};

5 changes: 1 addition & 4 deletions src/core/qgsattributeaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,8 @@ class CORE_EXPORT QgsAttributeAction

/*! Expands the given action, replacing all %'s with the value as
* given.
* @deprecated
*/
Q_DECL_DEPRECATED QString expandAction( QString action,
const QgsAttributeMap &attributes,
uint defaultValueIndex );
QString expandAction( QString action, const QgsAttributeMap &attributes, uint defaultValueIndex );

/*! Expands the given action using the expression builder
* This function currently replaces each expression between [% and %]
Expand Down
81 changes: 68 additions & 13 deletions src/core/qgsdatasourceuri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ QgsDataSourceURI::QgsDataSourceURI()
, mKeyColumn( "" )
, mUseEstimatedMetadata( false )
, mSelectAtIdDisabled( false )
, mGeometryType( QGis::UnknownGeometry )
, mWkbType( QGis::WKBUnknown )
{
// do nothing
}
Expand All @@ -37,7 +37,7 @@ QgsDataSourceURI::QgsDataSourceURI( QString uri )
, mKeyColumn( "" )
, mUseEstimatedMetadata( false )
, mSelectAtIdDisabled( false )
, mGeometryType( QGis::UnknownGeometry )
, mWkbType( QGis::WKBUnknown )
{
int i = 0;
while ( i < uri.length() )
Expand Down Expand Up @@ -134,19 +134,31 @@ QgsDataSourceURI::QgsDataSourceURI( QString uri )
QString geomTypeUpper = pval.toUpper();
if ( geomTypeUpper == "POINT" )
{
mGeometryType = QGis::Point;
mWkbType = QGis::WKBPoint;
}
else if ( geomTypeUpper == "LINE" )
else if ( geomTypeUpper == "LINESTRING" || geomTypeUpper == "LINE" )
{
mGeometryType = QGis::Line;
mWkbType = QGis::WKBLineString;
}
else if ( geomTypeUpper == "POLYGON" )
{
mGeometryType = QGis::Polygon;
mWkbType = QGis::WKBPolygon;
}
else if ( geomTypeUpper == "MULTIPOINT" )
{
mWkbType = QGis::WKBMultiPoint;
}
else if ( geomTypeUpper == "MULTLINESTRING" )
{
mWkbType = QGis::WKBMultiLineString;
}
else if ( geomTypeUpper == "MULTIPOLYGON" )
{
mWkbType = QGis::WKBMultiPolygon;
}
else
{
mGeometryType = QGis::UnknownGeometry;
mWkbType = QGis::WKBUnknown;
}
}
else if ( pname == "selectatid" )
Expand Down Expand Up @@ -514,9 +526,52 @@ QString QgsDataSourceURI::uri() const
theUri += QString( " srid=%1" ).arg( mSrid );
}

if ( mGeometryType != QGis::UnknownGeometry && mGeometryType != QGis::NoGeometry )
if ( mWkbType != QGis::WKBUnknown && mWkbType != QGis::WKBNoGeometry )
{
theUri += QString( " type=%1" ).arg( QGis::qgisVectorGeometryType[mGeometryType] );
theUri += " type=";

switch( mWkbType )
{
case QGis::WKBPoint:
theUri += "POINT";
break;
case QGis::WKBLineString:
theUri += "LINESTRING";
break;
case QGis::WKBPolygon:
theUri += "POLYGON";
break;
case QGis::WKBMultiPoint:
theUri += "MULTIPOINT";
break;
case QGis::WKBMultiLineString:
theUri += "MULTILINESTRING";
break;
case QGis::WKBMultiPolygon:
theUri += "MULTIPOLYGON";
break;
case QGis::WKBPoint25D:
theUri += "POINTM";
break;
case QGis::WKBLineString25D:
theUri += "LINESTRINGM";
break;
case QGis::WKBPolygon25D:
theUri += "POLYGONM";
break;
case QGis::WKBMultiPoint25D:
theUri += "MULTIPOINTM";
break;
case QGis::WKBMultiLineString25D:
theUri += "MULTILINESTRINGM";
break;
case QGis::WKBMultiPolygon25D:
theUri += "MULTIPOLYGONM";
break;
case QGis::WKBUnknown:
case QGis::WKBNoGeometry:
break;
}
}

if ( mSelectAtIdDisabled )
Expand Down Expand Up @@ -589,14 +644,14 @@ void QgsDataSourceURI::setDatabase( const QString &database )
mDatabase = database;
}

QGis::GeometryType QgsDataSourceURI::geometryType() const
QGis::WkbType QgsDataSourceURI::wkbType() const
{
return mGeometryType;
return mWkbType;
}

void QgsDataSourceURI::setGeometryType( QGis::GeometryType geometryType )
void QgsDataSourceURI::setWkbType( QGis::WkbType wkbType )
{
mGeometryType = geometryType;
mWkbType = wkbType;
}

QString QgsDataSourceURI::srid() const
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsdatasourceuri.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class CORE_EXPORT QgsDataSourceURI
void setKeyColumn( QString column );

// added in 1.9
QGis::GeometryType geometryType() const;
void setGeometryType( QGis::GeometryType type );
QGis::WkbType wkbType() const;
void setWkbType( QGis::WkbType type );

QString srid() const;
void setSrid( QString srid );
Expand Down Expand Up @@ -160,7 +160,7 @@ class CORE_EXPORT QgsDataSourceURI
//! Disable SelectAtId capability (eg. to trigger the attribute table memory model for expensive views)
bool mSelectAtIdDisabled;
//! geometry type (or QGis::WKBUnknown if not specified)
QGis::GeometryType mGeometryType;
QGis::WkbType mWkbType;
//! SRID or a null string if not specified
QString mSrid;
};
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsrectangle.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
27 changes: 18 additions & 9 deletions src/providers/mssql/qgsmssqldataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ void QgsMssqlConnectionItem::setLayerType( QgsMssqlLayerProperty layerProperty )

for ( int i = 0 ; i < typeList.size(); i++ )
{
QGis::GeometryType geomType = QgsMssqlTableModel::geomTypeFromMssql( typeList[i] );
if ( geomType == QGis::UnknownGeometry )
QGis::WkbType wkbType = QgsMssqlTableModel::wkbTypeFromMssql( typeList[i] );
if ( wkbType == QGis::WKBUnknown )
{
QgsDebugMsg( QString( "unsupported geometry type:%1" ).arg( typeList[i] ) );
continue;
Expand Down Expand Up @@ -420,7 +420,7 @@ QString QgsMssqlLayerItem::createUri()
QgsDataSourceURI uri = QgsDataSourceURI( connItem->connInfo() );
uri.setDataSource( mLayerProperty.schemaName, mLayerProperty.tableName, mLayerProperty.geometryColName, mLayerProperty.sql, pkColName );
uri.setSrid( mLayerProperty.srid );
uri.setGeometryType( QgsMssqlTableModel::geomTypeFromMssql( mLayerProperty.type ) );
uri.setWkbType( QgsMssqlTableModel::wkbTypeFromMssql( mLayerProperty.type ) );
QgsDebugMsg( QString( "layer uri: %1" ).arg( uri.uri() ) );
return uri.uri();
}
Expand Down Expand Up @@ -459,19 +459,28 @@ void QgsMssqlSchemaItem::addLayers( QgsDataItem* newLayers )

QgsMssqlLayerItem* QgsMssqlSchemaItem::addLayer( QgsMssqlLayerProperty layerProperty, bool refresh )
{
QGis::GeometryType geomType = QgsMssqlTableModel::geomTypeFromMssql( layerProperty.type );
QString tip = tr( "%1 as %2 in %3" ).arg( layerProperty.geometryColName ).arg( QgsMssqlTableModel::displayStringForGeomType( geomType ) ).arg( layerProperty.srid );
QGis::WkbType wkbType = QgsMssqlTableModel::wkbTypeFromMssql( layerProperty.type );
QString tip = tr( "%1 as %2 in %3" ).arg( layerProperty.geometryColName ).arg( QgsMssqlTableModel::displayStringForWkbType( wkbType ) ).arg( layerProperty.srid );

QgsLayerItem::LayerType layerType;
switch ( geomType )
switch ( wkbType )
{
case QGis::Point:
case QGis::WKBPoint:
case QGis::WKBPoint25D:
case QGis::WKBMultiPoint:
case QGis::WKBMultiPoint25D:
layerType = QgsLayerItem::Point;
break;
case QGis::Line:
case QGis::WKBLineString:
case QGis::WKBLineString25D:
case QGis::WKBMultiLineString:
case QGis::WKBMultiLineString25D:
layerType = QgsLayerItem::Line;
break;
case QGis::Polygon:
case QGis::WKBPolygon:
case QGis::WKBPolygon25D:
case QGis::WKBMultiPolygon:
case QGis::WKBMultiPolygon25D:
layerType = QgsLayerItem::Polygon;
break;
default:
Expand Down
Loading