mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-14 00:08:51 -05:00
Deprecate methods for constructing CRS from Postgis srids
Constructing CRS using Postgis srids is highly discouraged, and instead CRSes should always be constructed using auth:id codes or WKT strings. QGIS 4.0: The logic should be isolated into the postgres provider alone, and not exposed to stable API
This commit is contained in:
parent
b37dd0984e
commit
c76813c434
@ -349,13 +349,18 @@ and refer to QGIS internal CRS IDs.
|
|||||||
%End
|
%End
|
||||||
|
|
||||||
|
|
||||||
bool createFromSrid( long srid );
|
bool createFromSrid( long srid ) /Deprecated/;
|
||||||
%Docstring
|
%Docstring
|
||||||
Sets this CRS by lookup of the given PostGIS SRID in the CRS database.
|
Sets this CRS by lookup of the given PostGIS SRID in the CRS database.
|
||||||
|
|
||||||
:param srid: The PostGIS SRID for the desired spatial reference system.
|
:param srid: The PostGIS SRID for the desired spatial reference system.
|
||||||
|
|
||||||
:return: ``True`` on success else ``False``
|
:return: ``True`` on success else ``False``
|
||||||
|
|
||||||
|
.. deprecated::
|
||||||
|
Use alternative methods for SRS construction instead -- this
|
||||||
|
method was specifically created for use by the postgres provider alone,
|
||||||
|
and using it elsewhere will lead to subtle bugs.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
bool createFromWkt( const QString &wkt );
|
bool createFromWkt( const QString &wkt );
|
||||||
|
|||||||
@ -252,7 +252,7 @@ bool QgsCoordinateReferenceSystem::createFromId( const long id, CrsType type )
|
|||||||
result = createFromSrsId( id );
|
result = createFromSrsId( id );
|
||||||
break;
|
break;
|
||||||
case PostgisCrsId:
|
case PostgisCrsId:
|
||||||
result = createFromSrid( id );
|
result = createFromPostgisSrid( id );
|
||||||
break;
|
break;
|
||||||
case EpsgCrsId:
|
case EpsgCrsId:
|
||||||
result = createFromOgcWmsCrs( QStringLiteral( "EPSG:%1" ).arg( id ) );
|
result = createFromOgcWmsCrs( QStringLiteral( "EPSG:%1" ).arg( id ) );
|
||||||
@ -292,7 +292,7 @@ bool QgsCoordinateReferenceSystem::createFromString( const QString &definition )
|
|||||||
else if ( authName == QLatin1String( "postgis" ) )
|
else if ( authName == QLatin1String( "postgis" ) )
|
||||||
{
|
{
|
||||||
const long id = match.captured( 2 ).toLong();
|
const long id = match.captured( 2 ).toLong();
|
||||||
result = createFromId( id, PostgisCrsId );
|
result = createFromPostgisSrid( id );
|
||||||
}
|
}
|
||||||
else if ( authName == QLatin1String( "esri" ) || authName == QLatin1String( "osgeo" ) || authName == QLatin1String( "ignf" ) || authName == QLatin1String( "zangi" ) || authName == QLatin1String( "iau2000" ) )
|
else if ( authName == QLatin1String( "esri" ) || authName == QLatin1String( "osgeo" ) || authName == QLatin1String( "ignf" ) || authName == QLatin1String( "zangi" ) || authName == QLatin1String( "iau2000" ) )
|
||||||
{
|
{
|
||||||
@ -498,6 +498,11 @@ void QgsCoordinateReferenceSystem::validate()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool QgsCoordinateReferenceSystem::createFromSrid( const long id )
|
bool QgsCoordinateReferenceSystem::createFromSrid( const long id )
|
||||||
|
{
|
||||||
|
return createFromPostgisSrid( id );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QgsCoordinateReferenceSystem::createFromPostgisSrid( const long id )
|
||||||
{
|
{
|
||||||
QgsReadWriteLocker locker( *sSrIdCacheLock(), QgsReadWriteLocker::Read );
|
QgsReadWriteLocker locker( *sSrIdCacheLock(), QgsReadWriteLocker::Read );
|
||||||
if ( !sDisableSrIdCache )
|
if ( !sDisableSrIdCache )
|
||||||
|
|||||||
@ -208,7 +208,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
|
|||||||
enum CrsType
|
enum CrsType
|
||||||
{
|
{
|
||||||
InternalCrsId, //!< Internal ID used by QGIS in the local SQLite database
|
InternalCrsId, //!< Internal ID used by QGIS in the local SQLite database
|
||||||
PostgisCrsId, //!< SRID used in PostGIS
|
PostgisCrsId, //!< SRID used in PostGIS. DEPRECATED -- DO NOT USE
|
||||||
EpsgCrsId //!< EPSG code
|
EpsgCrsId //!< EPSG code
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -364,8 +364,12 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
|
|||||||
* Sets this CRS by lookup of the given PostGIS SRID in the CRS database.
|
* Sets this CRS by lookup of the given PostGIS SRID in the CRS database.
|
||||||
* \param srid The PostGIS SRID for the desired spatial reference system.
|
* \param srid The PostGIS SRID for the desired spatial reference system.
|
||||||
* \returns TRUE on success else FALSE
|
* \returns TRUE on success else FALSE
|
||||||
|
*
|
||||||
|
* \deprecated Use alternative methods for SRS construction instead -- this
|
||||||
|
* method was specifically created for use by the postgres provider alone,
|
||||||
|
* and using it elsewhere will lead to subtle bugs.
|
||||||
*/
|
*/
|
||||||
bool createFromSrid( long srid );
|
Q_DECL_DEPRECATED bool createFromSrid( long srid ) SIP_DEPRECATED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets this CRS using a WKT definition.
|
* Sets this CRS using a WKT definition.
|
||||||
@ -933,6 +937,9 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
|
|||||||
static const QHash< long, QgsCoordinateReferenceSystem > &srIdCache();
|
static const QHash< long, QgsCoordinateReferenceSystem > &srIdCache();
|
||||||
|
|
||||||
friend class TestQgsCoordinateReferenceSystem;
|
friend class TestQgsCoordinateReferenceSystem;
|
||||||
|
friend class QgsPostgresProvider;
|
||||||
|
|
||||||
|
bool createFromPostgisSrid( const long id );
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE( QgsCoordinateReferenceSystem )
|
Q_DECLARE_METATYPE( QgsCoordinateReferenceSystem )
|
||||||
|
|||||||
@ -548,12 +548,6 @@ QgsCoordinateReferenceSystem QgsDb2Provider::crs() const
|
|||||||
{
|
{
|
||||||
if ( !mCrs.isValid() && mSRId > 0 )
|
if ( !mCrs.isValid() && mSRId > 0 )
|
||||||
{
|
{
|
||||||
mCrs.createFromSrid( mSRId );
|
|
||||||
if ( mCrs.isValid() )
|
|
||||||
{
|
|
||||||
return mCrs;
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to load crs from the database tables as a fallback
|
// try to load crs from the database tables as a fallback
|
||||||
QSqlQuery query = QSqlQuery( mDatabase );
|
QSqlQuery query = QSqlQuery( mDatabase );
|
||||||
query.setForwardOnly( true );
|
query.setForwardOnly( true );
|
||||||
|
|||||||
@ -534,7 +534,7 @@ QString QgsGPXProvider::description() const
|
|||||||
|
|
||||||
QgsCoordinateReferenceSystem QgsGPXProvider::crs() const
|
QgsCoordinateReferenceSystem QgsGPXProvider::crs() const
|
||||||
{
|
{
|
||||||
return QgsCoordinateReferenceSystem( GEOSRID, QgsCoordinateReferenceSystem::PostgisCrsId ); // use WGS84
|
return QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsDataProvider *QgsGpxProviderMetadata::createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options )
|
QgsDataProvider *QgsGpxProviderMetadata::createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options )
|
||||||
|
|||||||
@ -4328,7 +4328,9 @@ QgsCoordinateReferenceSystem QgsPostgresProvider::crs() const
|
|||||||
{
|
{
|
||||||
QgsCoordinateReferenceSystem srs;
|
QgsCoordinateReferenceSystem srs;
|
||||||
int srid = mRequestedSrid.isEmpty() ? mDetectedSrid.toInt() : mRequestedSrid.toInt();
|
int srid = mRequestedSrid.isEmpty() ? mDetectedSrid.toInt() : mRequestedSrid.toInt();
|
||||||
srs.createFromSrid( srid );
|
|
||||||
|
// TODO QGIS 4 - move the logic from createFromSridInternal to sit within the postgres provider alone
|
||||||
|
srs.createFromPostgisSrid( srid );
|
||||||
if ( !srs.isValid() )
|
if ( !srs.isValid() )
|
||||||
{
|
{
|
||||||
static QMutex sMutex;
|
static QMutex sMutex;
|
||||||
|
|||||||
@ -337,7 +337,7 @@ void TestQgsCoordinateReferenceSystem::ogcWmsCrsCache()
|
|||||||
void TestQgsCoordinateReferenceSystem::createFromSrid()
|
void TestQgsCoordinateReferenceSystem::createFromSrid()
|
||||||
{
|
{
|
||||||
QgsCoordinateReferenceSystem myCrs;
|
QgsCoordinateReferenceSystem myCrs;
|
||||||
myCrs.createFromSrid( GEOSRID );
|
myCrs.createFromPostgisSrid( GEOSRID );
|
||||||
debugPrint( myCrs );
|
debugPrint( myCrs );
|
||||||
QVERIFY( myCrs.isValid() );
|
QVERIFY( myCrs.isValid() );
|
||||||
QCOMPARE( myCrs.srsid(), GEOCRS_ID );
|
QCOMPARE( myCrs.srsid(), GEOCRS_ID );
|
||||||
@ -353,24 +353,24 @@ void TestQgsCoordinateReferenceSystem::sridCache()
|
|||||||
{
|
{
|
||||||
// test that crs can be retrieved correctly from cache
|
// test that crs can be retrieved correctly from cache
|
||||||
QgsCoordinateReferenceSystem crs;
|
QgsCoordinateReferenceSystem crs;
|
||||||
crs.createFromSrid( 3112 );
|
crs.createFromPostgisSrid( 3112 );
|
||||||
QVERIFY( crs.isValid() );
|
QVERIFY( crs.isValid() );
|
||||||
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:3112" ) );
|
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:3112" ) );
|
||||||
QVERIFY( QgsCoordinateReferenceSystem::srIdCache().contains( 3112 ) );
|
QVERIFY( QgsCoordinateReferenceSystem::srIdCache().contains( 3112 ) );
|
||||||
// a second time, so crs is fetched from cache
|
// a second time, so crs is fetched from cache
|
||||||
QgsCoordinateReferenceSystem crs2;
|
QgsCoordinateReferenceSystem crs2;
|
||||||
crs2.createFromSrid( 3112 );
|
crs2.createFromPostgisSrid( 3112 );
|
||||||
QVERIFY( crs2.isValid() );
|
QVERIFY( crs2.isValid() );
|
||||||
QCOMPARE( crs2.authid(), QStringLiteral( "EPSG:3112" ) );
|
QCOMPARE( crs2.authid(), QStringLiteral( "EPSG:3112" ) );
|
||||||
|
|
||||||
// invalid
|
// invalid
|
||||||
QgsCoordinateReferenceSystem crs3;
|
QgsCoordinateReferenceSystem crs3;
|
||||||
crs3.createFromSrid( -3141 );
|
crs3.createFromPostgisSrid( -3141 );
|
||||||
QVERIFY( !crs3.isValid() );
|
QVERIFY( !crs3.isValid() );
|
||||||
QVERIFY( QgsCoordinateReferenceSystem::srIdCache().contains( -3141 ) );
|
QVERIFY( QgsCoordinateReferenceSystem::srIdCache().contains( -3141 ) );
|
||||||
// a second time, so invalid crs is fetched from cache
|
// a second time, so invalid crs is fetched from cache
|
||||||
QgsCoordinateReferenceSystem crs4;
|
QgsCoordinateReferenceSystem crs4;
|
||||||
crs4.createFromSrid( -3141 );
|
crs4.createFromPostgisSrid( -3141 );
|
||||||
QVERIFY( !crs4.isValid() );
|
QVERIFY( !crs4.isValid() );
|
||||||
|
|
||||||
QgsCoordinateReferenceSystem::invalidateCache();
|
QgsCoordinateReferenceSystem::invalidateCache();
|
||||||
@ -611,8 +611,7 @@ void TestQgsCoordinateReferenceSystem::createFromESRIWkt()
|
|||||||
void TestQgsCoordinateReferenceSystem::createFromSrId()
|
void TestQgsCoordinateReferenceSystem::createFromSrId()
|
||||||
{
|
{
|
||||||
QgsCoordinateReferenceSystem myCrs;
|
QgsCoordinateReferenceSystem myCrs;
|
||||||
QVERIFY( myCrs.createFromSrid( GEOSRID ) );
|
QVERIFY( myCrs.createFromPostgisSrid( GEOSRID ) );
|
||||||
debugPrint( myCrs );
|
|
||||||
QVERIFY( myCrs.isValid() );
|
QVERIFY( myCrs.isValid() );
|
||||||
QCOMPARE( myCrs.srsid(), GEOCRS_ID );
|
QCOMPARE( myCrs.srsid(), GEOCRS_ID );
|
||||||
}
|
}
|
||||||
@ -778,10 +777,10 @@ void TestQgsCoordinateReferenceSystem::fromStringCache()
|
|||||||
|
|
||||||
void TestQgsCoordinateReferenceSystem::isValid()
|
void TestQgsCoordinateReferenceSystem::isValid()
|
||||||
{
|
{
|
||||||
QgsCoordinateReferenceSystem myCrs;
|
QgsCoordinateReferenceSystem crs( QStringLiteral( "EPSG:4326" ) );
|
||||||
myCrs.createFromSrid( GEOSRID );
|
QVERIFY( crs.isValid() );
|
||||||
QVERIFY( myCrs.isValid() );
|
crs = QgsCoordinateReferenceSystem( QStringLiteral( "xxxxxxxxxxxxxxx" ) );
|
||||||
debugPrint( myCrs );
|
QVERIFY( !crs.isValid() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestQgsCoordinateReferenceSystem::validate()
|
void TestQgsCoordinateReferenceSystem::validate()
|
||||||
@ -815,20 +814,14 @@ void TestQgsCoordinateReferenceSystem::validate()
|
|||||||
|
|
||||||
void TestQgsCoordinateReferenceSystem::equality()
|
void TestQgsCoordinateReferenceSystem::equality()
|
||||||
{
|
{
|
||||||
QgsCoordinateReferenceSystem myCrs;
|
QgsCoordinateReferenceSystem myCrs( QStringLiteral( "EPSG:4326" ) );
|
||||||
myCrs.createFromSrid( GEOSRID );
|
QgsCoordinateReferenceSystem myCrs2( QStringLiteral( "EPSG:4326" ) );
|
||||||
QgsCoordinateReferenceSystem myCrs2;
|
|
||||||
myCrs2.createFromSrsId( GEOCRS_ID );
|
|
||||||
debugPrint( myCrs );
|
|
||||||
QVERIFY( myCrs == myCrs2 );
|
QVERIFY( myCrs == myCrs2 );
|
||||||
}
|
}
|
||||||
void TestQgsCoordinateReferenceSystem::noEquality()
|
void TestQgsCoordinateReferenceSystem::noEquality()
|
||||||
{
|
{
|
||||||
QgsCoordinateReferenceSystem myCrs;
|
QgsCoordinateReferenceSystem myCrs( QStringLiteral( "EPSG:4326" ) );
|
||||||
myCrs.createFromSrid( GEOSRID );
|
QgsCoordinateReferenceSystem myCrs2( QStringLiteral( "EPSG:4327" ) );
|
||||||
QgsCoordinateReferenceSystem myCrs2;
|
|
||||||
myCrs2.createFromSrsId( 4327 );
|
|
||||||
debugPrint( myCrs );
|
|
||||||
QVERIFY( myCrs != myCrs2 );
|
QVERIFY( myCrs != myCrs2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -840,8 +833,7 @@ void TestQgsCoordinateReferenceSystem::equalityInvalid()
|
|||||||
}
|
}
|
||||||
void TestQgsCoordinateReferenceSystem::readWriteXml()
|
void TestQgsCoordinateReferenceSystem::readWriteXml()
|
||||||
{
|
{
|
||||||
QgsCoordinateReferenceSystem myCrs;
|
QgsCoordinateReferenceSystem myCrs( QStringLiteral( "EPSG:4326" ) );
|
||||||
myCrs.createFromSrid( GEOSRID );
|
|
||||||
QVERIFY( myCrs.isValid() );
|
QVERIFY( myCrs.isValid() );
|
||||||
QDomDocument document( QStringLiteral( "test" ) );
|
QDomDocument document( QStringLiteral( "test" ) );
|
||||||
QDomElement node = document.createElement( QStringLiteral( "crs" ) );
|
QDomElement node = document.createElement( QStringLiteral( "crs" ) );
|
||||||
@ -1056,15 +1048,13 @@ void TestQgsCoordinateReferenceSystem::customSrsValidation()
|
|||||||
void TestQgsCoordinateReferenceSystem::postgisSrid()
|
void TestQgsCoordinateReferenceSystem::postgisSrid()
|
||||||
{
|
{
|
||||||
QgsCoordinateReferenceSystem myCrs;
|
QgsCoordinateReferenceSystem myCrs;
|
||||||
myCrs.createFromSrid( GEOSRID );
|
myCrs.createFromPostgisSrid( GEOSRID );
|
||||||
QVERIFY( myCrs.postgisSrid() == GEOSRID );
|
QVERIFY( myCrs.postgisSrid() == GEOSRID );
|
||||||
debugPrint( myCrs );
|
debugPrint( myCrs );
|
||||||
}
|
}
|
||||||
void TestQgsCoordinateReferenceSystem::ellipsoidAcronym()
|
void TestQgsCoordinateReferenceSystem::ellipsoidAcronym()
|
||||||
{
|
{
|
||||||
QgsCoordinateReferenceSystem myCrs;
|
QgsCoordinateReferenceSystem myCrs( QStringLiteral( "EPSG:4326" ) );
|
||||||
myCrs.createFromSrid( GEOSRID );
|
|
||||||
debugPrint( myCrs );
|
|
||||||
#if PROJ_VERSION_MAJOR>=6
|
#if PROJ_VERSION_MAJOR>=6
|
||||||
QCOMPARE( myCrs.ellipsoidAcronym(), QStringLiteral( "EPSG:7030" ) );
|
QCOMPARE( myCrs.ellipsoidAcronym(), QStringLiteral( "EPSG:7030" ) );
|
||||||
#else
|
#else
|
||||||
@ -1081,35 +1071,26 @@ void TestQgsCoordinateReferenceSystem::ellipsoidAcronym()
|
|||||||
}
|
}
|
||||||
void TestQgsCoordinateReferenceSystem::toWkt()
|
void TestQgsCoordinateReferenceSystem::toWkt()
|
||||||
{
|
{
|
||||||
QgsCoordinateReferenceSystem myCrs;
|
QgsCoordinateReferenceSystem myCrs( QStringLiteral( "EPSG:4326" ) );
|
||||||
myCrs.createFromSrid( GEOSRID );
|
|
||||||
QString myWkt = myCrs.toWkt();
|
QString myWkt = myCrs.toWkt();
|
||||||
debugPrint( myCrs );
|
|
||||||
//Note: this is not the same as geoWkt() as OGR strips off the TOWGS clause...
|
|
||||||
QString myStrippedWkt( "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID"
|
QString myStrippedWkt( "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID"
|
||||||
"[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],"
|
"[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],"
|
||||||
"AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY"
|
"AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY"
|
||||||
"[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY"
|
"[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY"
|
||||||
"[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]" );
|
"[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]" );
|
||||||
qDebug() << "wkt: " << myWkt;
|
QCOMPARE( myWkt, myStrippedWkt );
|
||||||
qDebug() << "stripped: " << myStrippedWkt;
|
|
||||||
QVERIFY( myWkt == myStrippedWkt );
|
|
||||||
}
|
}
|
||||||
void TestQgsCoordinateReferenceSystem::toProj()
|
void TestQgsCoordinateReferenceSystem::toProj()
|
||||||
{
|
{
|
||||||
QgsCoordinateReferenceSystem myCrs;
|
QgsCoordinateReferenceSystem myCrs( QStringLiteral( "EPSG:4326" ) );
|
||||||
myCrs.createFromSrid( GEOSRID );
|
|
||||||
debugPrint( myCrs );
|
|
||||||
//first proj string produced by gdal 1.8-1.9
|
//first proj string produced by gdal 1.8-1.9
|
||||||
//second by gdal 1.7
|
//second by gdal 1.7
|
||||||
QCOMPARE( myCrs.toProj(), geoProj4() );
|
QCOMPARE( myCrs.toProj(), geoProj4() );
|
||||||
}
|
}
|
||||||
void TestQgsCoordinateReferenceSystem::isGeographic()
|
void TestQgsCoordinateReferenceSystem::isGeographic()
|
||||||
{
|
{
|
||||||
QgsCoordinateReferenceSystem geographic;
|
QgsCoordinateReferenceSystem geographic( QStringLiteral( "EPSG:4326" ) );
|
||||||
geographic.createFromSrid( GEOSRID );
|
|
||||||
QVERIFY( geographic.isGeographic() );
|
QVERIFY( geographic.isGeographic() );
|
||||||
debugPrint( geographic );
|
|
||||||
|
|
||||||
QgsCoordinateReferenceSystem nonGeographic;
|
QgsCoordinateReferenceSystem nonGeographic;
|
||||||
nonGeographic.createFromId( 3857, QgsCoordinateReferenceSystem::EpsgCrsId );
|
nonGeographic.createFromId( 3857, QgsCoordinateReferenceSystem::EpsgCrsId );
|
||||||
@ -1211,8 +1192,7 @@ void TestQgsCoordinateReferenceSystem::validSrsIds()
|
|||||||
|
|
||||||
void TestQgsCoordinateReferenceSystem::asVariant()
|
void TestQgsCoordinateReferenceSystem::asVariant()
|
||||||
{
|
{
|
||||||
QgsCoordinateReferenceSystem original;
|
QgsCoordinateReferenceSystem original( QStringLiteral( "EPSG:3112" ) );
|
||||||
original.createFromSrid( 3112 );
|
|
||||||
|
|
||||||
//convert to and from a QVariant
|
//convert to and from a QVariant
|
||||||
QVariant var = QVariant::fromValue( original );
|
QVariant var = QVariant::fromValue( original );
|
||||||
|
|||||||
@ -130,10 +130,8 @@ void TestQgsCoordinateTransform::isValid()
|
|||||||
QgsCoordinateTransform tr;
|
QgsCoordinateTransform tr;
|
||||||
QVERIFY( !tr.isValid() );
|
QVERIFY( !tr.isValid() );
|
||||||
|
|
||||||
QgsCoordinateReferenceSystem srs1;
|
QgsCoordinateReferenceSystem srs1( QStringLiteral( "EPSG:3994" ) );
|
||||||
srs1.createFromSrid( 3994 );
|
QgsCoordinateReferenceSystem srs2( QStringLiteral( "EPSG:4326" ) );
|
||||||
QgsCoordinateReferenceSystem srs2;
|
|
||||||
srs2.createFromSrid( 4326 );
|
|
||||||
|
|
||||||
// valid source, invalid destination
|
// valid source, invalid destination
|
||||||
QgsCoordinateTransform tr2( srs1, QgsCoordinateReferenceSystem(), QgsProject::instance() );
|
QgsCoordinateTransform tr2( srs1, QgsCoordinateReferenceSystem(), QgsProject::instance() );
|
||||||
@ -163,10 +161,8 @@ void TestQgsCoordinateTransform::isShortCircuited()
|
|||||||
//invalid transform shortcircuits
|
//invalid transform shortcircuits
|
||||||
QVERIFY( tr.isShortCircuited() );
|
QVERIFY( tr.isShortCircuited() );
|
||||||
|
|
||||||
QgsCoordinateReferenceSystem srs1;
|
QgsCoordinateReferenceSystem srs1( QStringLiteral( "EPSG:3994" ) );
|
||||||
srs1.createFromSrid( 3994 );
|
QgsCoordinateReferenceSystem srs2( QStringLiteral( "EPSG:4326" ) );
|
||||||
QgsCoordinateReferenceSystem srs2;
|
|
||||||
srs2.createFromSrid( 4326 );
|
|
||||||
|
|
||||||
// valid source, invalid destination
|
// valid source, invalid destination
|
||||||
QgsCoordinateTransform tr2( srs1, QgsCoordinateReferenceSystem(), QgsProject::instance() );
|
QgsCoordinateTransform tr2( srs1, QgsCoordinateReferenceSystem(), QgsProject::instance() );
|
||||||
@ -400,10 +396,8 @@ void TestQgsCoordinateTransform::transform()
|
|||||||
void TestQgsCoordinateTransform::transformBoundingBox()
|
void TestQgsCoordinateTransform::transformBoundingBox()
|
||||||
{
|
{
|
||||||
//test transforming a bounding box which crosses the 180 degree longitude line
|
//test transforming a bounding box which crosses the 180 degree longitude line
|
||||||
QgsCoordinateReferenceSystem sourceSrs;
|
QgsCoordinateReferenceSystem sourceSrs( QStringLiteral( "EPSG:3994" ) );
|
||||||
sourceSrs.createFromSrid( 3994 );
|
QgsCoordinateReferenceSystem destSrs( QStringLiteral( "EPSG:4326" ) );
|
||||||
QgsCoordinateReferenceSystem destSrs;
|
|
||||||
destSrs.createFromSrid( 4326 );
|
|
||||||
|
|
||||||
QgsCoordinateTransform tr( sourceSrs, destSrs, QgsProject::instance() );
|
QgsCoordinateTransform tr( sourceSrs, destSrs, QgsProject::instance() );
|
||||||
QgsRectangle crossingRect( 6374985, -3626584, 7021195, -3272435 );
|
QgsRectangle crossingRect( 6374985, -3626584, 7021195, -3272435 );
|
||||||
|
|||||||
@ -837,10 +837,8 @@ void TestQgsGeometry::point()
|
|||||||
QCOMPARE( p15.boundingBox(), QgsRectangle( 21.0, 23.0, 21.0, 23.0 ) );
|
QCOMPARE( p15.boundingBox(), QgsRectangle( 21.0, 23.0, 21.0, 23.0 ) );
|
||||||
|
|
||||||
//CRS transform
|
//CRS transform
|
||||||
QgsCoordinateReferenceSystem sourceSrs;
|
QgsCoordinateReferenceSystem sourceSrs( QStringLiteral( "EPSG:3994" ) );
|
||||||
sourceSrs.createFromSrid( 3994 );
|
QgsCoordinateReferenceSystem destSrs( QStringLiteral( "EPSG:4202" ) ); // want a transform with ellipsoid change
|
||||||
QgsCoordinateReferenceSystem destSrs;
|
|
||||||
destSrs.createFromSrid( 4202 ); // want a transform with ellipsoid change
|
|
||||||
QgsCoordinateTransform tr( sourceSrs, destSrs, QgsProject::instance() );
|
QgsCoordinateTransform tr( sourceSrs, destSrs, QgsProject::instance() );
|
||||||
QgsPoint p16( QgsWkbTypes::PointZM, 6374985, -3626584, 1, 2 );
|
QgsPoint p16( QgsWkbTypes::PointZM, 6374985, -3626584, 1, 2 );
|
||||||
p16.transform( tr, QgsCoordinateTransform::ForwardTransform );
|
p16.transform( tr, QgsCoordinateTransform::ForwardTransform );
|
||||||
@ -1881,10 +1879,8 @@ void TestQgsGeometry::circularString()
|
|||||||
QCOMPARE( points.at( 2 ), QgsPoint( QgsWkbTypes::PointZM, 15, 10, 6, 7 ) );
|
QCOMPARE( points.at( 2 ), QgsPoint( QgsWkbTypes::PointZM, 15, 10, 6, 7 ) );
|
||||||
|
|
||||||
//CRS transform
|
//CRS transform
|
||||||
QgsCoordinateReferenceSystem sourceSrs;
|
QgsCoordinateReferenceSystem sourceSrs( QStringLiteral( "EPSG:3994" ) );
|
||||||
sourceSrs.createFromSrid( 3994 );
|
QgsCoordinateReferenceSystem destSrs( QStringLiteral( "EPSG:4202" ) );// want a transform with ellipsoid change
|
||||||
QgsCoordinateReferenceSystem destSrs;
|
|
||||||
destSrs.createFromSrid( 4202 ); // want a transform with ellipsoid change
|
|
||||||
QgsCoordinateTransform tr( sourceSrs, destSrs, QgsProject::instance() );
|
QgsCoordinateTransform tr( sourceSrs, destSrs, QgsProject::instance() );
|
||||||
|
|
||||||
// 2d CRS transform
|
// 2d CRS transform
|
||||||
@ -3857,10 +3853,8 @@ void TestQgsGeometry::lineString()
|
|||||||
QCOMPARE( points.at( 2 ), QgsPoint( QgsWkbTypes::PointZM, 15, 10, 6, 7 ) );
|
QCOMPARE( points.at( 2 ), QgsPoint( QgsWkbTypes::PointZM, 15, 10, 6, 7 ) );
|
||||||
|
|
||||||
//CRS transform
|
//CRS transform
|
||||||
QgsCoordinateReferenceSystem sourceSrs;
|
QgsCoordinateReferenceSystem sourceSrs( QStringLiteral( "EPSG:3994" ) );
|
||||||
sourceSrs.createFromSrid( 3994 );
|
QgsCoordinateReferenceSystem destSrs( QStringLiteral( "EPSG:4202" ) );// want a transform with ellipsoid change
|
||||||
QgsCoordinateReferenceSystem destSrs;
|
|
||||||
destSrs.createFromSrid( 4202 ); // want a transform with ellipsoid change
|
|
||||||
QgsCoordinateTransform tr( sourceSrs, destSrs, QgsProject::instance() );
|
QgsCoordinateTransform tr( sourceSrs, destSrs, QgsProject::instance() );
|
||||||
|
|
||||||
// 2d CRS transform
|
// 2d CRS transform
|
||||||
@ -5793,10 +5787,8 @@ void TestQgsGeometry::polygon()
|
|||||||
|
|
||||||
//transform
|
//transform
|
||||||
//CRS transform
|
//CRS transform
|
||||||
QgsCoordinateReferenceSystem sourceSrs;
|
QgsCoordinateReferenceSystem sourceSrs( QStringLiteral( "EPSG:3994" ) );
|
||||||
sourceSrs.createFromSrid( 3994 );
|
QgsCoordinateReferenceSystem destSrs( QStringLiteral( "EPSG:4202" ) ); // want a transform with ellipsoid change
|
||||||
QgsCoordinateReferenceSystem destSrs;
|
|
||||||
destSrs.createFromSrid( 4202 ); // want a transform with ellipsoid change
|
|
||||||
QgsCoordinateTransform tr( sourceSrs, destSrs, QgsProject::instance() );
|
QgsCoordinateTransform tr( sourceSrs, destSrs, QgsProject::instance() );
|
||||||
|
|
||||||
// 2d CRS transform
|
// 2d CRS transform
|
||||||
@ -10405,10 +10397,8 @@ void TestQgsGeometry::compoundCurve()
|
|||||||
QCOMPARE( points.at( 3 ), QgsPoint( QgsWkbTypes::PointZM, 25, 10, 6, 7 ) );
|
QCOMPARE( points.at( 3 ), QgsPoint( QgsWkbTypes::PointZM, 25, 10, 6, 7 ) );
|
||||||
|
|
||||||
//CRS transform
|
//CRS transform
|
||||||
QgsCoordinateReferenceSystem sourceSrs;
|
QgsCoordinateReferenceSystem sourceSrs( QStringLiteral( "EPSG:3994" ) );
|
||||||
sourceSrs.createFromSrid( 3994 );
|
QgsCoordinateReferenceSystem destSrs( QStringLiteral( "EPSG:4202" ) ); // want a transform with ellipsoid change
|
||||||
QgsCoordinateReferenceSystem destSrs;
|
|
||||||
destSrs.createFromSrid( 4202 ); // want a transform with ellipsoid change
|
|
||||||
QgsCoordinateTransform tr( sourceSrs, destSrs, QgsProject::instance() );
|
QgsCoordinateTransform tr( sourceSrs, destSrs, QgsProject::instance() );
|
||||||
|
|
||||||
// 2d CRS transform
|
// 2d CRS transform
|
||||||
@ -15379,10 +15369,8 @@ void TestQgsGeometry::geometryCollection()
|
|||||||
|
|
||||||
//transform
|
//transform
|
||||||
//CRS transform
|
//CRS transform
|
||||||
QgsCoordinateReferenceSystem sourceSrs;
|
QgsCoordinateReferenceSystem sourceSrs( QStringLiteral( "EPSG:3994" ) );
|
||||||
sourceSrs.createFromSrid( 3994 );
|
QgsCoordinateReferenceSystem destSrs( QStringLiteral( "EPSG:4202" ) ); // want a transform with ellipsoid change
|
||||||
QgsCoordinateReferenceSystem destSrs;
|
|
||||||
destSrs.createFromSrid( 4202 ); // want a transform with ellipsoid change
|
|
||||||
QgsCoordinateTransform tr( sourceSrs, destSrs, QgsProject::instance() );
|
QgsCoordinateTransform tr( sourceSrs, destSrs, QgsProject::instance() );
|
||||||
|
|
||||||
// 2d CRS transform
|
// 2d CRS transform
|
||||||
|
|||||||
@ -122,9 +122,7 @@ void TestQgsLayoutAtlas::init()
|
|||||||
{
|
{
|
||||||
//create composition with composer map
|
//create composition with composer map
|
||||||
|
|
||||||
// select epsg:2154
|
QgsCoordinateReferenceSystem crs( QStringLiteral( "EPSG:2154" ) );
|
||||||
QgsCoordinateReferenceSystem crs;
|
|
||||||
crs.createFromSrid( 2154 );
|
|
||||||
QgsProject::instance()->setCrs( crs );
|
QgsProject::instance()->setCrs( crs );
|
||||||
mLayout = new QgsPrintLayout( QgsProject::instance() );
|
mLayout = new QgsPrintLayout( QgsProject::instance() );
|
||||||
mLayout->initializeDefaults();
|
mLayout->initializeDefaults();
|
||||||
|
|||||||
@ -1203,10 +1203,8 @@ void TestQgsLayoutMapGrid::annotationFormats()
|
|||||||
l.addLayoutItem( map );
|
l.addLayoutItem( map );
|
||||||
|
|
||||||
//create grids in geographic and projected coordinates
|
//create grids in geographic and projected coordinates
|
||||||
QgsCoordinateReferenceSystem projectedCrs;
|
QgsCoordinateReferenceSystem projectedCrs( QStringLiteral( "EPSG:3994" ) );
|
||||||
projectedCrs.createFromSrid( 3994 );
|
QgsCoordinateReferenceSystem geographicCrs( QStringLiteral( "EPSG:4326" ) );
|
||||||
QgsCoordinateReferenceSystem geographicCrs;
|
|
||||||
geographicCrs.createFromSrid( 4326 );
|
|
||||||
|
|
||||||
QgsLayoutItemMapGrid gridGeographic( QStringLiteral( "geographic grid" ), map );
|
QgsLayoutItemMapGrid gridGeographic( QStringLiteral( "geographic grid" ), map );
|
||||||
gridGeographic.setCrs( geographicCrs );
|
gridGeographic.setCrs( geographicCrs );
|
||||||
|
|||||||
@ -787,9 +787,8 @@ if __name__ == '__main__':
|
|||||||
# local_srv.open_temp_dir()
|
# local_srv.open_temp_dir()
|
||||||
# sys.exit()
|
# sys.exit()
|
||||||
# creating crs needs app instance to access /resources/srs.db
|
# creating crs needs app instance to access /resources/srs.db
|
||||||
# crs = QgsCoordinateReferenceSystem()
|
# crs = QgsCoordinateReferenceSystem('EPSG:32613')
|
||||||
# default for labeling test data sources: WGS 84 / UTM zone 13N
|
# default for labeling test data sources: WGS 84 / UTM zone 13N
|
||||||
# crs.createFromSrid(32613)
|
|
||||||
req_params = {
|
req_params = {
|
||||||
'SERVICE': 'WMS',
|
'SERVICE': 'WMS',
|
||||||
'VERSION': '1.3.0',
|
'VERSION': '1.3.0',
|
||||||
|
|||||||
@ -87,8 +87,7 @@ class TestQgsLayoutAtlas(unittest.TestCase):
|
|||||||
# create layout with layout map
|
# create layout with layout map
|
||||||
|
|
||||||
# select epsg:2154
|
# select epsg:2154
|
||||||
crs = QgsCoordinateReferenceSystem()
|
crs = QgsCoordinateReferenceSystem('epsg:2154')
|
||||||
crs.createFromSrid(2154)
|
|
||||||
QgsProject.instance().setCrs(crs)
|
QgsProject.instance().setCrs(crs)
|
||||||
|
|
||||||
self.layout = QgsPrintLayout(QgsProject.instance())
|
self.layout = QgsPrintLayout(QgsProject.instance())
|
||||||
|
|||||||
@ -890,8 +890,7 @@ class TestQgsLayoutExporter(unittest.TestCase):
|
|||||||
project = QgsProject()
|
project = QgsProject()
|
||||||
project.addMapLayers([layer])
|
project.addMapLayers([layer])
|
||||||
# select epsg:2154
|
# select epsg:2154
|
||||||
crs = QgsCoordinateReferenceSystem()
|
crs = QgsCoordinateReferenceSystem('epsg:2154')
|
||||||
crs.createFromSrid(2154)
|
|
||||||
project.setCrs(crs)
|
project.setCrs(crs)
|
||||||
|
|
||||||
layout = QgsPrintLayout(project)
|
layout = QgsPrintLayout(project)
|
||||||
|
|||||||
@ -186,10 +186,8 @@ class TestQgsPalLabeling(unittest.TestCase):
|
|||||||
:rtype: QgsMapSettings
|
:rtype: QgsMapSettings
|
||||||
"""
|
"""
|
||||||
ms = QgsMapSettings()
|
ms = QgsMapSettings()
|
||||||
crs = QgsCoordinateReferenceSystem()
|
|
||||||
""":type: QgsCoordinateReferenceSystem"""
|
|
||||||
# default for labeling test data: WGS 84 / UTM zone 13N
|
# default for labeling test data: WGS 84 / UTM zone 13N
|
||||||
crs.createFromSrid(32613)
|
crs = QgsCoordinateReferenceSystem('epsg:32613')
|
||||||
ms.setBackgroundColor(QColor(152, 219, 249))
|
ms.setBackgroundColor(QColor(152, 219, 249))
|
||||||
ms.setOutputSize(QSize(420, 280))
|
ms.setOutputSize(QSize(420, 280))
|
||||||
ms.setOutputDpi(72)
|
ms.setOutputDpi(72)
|
||||||
|
|||||||
@ -56,9 +56,7 @@ class TestQgsProjectBadLayers(unittest.TestCase):
|
|||||||
:rtype: QgsMapSettings
|
:rtype: QgsMapSettings
|
||||||
"""
|
"""
|
||||||
ms = QgsMapSettings()
|
ms = QgsMapSettings()
|
||||||
crs = QgsCoordinateReferenceSystem()
|
crs = QgsCoordinateReferenceSystem('epsg:4326')
|
||||||
""":type: QgsCoordinateReferenceSystem"""
|
|
||||||
crs.createFromSrid(4326)
|
|
||||||
ms.setBackgroundColor(QColor(152, 219, 249))
|
ms.setBackgroundColor(QColor(152, 219, 249))
|
||||||
ms.setOutputSize(QSize(420, 280))
|
ms.setOutputSize(QSize(420, 280))
|
||||||
ms.setOutputDpi(72)
|
ms.setOutputDpi(72)
|
||||||
|
|||||||
@ -99,8 +99,7 @@ class TestSelectiveMasking(unittest.TestCase):
|
|||||||
self.report = "<h1>Python Selective Masking Tests</h1>\n"
|
self.report = "<h1>Python Selective Masking Tests</h1>\n"
|
||||||
|
|
||||||
self.map_settings = QgsMapSettings()
|
self.map_settings = QgsMapSettings()
|
||||||
crs = QgsCoordinateReferenceSystem()
|
crs = QgsCoordinateReferenceSystem('epsg:4326')
|
||||||
crs.createFromSrid(4326)
|
|
||||||
extent = QgsRectangle(-123.0, 22.7, -76.4, 46.9)
|
extent = QgsRectangle(-123.0, 22.7, -76.4, 46.9)
|
||||||
self.map_settings.setBackgroundColor(QColor(152, 219, 249))
|
self.map_settings.setBackgroundColor(QColor(152, 219, 249))
|
||||||
self.map_settings.setOutputSize(QSize(420, 280))
|
self.map_settings.setOutputSize(QSize(420, 280))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user