Skip to content
Permalink
Browse files

Deprecate most methods which construct CRSes from internal CRS ids

These should NOT be used, and auth:code or WKT definitions used instead.

Unfortunately some use of these methods are very heavily entangled around
other code, so we can't deprecate all of them until 4.0
  • Loading branch information
nyalldawson committed Dec 18, 2019
1 parent c76813c commit cbc1ee56cc33e1dd26400d2e9834651f26ae09b2
@@ -202,7 +202,7 @@ If no prefix is specified, WKT definition is assumed.
%End


explicit QgsCoordinateReferenceSystem( long id, CrsType type = PostgisCrsId );
explicit QgsCoordinateReferenceSystem( long id, CrsType type = PostgisCrsId ) /Deprecated/;
%Docstring
Constructor a CRS object using a PostGIS SRID, an EPSG code or an internal QGIS CRS ID.

@@ -214,6 +214,11 @@ Constructor a CRS object using a PostGIS SRID, an EPSG code or an internal QGIS

:param id: The ID valid for the chosen CRS ID type
:param type: One of the types described in CrsType

.. deprecated::
We encourage you to use EPSG codes or WKT to describe CRSes in your code
wherever possible. Internal QGIS CRS IDs are not guaranteed to be permanent / involatile,
and Proj strings are a lossy format.
%End

QgsCoordinateReferenceSystem( const QgsCoordinateReferenceSystem &srs );
@@ -317,17 +322,16 @@ Creates a CRS from a specified QGIS SRS ID.



bool createFromId( long id, CrsType type = PostgisCrsId );
bool createFromId( long id, CrsType type = PostgisCrsId ) /Deprecated/;
%Docstring
Sets this CRS by lookup of the given ID in the CRS database.

:return: ``True`` on success else ``False``

.. note::

.. deprecated::
We encourage you to use EPSG code or WKT to describe CRSes in your code
wherever possible. Internal QGIS CRS IDs are not guaranteed to be permanent / involatile,
and Proj strings are a lossy format.
wherever possible. Internal QGIS CRS IDs are not guaranteed to be permanent / involatile,
and Proj strings are a lossy format.
%End


@@ -401,6 +405,11 @@ user's local CRS database from home directory is used.
this method uses an internal cache. Call invalidateCache() to clear the cache.

.. seealso:: :py:func:`fromSrsId`

.. warning::

This method is highly discouraged, and CRS objects should instead be constructed
using auth:id codes or WKT strings
%End

bool createFromProj4( const QString &projString ) /Deprecated/;
@@ -517,7 +526,7 @@ For more details on supported formats see OGRSpatialReference.SetFromUserInput()
/ // TODO QGIS3: rename to createFromStringOGR so it is clear it's similar to createFromString, just different backend
%End

static void setupESRIWktFix();
static void setupESRIWktFix() /Deprecated/;
%Docstring
Make sure that ESRI WKT import is done properly.
This is required for proper shapefile CRS import when using gdal>= 1.9.
@@ -532,6 +541,9 @@ This is required for proper shapefile CRS import when using gdal>= 1.9.
This function sets CPL config option GDAL_FIX_ESRI_WKT to a proper value,
unless it has been set by the user through the commandline or an environment variable.
For more details refer to OGRSpatialReference.morphFromESRI() .

.. deprecated::
Not used on builds based on Proj version 6 or later
%End

bool isValid() const;
@@ -270,7 +270,7 @@ QVariantMap QgsImportPhotosAlgorithm::processAlgorithm( const QVariantMap &param
outFields.append( QgsField( QStringLiteral( "timestamp" ), QVariant::DateTime ) );
QString outputDest;
std::unique_ptr< QgsFeatureSink > outputSink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, outputDest, outFields,
QgsWkbTypes::PointZ, QgsCoordinateReferenceSystem( 4326 ) ) );
QgsWkbTypes::PointZ, QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ) ) );

QgsFields invalidFields;
invalidFields.append( QgsField( QStringLiteral( "photo" ), QVariant::String ) );
@@ -253,15 +253,7 @@ QString QgsMemoryProvider::dataSourceUri( bool expandAuthConfig ) const
}
else
{
int srid = mCrs.postgisSrid();
if ( srid )
{
crsDef = QStringLiteral( "postgis:%1" ).arg( srid );
}
else
{
crsDef = QStringLiteral( "wkt:%1" ).arg( mCrs.toWkt() );
}
crsDef = QStringLiteral( "wkt:%1" ).arg( mCrs.toWkt() );
}
uri.addQueryItem( QStringLiteral( "crs" ), crsDef );
}
@@ -3696,7 +3696,11 @@ QgsCoordinateReferenceSystem QgsOgrProvider::crs() const
}

// add towgs84 parameter
#if PROJ_VERSION_MAJOR<6
Q_NOWARN_DEPRECATED_PUSH
QgsCoordinateReferenceSystem::setupESRIWktFix();
Q_NOWARN_DEPRECATED_POP
#endif

if ( OGRSpatialReferenceH spatialRefSys = mOgrLayer->GetSpatialRef() )
{
@@ -122,7 +122,9 @@ QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem( const QString &defin
QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem( const long id, CrsType type )
{
d = new QgsCoordinateReferenceSystemPrivate();
Q_NOWARN_DEPRECATED_PUSH
createFromId( id, type );
Q_NOWARN_DEPRECATED_POP
}

QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem( const QgsCoordinateReferenceSystem &srs ) //NOLINT
@@ -301,7 +303,9 @@ bool QgsCoordinateReferenceSystem::createFromString( const QString &definition )
else
{
const long id = match.captured( 2 ).toLong();
Q_NOWARN_DEPRECATED_PUSH
result = createFromId( id, InternalCrsId );
Q_NOWARN_DEPRECATED_POP
}
}
else
@@ -339,11 +343,15 @@ bool QgsCoordinateReferenceSystem::createFromUserInput( const QString &definitio
QString userWkt;
OGRSpatialReferenceH crs = OSRNewSpatialReference( nullptr );

#if PROJ_VERSION_MAJOR<6
// make sure towgs84 parameter is loaded if using an ESRI definition and gdal >= 1.9
if ( definition.startsWith( QLatin1String( "ESRI::" ) ) )
{
Q_NOWARN_DEPRECATED_PUSH
setupESRIWktFix();
Q_NOWARN_DEPRECATED_POP
}
#endif

if ( OSRSetFromUserInput( crs, definition.toLocal8Bit().constData() ) == OGRERR_NONE )
{
@@ -251,8 +251,11 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* and proj strings are a lossy format.
* \param id The ID valid for the chosen CRS ID type
* \param type One of the types described in CrsType
* \deprecated We encourage you to use EPSG codes or WKT to describe CRSes in your code
* wherever possible. Internal QGIS CRS IDs are not guaranteed to be permanent / involatile,
* and Proj strings are a lossy format.
*/
explicit QgsCoordinateReferenceSystem( long id, CrsType type = PostgisCrsId );
Q_DECL_DEPRECATED explicit QgsCoordinateReferenceSystem( long id, CrsType type = PostgisCrsId ) SIP_DEPRECATED;

//! Copy constructor
QgsCoordinateReferenceSystem( const QgsCoordinateReferenceSystem &srs );
@@ -338,11 +341,11 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
/**
* Sets this CRS by lookup of the given ID in the CRS database.
* \returns TRUE on success else FALSE
* \note We encourage you to use EPSG code or WKT to describe CRSes in your code
* \deprecated We encourage you to use EPSG code or WKT to describe CRSes in your code
* wherever possible. Internal QGIS CRS IDs are not guaranteed to be permanent / involatile,
* and Proj strings are a lossy format.
*/
bool createFromId( long id, CrsType type = PostgisCrsId );
Q_DECL_DEPRECATED bool createFromId( long id, CrsType type = PostgisCrsId ) SIP_DEPRECATED;

// TODO QGIS 4: remove "QGIS" and "CUSTOM", only support "USER" (also returned by authid())

@@ -394,6 +397,8 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* \returns TRUE on success else FALSE
* \note this method uses an internal cache. Call invalidateCache() to clear the cache.
* \see fromSrsId()
* \warning This method is highly discouraged, and CRS objects should instead be constructed
* using auth:id codes or WKT strings
*/
bool createFromSrsId( long srsId );

@@ -492,8 +497,9 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* \note This function sets CPL config option GDAL_FIX_ESRI_WKT to a proper value,
* unless it has been set by the user through the commandline or an environment variable.
* For more details refer to OGRSpatialReference::morphFromESRI() .
* \deprecated Not used on builds based on Proj version 6 or later
*/
static void setupESRIWktFix();
Q_DECL_DEPRECATED static void setupESRIWktFix() SIP_DEPRECATED;

//! Returns whether this CRS is correctly initialized and usable
bool isValid() const;
@@ -81,7 +81,7 @@ QString QgsCoordinateUtils::formatCoordinateForProject( QgsProject *project, con
if ( destCrs.isValid() && !destCrs.isGeographic() )
{
// need to transform to geographic coordinates
QgsCoordinateTransform ct( destCrs, QgsCoordinateReferenceSystem( GEOSRID ), project );
QgsCoordinateTransform ct( destCrs, QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ), project );
try
{
geo = ct.transform( point );
@@ -48,7 +48,7 @@ QgsDistanceArea::QgsDistanceArea()
mSemiMinor = -1.0;
mInvFlattening = -1.0;
QgsCoordinateTransformContext context; // this is ok - by default we have a source/dest of WGS84, so no reprojection takes place
setSourceCrs( QgsCoordinateReferenceSystem::fromSrsId( GEOCRS_ID ), context ); // WGS 84
setSourceCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ), context ); // WGS 84
setEllipsoid( geoNone() );
}

@@ -40,7 +40,7 @@ QgsJsonExporter::QgsJsonExporter( QgsVectorLayer *vectorLayer, int precision )
mCrs = vectorLayer->crs();
mTransform.setSourceCrs( mCrs );
}
mTransform.setDestinationCrs( QgsCoordinateReferenceSystem( 4326, QgsCoordinateReferenceSystem::EpsgCrsId ) );
mTransform.setDestinationCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ) );
}

void QgsJsonExporter::setVectorLayer( QgsVectorLayer *vectorLayer )
@@ -74,7 +74,7 @@ CoordinateCapture::CoordinateCapture( QgisInterface *qgisInterface )
*/
void CoordinateCapture::initGui()
{
mCrs.createFromSrsId( GEOCRS_ID ); // initialize the CRS object
mCrs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ); // initialize the CRS object

connect( mQGisIface->mapCanvas(), &QgsMapCanvas::destinationCrsChanged, this, &CoordinateCapture::setSourceCrs );
connect( mQGisIface, &QgisInterface::currentThemeChanged, this, &CoordinateCapture::setCurrentTheme );
@@ -122,7 +122,7 @@ namespace QgsWfs
QgsCoordinateReferenceSystem requestCrs;
int requestPrecision = 6;
if ( !onlyOneLayer )
requestCrs = QgsCoordinateReferenceSystem( 4326, QgsCoordinateReferenceSystem::EpsgCrsId );
requestCrs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );

QList<getFeatureQuery>::iterator qIt = aRequest.queries.begin();
for ( ; qIt != aRequest.queries.end(); ++qIt )
@@ -1091,7 +1091,7 @@ namespace QgsWfs
QgsGeometry exportGeom = QgsGeometry::fromRect( *rect );
QgsCoordinateTransform transform;
transform.setSourceCrs( crs );
transform.setDestinationCrs( QgsCoordinateReferenceSystem( 4326, QgsCoordinateReferenceSystem::EpsgCrsId ) );
transform.setDestinationCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ) );
try
{
if ( exportGeom.transform( transform ) == 0 )
@@ -447,8 +447,7 @@ void TestQgsRasterCalculator::calcWithLayers()
QVector<QgsRasterCalculatorEntry> entries;
entries << entry1 << entry2;

QgsCoordinateReferenceSystem crs;
crs.createFromId( 32633, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem crs( QStringLiteral( "EPSG:323633" ) );
QgsRectangle extent( 783235, 3348110, 783350, 3347960 );

QTemporaryFile tmpFile;
@@ -515,8 +514,7 @@ void TestQgsRasterCalculator::calcWithReprojectedLayers()
QVector<QgsRasterCalculatorEntry> entries;
entries << entry1 << entry2;

QgsCoordinateReferenceSystem crs;
crs.createFromId( 32633, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem crs( QStringLiteral( "EPSG:323633" ) );
QgsRectangle extent( 783235, 3348110, 783350, 3347960 );

QTemporaryFile tmpFile;
@@ -637,8 +635,7 @@ void TestQgsRasterCalculator::errors( )
QVector<QgsRasterCalculatorEntry> entries;
entries << entry1;

QgsCoordinateReferenceSystem crs;
crs.createFromId( 32633, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem crs( QStringLiteral( "EPSG:323633" ) );
QgsRectangle extent( 783235, 3348110, 783350, 3347960 );

QTemporaryFile tmpFile;
@@ -763,8 +760,7 @@ void TestQgsRasterCalculator::calcFormulasWithReprojectedLayers()
QVector<QgsRasterCalculatorEntry> entries;
entries << entry1 << entry2;

QgsCoordinateReferenceSystem crs;
crs.createFromId( 32633, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem crs( QStringLiteral( "EPSG:323633" ) );
QgsRectangle extent( 783235, 3348110, 783350, 3347960 );


@@ -399,8 +399,7 @@ void TestQgisAppClipboard::clipboardLogic()
feats.addFeature( feat );
feats.addFeature( feat2 );
feats.setFields( fields );
QgsCoordinateReferenceSystem crs;
crs.createFromSrsId( 3452 );
QgsCoordinateReferenceSystem crs( QStringLiteral( "EPSG:4326" ) );
feats.setCrs( crs );
mQgisApp->clipboard()->replaceWithCopyOf( feats );

@@ -331,7 +331,7 @@ void TestQgsAttributeTable::testRegression15974()
QString path = QDir::tempPath() + "/testshp15974.shp";
std::unique_ptr< QgsVectorLayer> tempLayer( new QgsVectorLayer( QStringLiteral( "polygon?crs=epsg:4326&field=id:integer" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) ) );
QVERIFY( tempLayer->isValid() );
QgsVectorFileWriter::writeAsVectorFormat( tempLayer.get(), path, QStringLiteral( "system" ), QgsCoordinateReferenceSystem( 4326 ), QStringLiteral( "ESRI Shapefile" ) );
QgsVectorFileWriter::writeAsVectorFormat( tempLayer.get(), path, QStringLiteral( "system" ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ), QStringLiteral( "ESRI Shapefile" ) );
std::unique_ptr< QgsVectorLayer> shpLayer( new QgsVectorLayer( path, QStringLiteral( "test" ), QStringLiteral( "ogr" ) ) );
QgsFeature f1( shpLayer->dataProvider()->fields(), 1 );
QgsGeometry geom;
@@ -200,7 +200,7 @@ void TestQgsCoordinateReferenceSystem::copyCtor()
QCOMPARE( myCrs2.authid(), QStringLiteral( "EPSG:4326" ) );

//test implicit sharing detachment - modify original
myCrs.createFromId( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
myCrs.createFromString( QStringLiteral( "EPSG:3111" ) ) );
QVERIFY( myCrs.isValid() );
QCOMPARE( myCrs.authid(), QStringLiteral( "EPSG:3111" ) );
QVERIFY( myCrs2.isValid() );
@@ -217,7 +217,7 @@ void TestQgsCoordinateReferenceSystem::assignmentCtor()
QCOMPARE( myCrs2.authid(), QStringLiteral( "EPSG:4326" ) );

//test implicit sharing detachment - modify original
myCrs.createFromId( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
myCrs.createFromString( QStringLiteral( "EPSG:3111" ) );
QVERIFY( myCrs.isValid() );
QCOMPARE( myCrs.authid(), QStringLiteral( "EPSG:3111" ) );
QVERIFY( myCrs2.isValid() );
@@ -1092,8 +1092,7 @@ void TestQgsCoordinateReferenceSystem::isGeographic()
QgsCoordinateReferenceSystem geographic( QStringLiteral( "EPSG:4326" ) );
QVERIFY( geographic.isGeographic() );

QgsCoordinateReferenceSystem nonGeographic;
nonGeographic.createFromId( 3857, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateReferenceSystem nonGeographic( QStringLiteral( "EPSG:3857" ) );
QVERIFY( !nonGeographic.isGeographic() );
}
void TestQgsCoordinateReferenceSystem::mapUnits()

0 comments on commit cbc1ee5

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