Skip to content

Commit 15b4843

Browse files
committed
Use CRS cache for faster lookup of crs by authid. Important especially for wms server. Replaces wmsserver/epsgcache.cpp and .h
1 parent 05cdd52 commit 15b4843

File tree

7 files changed

+56
-72
lines changed

7 files changed

+56
-72
lines changed

src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ SET(QGIS_CORE_SRCS
4848
qgsclipper.cpp
4949
qgscontexthelp.cpp
5050
qgscoordinatetransform.cpp
51+
qgscrscache.cpp
5152
qgsdatasourceuri.cpp
5253
qgsdataitem.cpp
5354
qgsdiagram.cpp

src/core/qgscoordinatereferencesystem.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <QTextStream>
2828

2929
#include "qgsapplication.h"
30+
#include "qgscrscache.h"
3031
#include "qgslogger.h"
3132
#include "qgsmessageoutput.h"
3233
#include "qgis.h" //const vals declared here
@@ -1001,14 +1002,24 @@ bool QgsCoordinateReferenceSystem::readXML( QDomNode & theNode )
10011002
QDomNode myNode = srsNode.namedItem( "authid" );
10021003
if ( !myNode.isNull() )
10031004
{
1004-
initialized = createFromOgcWmsCrs( myNode.toElement().text() );
1005+
operator=( QgsCRSCache::instance()->crsByAuthId( myNode.toElement().text() ) );
1006+
if ( isValid() )
1007+
{
1008+
initialized = true;
1009+
}
10051010
}
10061011

10071012
if ( !initialized )
10081013
{
10091014
myNode = srsNode.namedItem( "epsg" );
10101015
if ( !myNode.isNull() )
1011-
initialized = createFromOgcWmsCrs( QString( "EPSG:%1" ).arg( myNode.toElement().text().toLong() ) );
1016+
{
1017+
operator=( QgsCRSCache::instance()->crsByEpsgId( myNode.toElement().text().toLong() ) );
1018+
if ( isValid() )
1019+
{
1020+
initialized = true;
1021+
}
1022+
}
10121023
}
10131024

10141025
if ( initialized )
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/***************************************************************************
2-
qgsepsgcache.cpp
3-
----------------
4-
begin : June 9th, 2010
5-
copyright : (C) 2010 by Marco Hugentobler
2+
qgscrscache.cpp
3+
---------------
4+
begin : September 6th, 2011
5+
copyright : (C) 2011 by Marco Hugentobler
66
email : marco dot hugentobler at sourcepole dot ch
77
***************************************************************************/
88

@@ -15,44 +15,47 @@
1515
* *
1616
***************************************************************************/
1717

18-
#include "qgsepsgcache.h"
18+
#include "qgscrscache.h"
1919

20-
QgsEPSGCache* QgsEPSGCache::mInstance = 0;
20+
QgsCRSCache* QgsCRSCache::mInstance = 0;
2121

22-
QgsEPSGCache* QgsEPSGCache::instance()
22+
QgsCRSCache* QgsCRSCache::instance()
2323
{
2424
if ( !mInstance )
2525
{
26-
mInstance = new QgsEPSGCache();
26+
mInstance = new QgsCRSCache();
2727
}
2828
return mInstance;
2929
}
3030

31-
QgsEPSGCache::QgsEPSGCache()
31+
QgsCRSCache::QgsCRSCache()
3232
{
3333
}
3434

35-
QgsEPSGCache::~QgsEPSGCache()
35+
QgsCRSCache::~QgsCRSCache()
3636
{
3737
delete mInstance;
3838
}
3939

40-
const QgsCoordinateReferenceSystem& QgsEPSGCache::searchCRS( long epsg )
40+
const QgsCoordinateReferenceSystem& QgsCRSCache::crsByAuthId( const QString& authid )
4141
{
42-
QHash< long, QgsCoordinateReferenceSystem >::const_iterator crsIt = mCRS.find( epsg );
42+
QHash< QString, QgsCoordinateReferenceSystem >::const_iterator crsIt = mCRS.find( authid );
4343
if ( crsIt == mCRS.constEnd() )
4444
{
4545
QgsCoordinateReferenceSystem s;
46-
if ( ! s.createFromOgcWmsCrs( QString( "EPSG:%1" ).arg( epsg ) ) )
46+
if ( ! s.createFromOgcWmsCrs( authid ) )
4747
{
4848
return mInvalidCRS;
4949
}
50-
return mCRS.insert( epsg, s ).value();
50+
return mCRS.insert( authid, s ).value();
5151
}
5252
else
5353
{
5454
return crsIt.value();
5555
}
5656
}
5757

58-
58+
const QgsCoordinateReferenceSystem& QgsCRSCache::crsByEpsgId( long epsg )
59+
{
60+
return crsByAuthId( "EPSG:" + QString::number( epsg ) );
61+
}
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/***************************************************************************
2-
qgsepsgcache.h
2+
qgscrscache.h
33
--------------
4-
begin : June 9th, 2010
5-
copyright : (C) 2010 by Marco Hugentobler
4+
begin : September 6th, 2011
5+
copyright : (C) 2011 by Marco Hugentobler
66
email : marco dot hugentobler at sourcepole dot ch
77
***************************************************************************/
88

@@ -15,29 +15,29 @@
1515
* *
1616
***************************************************************************/
1717

18-
#ifndef QGSEPSGCACHE_H
19-
#define QGSEPSGCACHE_H
18+
#ifndef QGSCRSCACHE_H
19+
#define QGSCRSCACHE_H
2020

2121
#include "qgscoordinatereferencesystem.h"
2222
#include <QHash>
2323

24-
/**A class that cashes QgsCoordinateReferenceSystem instances and allows fast searching by epsg numbers*/
25-
class QgsEPSGCache
24+
class QgsCRSCache
2625
{
2726
public:
28-
static QgsEPSGCache* instance();
29-
~QgsEPSGCache();
30-
/**Returns the CRS for an epsg number (or an invalid CRS in case of error)*/
31-
const QgsCoordinateReferenceSystem& searchCRS( long epsg );
27+
static QgsCRSCache* instance();
28+
~QgsCRSCache();
29+
/**Returns the CRS for authid, e.g. 'EPSG:4326' (or an invalid CRS in case of error)*/
30+
const QgsCoordinateReferenceSystem& crsByAuthId( const QString& authid );
31+
const QgsCoordinateReferenceSystem& crsByEpsgId( long epgs );
3232

3333
protected:
34-
QgsEPSGCache();
34+
QgsCRSCache();
3535

3636
private:
37-
static QgsEPSGCache* mInstance;
38-
QHash< long, QgsCoordinateReferenceSystem > mCRS;
39-
/**CRS that is not initialised (is returned in case of error)*/
37+
static QgsCRSCache* mInstance;
38+
QHash< QString, QgsCoordinateReferenceSystem > mCRS;
39+
/**CRS that is not initialised (returned in case of error)*/
4040
QgsCoordinateReferenceSystem mInvalidCRS;
4141
};
4242

43-
#endif // QGSEPSGCACHE_H
43+
#endif // QGSCRSCACHE_H

src/mapserver/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ SET ( qgis_mapserv_SRCS
2020
qgscapabilitiescache.cpp
2121
qgsconfigcache.cpp
2222
qgsconfigparser.cpp
23-
qgsepsgcache.cpp
2423
qgsprojectparser.cpp
2524
qgshttprequesthandler.cpp
2625
qgsgetrequesthandler.cpp

src/mapserver/qgsprojectparser.cpp

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "qgsprojectparser.h"
1919
#include "qgsconfigcache.h"
20-
#include "qgsepsgcache.h"
20+
#include "qgscrscache.h"
2121
#include "qgsmslayercache.h"
2222
#include "qgslogger.h"
2323
#include "qgsmapserviceexception.h"
@@ -1450,20 +1450,10 @@ const QgsCoordinateReferenceSystem& QgsProjectParser::projectCRS() const
14501450
firstChildElement( "spatialrefsys" ).firstChildElement( "authid" );
14511451
if ( !authIdElem.isNull() )
14521452
{
1453-
QString authId = authIdElem.text();
1454-
QStringList authIdSplit = authId.split( ":" );
1455-
if ( authIdSplit.size() == 2 && authIdSplit.at( 0 ).compare( "EPSG", Qt::CaseInsensitive ) == 0 )
1456-
{
1457-
bool ok;
1458-
int id = authIdSplit.at( 1 ).toInt( &ok );
1459-
if ( ok )
1460-
{
1461-
return QgsEPSGCache::instance()->searchCRS( id );
1462-
}
1463-
}
1453+
return QgsCRSCache::instance()->crsByAuthId( authIdElem.text() );
14641454
}
14651455
}
1466-
return QgsEPSGCache::instance()->searchCRS( GEO_EPSG_CRS_ID );
1456+
return QgsCRSCache::instance()->crsByEpsgId( GEO_EPSG_CRS_ID );
14671457
}
14681458

14691459
QgsRectangle QgsProjectParser::layerBoundingBoxInProjectCRS( const QDomElement& layerElem ) const
@@ -1504,22 +1494,13 @@ QgsRectangle QgsProjectParser::layerBoundingBoxInProjectCRS( const QDomElement&
15041494
return BBox;
15051495
}
15061496

1507-
int authId;
1508-
QString authIdString = boundingBoxElem.attribute( "CRS" );
1509-
QStringList authIdSplit = authIdString.split( ":" );
1510-
if ( authIdSplit.size() < 2 )
1511-
{
1512-
return BBox;
1513-
}
1514-
authId = authIdSplit.at( 1 ).toInt( &conversionOk );
1515-
if ( !conversionOk )
1497+
//create layer crs
1498+
const QgsCoordinateReferenceSystem& layerCrs = QgsCRSCache::instance()->crsByAuthId( boundingBoxElem.attribute( "CRS" ) );
1499+
if ( !layerCrs.isValid() )
15161500
{
15171501
return BBox;
15181502
}
15191503

1520-
//create layer crs
1521-
const QgsCoordinateReferenceSystem& layerCrs = QgsEPSGCache::instance()->searchCRS( authId );
1522-
15231504
//get project crs
15241505
const QgsCoordinateReferenceSystem& projectCrs = projectCRS();
15251506
QgsCoordinateTransform t( layerCrs, projectCrs );

src/mapserver/qgswmsserver.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
***************************************************************************/
1717
#include "qgswmsserver.h"
1818
#include "qgsconfigparser.h"
19-
#include "qgsepsgcache.h"
19+
#include "qgscrscache.h"
2020
#include "qgsfield.h"
2121
#include "qgsgeometry.h"
2222
#include "qgsmaplayer.h"
@@ -1043,19 +1043,8 @@ int QgsWMSServer::configureMapRender( const QPaintDevice* paintDevice ) const
10431043
QgsDebugMsg( "enable on the fly projection" );
10441044
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectionsEnabled", 1 );
10451045

1046-
QString crsString = crsIt->second;
1047-
if ( !( crsString.left( 4 ) == "EPSG" ) )
1048-
{
1049-
return 3; // only EPSG ids supported
1050-
}
1051-
long epsgId = crsString.section( ":", 1, 1 ).toLong( &conversionSuccess );
1052-
if ( !conversionSuccess )
1053-
{
1054-
return 4;
1055-
}
1056-
10571046
//destination SRS
1058-
outputCRS = QgsEPSGCache::instance()->searchCRS( epsgId );
1047+
outputCRS = QgsCRSCache::instance()->crsByAuthId( crsIt->second );
10591048
if ( !outputCRS.isValid() )
10601049
{
10611050
QgsDebugMsg( "Error, could not create output CRS from EPSG" );

0 commit comments

Comments
 (0)