Skip to content
Permalink
Browse files

follow up 9a9b53b:

- enable transform caching (comparing before each use disables its point)
- invalidate the render transform cache only when the layer crs changes by
  connecting to the QgsMapLayer::layerCrsChanged() signal.
- make CRS of map layer private so that setCrs has to be used on each change
  • Loading branch information
jef-n committed Jan 15, 2012
1 parent 872e3c9 commit 84dc1ba5e9514b37dbf519b5adfb9e0063716d4e
@@ -513,6 +513,13 @@ const QgsCoordinateReferenceSystem& QgsMapLayer::srs()
void QgsMapLayer::setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal )
{
*mCRS = srs;

if ( !mCRS->isValid() )
{
mCRS->setValidationHint( tr( "Specify CRS for layer %1" ).arg( name() ) );
mCRS->validate();
}

if ( emitSignal )
emit layerCrsChanged();
}
@@ -235,7 +235,6 @@ class CORE_EXPORT QgsMapLayer : public QObject
@note emitSignal added in 1.4 */
void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );


/** A convenience function to capitalise the layer name */
static QString capitaliseLayerName( const QString name );

@@ -418,15 +417,15 @@ class CORE_EXPORT QgsMapLayer : public QObject
/** Name of the layer - used for display */
QString mLayerName;

/** layer's Spatial reference system */
QgsCoordinateReferenceSystem* mCRS;

QString mTitle;

/**Description of the layer*/
QString mAbstract;

private:
/** layer's spatial reference system.
private to make sure setCrs must be used and layerCrsChanged() is emitted */
QgsCoordinateReferenceSystem* mCRS;

/** private copy constructor - QgsMapLayer not copyable */
QgsMapLayer( QgsMapLayer const & );
@@ -680,7 +680,7 @@ void QgsMapRenderer::setDestinationCrs( const QgsCoordinateReferenceSystem& crs
QgsDebugMsg( "* DestCRS.srsid() = " + QString::number( crs.srsid() ) );
if ( *mDestCRS != crs )
{
mCachedTrForLayer = 0;
invalidateCachedLayerCrs();
QgsDebugMsg( "Setting DistArea CRS to " + QString::number( crs.srsid() ) );
mDistArea->setSourceCrs( crs.srsid() );
*mDestCRS = crs;
@@ -1107,15 +1107,26 @@ void QgsMapRenderer::setLabelingEngine( QgsLabelingEngineInterface* iface )

QgsCoordinateTransform *QgsMapRenderer::tr( QgsMapLayer *layer )
{
// mCachedTrForLayer is unset by setDestinationCrs(), but layer->crs may also be changed after CRS was cached -> check it - the question is, how efficient now the caching is, because crs == operator is not cheap
if ( mCachedTrForLayer != layer || layer->crs() != mCachedTr->sourceCrs() )
if ( mCachedTrForLayer != layer )
{
invalidateCachedLayerCrs();

delete mCachedTr;
mCachedTr = new QgsCoordinateTransform( layer->crs(), *mDestCRS );
mCachedTrForLayer = layer;

connect( layer, SIGNAL( layerCrsChanged() ), this, SLOT( invalidateCachedLayerCrs() ) );
}

return mCachedTr;
}

void QgsMapRenderer::invalidateCachedLayerCrs()
{
if ( mCachedTrForLayer )
disconnect( mCachedTrForLayer, SIGNAL( layerCrsChanged() ), this, SLOT( invalidateCachedLayerCrs() ) );

mCachedTrForLayer = 0;
}

bool QgsMapRenderer::mDrawing = false;
@@ -251,6 +251,9 @@ class CORE_EXPORT QgsMapRenderer : public QObject
//! called by signal from layer current being drawn
void onDrawingProgress( int current, int total );

//! invalidate cached layer CRS
void invalidateCachedLayerCrs();

protected:

//! adjust extent to fit the pixmap size
@@ -21,16 +21,7 @@
* *
***************************************************************************/

#include <cfloat>
#include <cstring>
#include <climits>
#include <cmath>
#include <iosfwd>
#include <limits>
#include <memory>
#include <set>
#include <sstream>
#include <utility>

#include <QImage>
#include <QPainter>
@@ -2588,11 +2579,11 @@ int QgsVectorLayer::addTopologicalPoints( const QgsPoint& p )

//work with a tolerance because coordinate projection may introduce some rounding
double threshold = 0.0000001;
if ( mCRS && mCRS->mapUnits() == QGis::Meters )
if ( crs().mapUnits() == QGis::Meters )
{
threshold = 0.001;
}
else if ( mCRS && mCRS->mapUnits() == QGis::Feet )
else if ( crs().mapUnits() == QGis::Feet )
{
threshold = 0.0001;
}
@@ -4478,24 +4469,14 @@ void QgsVectorLayer::setCoordinateSystem()
// for this layer
//

// get CRS directly from provider
*mCRS = mDataProvider->crs();

//QgsCoordinateReferenceSystem provides a mechanism for FORCE a srs to be valid
//which is inolves falling back to system, project or user selected
//defaults if the srs is not properly intialised.
//we only nee to do that if the srs is not alreay valid
if ( !mCRS->isValid() )
if ( hasGeometryType() )
{
if ( hasGeometryType() )
{
mCRS->setValidationHint( tr( "Specify CRS for layer %1" ).arg( name() ) );
mCRS->validate();
}
else
{
mCRS->createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
}
// get CRS directly from provider
setCrs( mDataProvider->crs() );
}
else
{
setCrs( QgsCoordinateReferenceSystem( GEO_EPSG_CRS_AUTHID ) );
}
}

@@ -1797,7 +1797,7 @@ QString QgsRasterLayer::metadata()
myMetadata += tr( "Layer Spatial Reference System: " );
myMetadata += "</p>\n";
myMetadata += "<p>";
myMetadata += mCRS->toProj4();
myMetadata += crs().toProj4();
myMetadata += "</p>\n";

myMetadata += "<p class=\"glossy\">";
@@ -2224,7 +2224,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs,
QString const & theCrs,
bool loadDefaultStyleFlag )
{
Q_UNUSED( loadDefaultStyleFlag );
@@ -2251,13 +2251,15 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
}


QgsDebugMsg( "Instantiated the data provider plugin"
+ QString( " with layer list of " ) + layers.join( ", " )
+ " and style list of " + styles.join( ", " )
+ " and format of " + format + " and CRS of " + crs );
QgsDebugMsg( QString( "Instantiated the data provider plugin with layer list of %1 and style list of %2 and format of %3 and CRS of %4" )
.arg( layers.join( ", " ) )
.arg( styles.join( ", " ) )
.arg( format )
.arg( theCrs )
);
if ( !mDataProvider->isValid() )
{
if ( provider != "gdal" || !layers.isEmpty() || !styles.isEmpty() || !format.isNull() || !crs.isNull() )
if ( provider != "gdal" || !layers.isEmpty() || !styles.isEmpty() || !format.isNull() || !theCrs.isNull() )
{
QgsMessageLog::logMessage( tr( "Data provider is invalid (layers %1, styles %2, formats: %3)" )
.arg( layers.join( ", " ) )
@@ -2270,7 +2272,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider,

mDataProvider->addLayers( layers, styles );
mDataProvider->setImageEncoding( format );
mDataProvider->setImageCrs( crs );
mDataProvider->setImageCrs( theCrs );

setNoDataValue( mDataProvider->noDataValue() );

@@ -2299,21 +2301,16 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
// Setup source CRS
if ( mProviderKey == "wms" )
{
*mCRS = QgsCoordinateReferenceSystem();
mCRS->createFromOgcWmsCrs( crs );
QgsCoordinateReferenceSystem crs;
crs.createFromOgcWmsCrs( theCrs );
setCrs( crs );
}
else
{
*mCRS = QgsCoordinateReferenceSystem( mDataProvider->crs() );
setCrs( QgsCoordinateReferenceSystem( mDataProvider->crs() ) );
}
//get the project projection, defaulting to this layer's projection
//if none exists....
if ( !mCRS->isValid() )
{
mCRS->setValidationHint( tr( "Specify CRS for layer %1" ).arg( name() ) );
mCRS->validate();
}
QString mySourceWkt = mCRS->toWkt();

QString mySourceWkt = crs().toWkt();

QgsDebugMsg( "using wkt:\n" + mySourceWkt );

0 comments on commit 84dc1ba

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