mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Cache for coordinate transformations
This commit is contained in:
parent
d4aa0ed62a
commit
496355b367
@ -16,6 +16,46 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgscrscache.h"
|
||||
#include "qgscoordinatetransform.h"
|
||||
|
||||
QgsCoordinateTransformCache* QgsCoordinateTransformCache::mInstance = 0;
|
||||
|
||||
QgsCoordinateTransformCache* QgsCoordinateTransformCache::instance()
|
||||
{
|
||||
if ( !mInstance )
|
||||
{
|
||||
mInstance = new QgsCoordinateTransformCache();
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
QgsCoordinateTransformCache::~QgsCoordinateTransformCache()
|
||||
{
|
||||
QHash< QPair< QString, QString >, QgsCoordinateTransform* >::const_iterator tIt = mTransforms.constBegin();
|
||||
for ( ; tIt != mTransforms.constEnd(); ++tIt )
|
||||
{
|
||||
delete tIt.value();
|
||||
}
|
||||
delete mInstance;
|
||||
}
|
||||
|
||||
const QgsCoordinateTransform* QgsCoordinateTransformCache::transform( const QString& srcAuthId, const QString& destAuthId )
|
||||
{
|
||||
QHash< QPair< QString, QString >, QgsCoordinateTransform* >::const_iterator ctIt =
|
||||
mTransforms.find( qMakePair( srcAuthId, destAuthId ) );
|
||||
if ( ctIt == mTransforms.constEnd() )
|
||||
{
|
||||
const QgsCoordinateReferenceSystem& srcCrs = QgsCRSCache::instance()->crsByAuthId( srcAuthId );
|
||||
const QgsCoordinateReferenceSystem& destCrs = QgsCRSCache::instance()->crsByAuthId( destAuthId );
|
||||
QgsCoordinateTransform* ct = new QgsCoordinateTransform( srcCrs, destCrs );
|
||||
mTransforms.insert( qMakePair( srcAuthId, destAuthId ), ct );
|
||||
return ct;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ctIt.value();
|
||||
}
|
||||
}
|
||||
|
||||
QgsCRSCache* QgsCRSCache::mInstance = 0;
|
||||
|
||||
|
@ -21,6 +21,25 @@
|
||||
#include "qgscoordinatereferencesystem.h"
|
||||
#include <QHash>
|
||||
|
||||
class QgsCoordinateTransform;
|
||||
|
||||
/**Cache coordinate transform by authid of source/dest transformation to avoid the
|
||||
overhead of initialisation for each redraw*/
|
||||
class CORE_EXPORT QgsCoordinateTransformCache
|
||||
{
|
||||
public:
|
||||
static QgsCoordinateTransformCache* instance();
|
||||
~QgsCoordinateTransformCache();
|
||||
/**Returns coordinate transformation. Cache keeps ownership
|
||||
@param srcAuthId auth id string of source crs
|
||||
@param destAuthId auth id string of dest crs*/
|
||||
const QgsCoordinateTransform* transform( const QString& srcAuthId, const QString& destAuthId );
|
||||
|
||||
private:
|
||||
static QgsCoordinateTransformCache* mInstance;
|
||||
QHash< QPair< QString, QString >, QgsCoordinateTransform* > mTransforms;
|
||||
};
|
||||
|
||||
class CORE_EXPORT QgsCRSCache
|
||||
{
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user