QGIS API Documentation  2.99.0-Master (c42dad3)
qgscrscache.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscrscache.cpp
3  ---------------
4  begin : September 6th, 2011
5  copyright : (C) 2011 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgscrscache.h"
19 #include "qgscoordinatetransform.h"
20 #include <QVector>
21 
23 {
24  static QgsCoordinateTransformCache mInstance;
25  return &mInstance;
26 }
27 
28 QgsCoordinateTransformCache::QgsCoordinateTransformCache()
29 {
30 }
31 
33 {}
34 
35 QgsCoordinateTransform QgsCoordinateTransformCache::transform( const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform, int destDatumTransform )
36 {
37  QList< QgsCoordinateTransform > values =
38  mTransforms.values( qMakePair( srcAuthId, destAuthId ) );
39 
40  QList< QgsCoordinateTransform >::const_iterator valIt = values.constBegin();
41  for ( ; valIt != values.constEnd(); ++valIt )
42  {
43  if (( *valIt ).isValid() &&
44  ( *valIt ).sourceDatumTransform() == srcDatumTransform &&
45  ( *valIt ).destinationDatumTransform() == destDatumTransform )
46  {
47  return *valIt;
48  }
49  }
50 
51  //not found, insert new value
54  QgsCoordinateTransform ct = QgsCoordinateTransform( srcCrs, destCrs );
55  ct.setSourceDatumTransform( srcDatumTransform );
56  ct.setDestinationDatumTransform( destDatumTransform );
57  ct.initialise();
58  mTransforms.insertMulti( qMakePair( srcAuthId, destAuthId ), ct );
59  return ct;
60 }
61 
62 void QgsCoordinateTransformCache::invalidateCrs( const QString& crsAuthId )
63 {
64  //get keys to remove first
65  QHash< QPair< QString, QString >, QgsCoordinateTransform >::const_iterator it = mTransforms.constBegin();
66  QVector< QPair< QString, QString > > updateList;
67 
68  for ( ; it != mTransforms.constEnd(); ++it )
69  {
70  if ( it.key().first == crsAuthId || it.key().second == crsAuthId )
71  {
72  updateList.append( it.key() );
73  }
74  }
75 
76  //and remove after
77  QVector< QPair< QString, QString > >::const_iterator updateIt = updateList.constBegin();
78  for ( ; updateIt != updateList.constEnd(); ++updateIt )
79  {
80  mTransforms.remove( *updateIt );
81  }
82 }
void initialise()
initialize is used to actually create the Transformer instance
static QgsCoordinateTransformCache * instance()
Definition: qgscrscache.cpp:22
void invalidateCrs(const QString &crsAuthId)
Removes transformations where a changed crs is involved from the cache.
Definition: qgscrscache.cpp:62
QgsCoordinateTransform transform(const QString &srcAuthId, const QString &destAuthId, int srcDatumTransform=-1, int destDatumTransform=-1)
Returns coordinate transformation.
Definition: qgscrscache.cpp:35
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
Cache coordinate transform by authid of source/dest transformation to avoid the overhead of initializ...
Definition: qgscrscache.h:30