Rip off a band aid, and deprecate all "proj4" calls from the API

Alias these across to new "proj" methods, which don't include the
version number.
This commit is contained in:
Nyall Dawson 2019-12-18 10:29:40 +10:00
parent 6654870c0b
commit b37dd0984e
36 changed files with 506 additions and 341 deletions

View File

@ -34,12 +34,12 @@ latitude/longitude in degrees. The most common one is World Geodetic System 84 (
typically using meters or feet as units. Common projected coordinate systems are Universal
Transverse Mercator or Albers Equal Area.
Internally QGIS uses proj4 library for all the math behind coordinate transformations, so in case
Internally QGIS uses proj library for all the math behind coordinate transformations, so in case
of any troubles with projections it is best to examine the PROJ representation within the object,
as that is the representation that will be ultimately used.
Methods that allow inspection of CRS instances include isValid(), authid(), description(),
toWkt(), toProj4(), mapUnits() and others.
toWkt(), toProj(), mapUnits() and others.
Creation of CRS instances is further described in \ref crs_construct_and_copy section below.
Transformations between coordinate reference systems are done using QgsCoordinateTransform class.
@ -50,7 +50,7 @@ For example, the following code will create and inspect "British national grid"
crs = QgsCoordinateReferenceSystem("EPSG:27700")
if crs.isValid():
print("CRS Description: {}".format(crs.description()))
print("CRS PROJ text: {}".format(crs.toProj4()))
print("CRS PROJ text: {}".format(crs.toProj()))
else:
print("Invalid CRS!")
@ -83,11 +83,11 @@ See authid() and createFromOgcWmsCrs() methods.
2. **PROJ string.** This is a string consisting of a series of key/value pairs in the following
format: `+param1=value1 +param2=value2 [...]`. This is the format natively used by the
underlying proj4 library. For example, the definition of WGS84 looks like this:
underlying proj library. For example, the definition of WGS84 looks like this:
+proj=longlat +datum=WGS84 +no_defs
See toProj4() and createFromProj4() methods.
See toProj() and createFromProj() methods.
3. **Well-known text (WKT).** Defined by Open Geospatial Consortium (OGC), this is another common
format to define CRS. For WGS84 the OGC WKT definition is the following:
@ -169,6 +169,12 @@ both flavors.
EpsgCrsId
};
enum Format
{
FormatWkt,
FormatProj,
};
QgsCoordinateReferenceSystem();
%Docstring
Constructs an invalid CRS object
@ -185,7 +191,7 @@ It supports the following formats:
- "EPSG:<code>" - handled with createFromOgcWms()
- "POSTGIS:<srid>" - handled with createFromSrid()
- "INTERNAL:<srsid>" - handled with createFromSrsId()
- "PROJ4:<proj4>" - handled with createFromProj4()
- "PROJ4:<proj4>" - handled with createFromProj()
- "WKT:<wkt>" - handled with createFromWkt()
If no prefix is specified, WKT definition is assumed.
@ -202,8 +208,9 @@ Constructor a CRS object using a PostGIS SRID, an EPSG code or an internal QGIS
.. note::
We encourage you to use EPSG code, WKT or Proj4 to describe CRS's in your code
wherever possible. Internal QGIS CRS IDs are not guaranteed to be permanent / involatile.
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.
:param id: The ID valid for the chosen CRS ID type
:param type: One of the types described in CrsType
@ -253,17 +260,31 @@ Creates a CRS from a given EPSG ID.
.. versionadded:: 3.0
%End
static QgsCoordinateReferenceSystem fromProj4( const QString &proj4 );
static QgsCoordinateReferenceSystem fromProj4( const QString &proj4 ) /Deprecated/;
%Docstring
Creates a CRS from a proj4 style formatted string.
Creates a CRS from a proj style formatted string.
:param proj4: proj4 format string
:param proj: proj format string
:return: matching CRS, or an invalid CRS if string could not be matched
.. seealso:: :py:func:`createFromProj4`
.. seealso:: :py:func:`createFromProj`
.. versionadded:: 3.0
.. deprecated::
Use fromProj() instead.
%End
static QgsCoordinateReferenceSystem fromProj( const QString &proj );
%Docstring
Creates a CRS from a proj style formatted string.
:param proj: proj format string
:return: matching CRS, or an invalid CRS if string could not be matched
.. seealso:: :py:func:`createFromProj`
.. versionadded:: 3.10.3
%End
static QgsCoordinateReferenceSystem fromWkt( const QString &wkt );
@ -304,8 +325,9 @@ Sets this CRS by lookup of the given ID in the CRS database.
.. note::
We encourage you to use EPSG code, WKT or Proj4 to describe CRS's in your code
wherever possible. Internal QGIS CRS IDs are not guaranteed to be permanent / involatile.
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.
%End
@ -342,8 +364,6 @@ Sets this CRS using a WKT definition.
If EPSG code of the WKT definition can be determined, it is extracted
and createFromOgcWmsCrs() is used to initialize the object.
Otherwise the WKT will be converted to a proj4 string and createFromProj4()
set up the object.
:param wkt: The WKT for the desired spatial reference system.
@ -378,25 +398,26 @@ user's local CRS database from home directory is used.
.. seealso:: :py:func:`fromSrsId`
%End
bool createFromProj4( const QString &projString );
bool createFromProj4( const QString &projString ) /Deprecated/;
%Docstring
Sets this CRS by passing it a PROJ style formatted string.
The string will be parsed and the projection and ellipsoid
members set and the remainder of the proj4 string will be stored
members set and the remainder of the Proj string will be stored
in the parameters member. The reason for this is so that we
can easily present the user with 'natural language' representation
of the projection and ellipsoid by looking them up in the srs.db sqlite
database.
We try to match the proj4 string to internal QGIS CRS ID using the following logic:
We try to match the Proj string to internal QGIS CRS ID using the following logic:
- perform a whole text search on proj4 string (if not null)
- if not match is found, split proj4 into individual parameters and try to find
a match where the parameters are in a different order
- if none of the above match, use findMatchingProj()
- ask the Proj library to identify the CRS to a standard registered CRS (e.g. EPSG codes)
- if no match is found, compare the CRS to all user CRSes, using the Proj library
to determine CRS equivalence (hence making the match parameter order insensitive)
- if none of the above match, use the Proj string to create the CRS and do not
associated an internal CRS ID to it.
:param projString: A proj4 format string
:param projString: A Proj format string
:return: ``True`` on success else ``False``
@ -408,7 +429,46 @@ a match where the parameters are in a different order
this method uses an internal cache. Call invalidateCache() to clear the cache.
.. seealso:: :py:func:`fromProj4`
.. seealso:: :py:func:`fromProj`
.. deprecated::
Use createFromProj() instead
%End
bool createFromProj( const QString &projString );
%Docstring
Sets this CRS by passing it a PROJ style formatted string.
The string will be parsed and the projection and ellipsoid
members set and the remainder of the Proj string will be stored
in the parameters member. The reason for this is so that we
can easily present the user with 'natural language' representation
of the projection and ellipsoid by looking them up in the srs.db sqlite
database.
We try to match the Proj string to internal QGIS CRS ID using the following logic:
- ask the Proj library to identify the CRS to a standard registered CRS (e.g. EPSG codes)
- if no match is found, compare the CRS to all user CRSes, using the Proj library
to determine CRS equivalence (hence making the match parameter order insensitive)
- if none of the above match, use the Proj string to create the CRS and do not
associated an internal CRS ID to it.
:param projString: A Proj format string
:return: ``True`` on success else ``False``
.. note::
Some members may be left blank if no match can be found in CRS database.
.. note::
this method uses an internal cache. Call invalidateCache() to clear the cache.
.. seealso:: :py:func:`fromProj`
.. versionadded:: 3.10.3
%End
bool createFromString( const QString &definition );
@ -419,7 +479,7 @@ It supports the following formats:
- "EPSG:<code>" - handled with createFromOgcWms()
- "POSTGIS:<srid>" - handled with createFromSrid()
- "INTERNAL:<srsid>" - handled with createFromSrsId()
- "PROJ4:<proj4>" - handled with createFromProj4()
- "PROJ4:<proj4>" - handled with createFromProj()
- "WKT:<wkt>" - handled with createFromWkt()
If no prefix is specified, WKT definition is assumed.
@ -491,7 +551,7 @@ if that involves resorting to a hard coded default of geocs:wgs84.
%End
long findMatchingProj();
long findMatchingProj() /Deprecated/;
%Docstring
Walks the CRS databases (both system and user database) trying to match
stored PROJ string to a database entry in order to fill in further
@ -499,9 +559,12 @@ pieces of information about CRS.
.. note::
The ellipsoid and projection acronyms must be set as well as the proj4string!
The ellipsoid and projection acronyms must be set as well as the proj string!
:return: long the SrsId of the matched CRS, zero if no match was found
.. deprecated::
Not used in Proj >= 6 based builds
%End
bool operator==( const QgsCoordinateReferenceSystem &srs ) const;
@ -582,7 +645,7 @@ user.
%Docstring
Returns the projection acronym for the projection used by the CRS.
:return: the official proj4 acronym for the projection family
:return: the official Proj acronym for the projection family
.. note::
@ -595,7 +658,7 @@ Returns the projection acronym for the projection used by the CRS.
%Docstring
Returns the ellipsoid acronym for the ellipsoid used by the CRS.
:return: the official proj4 acronym for the ellipoid
:return: the official authority:code identifier for the ellipoid, or PARAMETER:MAJOR:MINOR for custom ellipsoids
.. note::
@ -624,24 +687,48 @@ only used on builds based on Proj >= 6, with earlier versions always using WKT1_
If ``multiline`` is ``True`` then a formatted multiline string will be returned, using the specified ``indentationWidth``.
This is only used on builds based on Proj >= 6.
.. seealso:: :py:func:`toProj4`
.. seealso:: :py:func:`toProj`
%End
QString toProj4() const;
QString toProj4() const /Deprecated/;
%Docstring
Returns a Proj4 string representation of this CRS.
Returns a Proj string representation of this CRS.
If proj and ellps keys are found in the parameters,
they will be stripped out and the projection and ellipsoid acronyms will be
overridden with these.
:return: Proj4 format string that defines this CRS.
:return: Proj format string that defines this CRS.
.. note::
.. warning::
an empty string will be returned if the CRS could not be represented by a Proj4 string
Not all CRS definitions can be represented by Proj strings. An empty
string will be returned if the CRS could not be represented by a Proj string.
.. seealso:: :py:func:`toWkt`
.. deprecated::
use toProj() instead.
%End
QString toProj() const;
%Docstring
Returns a Proj string representation of this CRS.
If proj and ellps keys are found in the parameters,
they will be stripped out and the projection and ellipsoid acronyms will be
overridden with these.
:return: Proj format string that defines this CRS.
.. warning::
Not all CRS definitions can be represented by Proj strings. An empty
string will be returned if the CRS could not be represented by a Proj string.
.. seealso:: :py:func:`toWkt`
.. versionadded:: 3.10.3
%End
bool isGeographic() const;
@ -696,14 +783,19 @@ Update proj.4 parameters in our database from proj.4
This is used internally and should not be necessary to call in client code
%End
long saveAsUserCrs( const QString &name, bool storeWkt = true );
long saveAsUserCrs( const QString &name, Format nativeFormat = FormatWkt );
%Docstring
Saves the CRS as a custom ("USER") CRS.
Returns the new CRS srsid(), or -1 if the CRS could not be saved.
If ``storeWkt`` is ``True`` then the WKT representation of the CRS will be stored in the database.
If it is ``False``, then only the lossy PROJ string representation of the CRS will be stored (not recommended).
The ``nativeFormat`` argument specifies the format to use when saving the CRS
definition. FormatWkt is recommended as it is a lossless format.
.. warning::
Not all CRS definitions can be represented as a Proj string, so
take care when using the FormatProj option.
%End
QString geographicCrsAuthId() const;

View File

@ -662,7 +662,7 @@ class PostGisDBConnector(DBConnector):
return QgsCoordinateReferenceSystem()
proj4text = res[0]
crs = QgsCoordinateReferenceSystem.fromProj4(proj4text)
crs = QgsCoordinateReferenceSystem.fromProj(proj4text)
return crs
def getSpatialRefInfo(self, srid):

View File

@ -436,4 +436,4 @@ class GdalUtils:
return crs.authid()
# fallback to proj4 string, stripping out newline characters
return crs.toProj4().replace('\n', ' ').replace('\r', ' ')
return crs.toProj().replace('\n', ' ').replace('\r', ' ')

View File

@ -1011,7 +1011,7 @@ class Grass7Algorithm(QgsProcessingAlgorithm):
"""
if not Grass7Utils.projectionSet and iface:
self.destination_crs = iface.mapCanvas().mapSettings().destinationCrs()
proj4 = iface.mapCanvas().mapSettings().destinationCrs().toProj4()
proj4 = iface.mapCanvas().mapSettings().destinationCrs().toProj()
command = 'g.proj -c proj4="{}"'.format(proj4)
self.commands.append(command)
Grass7Utils.projectionSet = True
@ -1022,7 +1022,7 @@ class Grass7Algorithm(QgsProcessingAlgorithm):
We creates a PROJ4 definition which is transmitted to Grass
"""
if not Grass7Utils.projectionSet:
proj4 = str(layer.crs().toProj4())
proj4 = str(layer.crs().toProj())
self.destination_crs = layer.crs()
command = 'g.proj -c proj4="{}"'.format(proj4)
self.commands.append(command)

View File

@ -28,7 +28,7 @@ from ..Grass7Utils import isWindows
def processInputs(alg, parameters, context, feedback):
# Grab the projection from the input vector layer
layer = alg.parameterAsLayer(parameters, 'input', context)
layerCrs = layer.crs().toProj4()
layerCrs = layer.crs().toProj()
# Creates a new location with this Crs
newLocation = 'newProj{}'.format(alg.uniqueSuffix)
@ -49,7 +49,7 @@ def processInputs(alg, parameters, context, feedback):
# Grab the projected Crs
crs = alg.parameterAsCrs(parameters, 'crs', context)
alg.commands.append('g.proj -c proj4="{}"'.format(
crs.toProj4(), newLocation))
crs.toProj(), newLocation))
# Remove crs parameter
alg.removeParameter('crs')

View File

@ -28,7 +28,7 @@ def processInputs(alg, parameters, context, feedback):
# Grab the projection from the input vector layer
layer = alg.parameterAsLayer(parameters, 'input', context)
alg.setSessionProjectionFromLayer(layer)
layerCrs = layer.crs().toProj4()
layerCrs = layer.crs().toProj()
# Creates a new location with this Crs
newLocation = 'newProj{}'.format(alg.uniqueSuffix)
@ -49,7 +49,7 @@ def processInputs(alg, parameters, context, feedback):
# Grab the projected Crs
crs = alg.parameterAsCrs(parameters, 'crs', context)
alg.commands.append('g.proj -c proj4="{}"'.format(
crs.toProj4(), newLocation))
crs.toProj(), newLocation))
# Remove crs parameter
alg.removeParameter('crs')

View File

@ -117,7 +117,7 @@ class HypsometricCurves(QgisAlgorithm):
rasterGeom = QgsGeometry.fromRect(rasterBBox)
crs = osr.SpatialReference()
crs.ImportFromProj4(str(target_crs.toProj4()))
crs.ImportFromProj4(str(target_crs.toProj()))
memVectorDriver = ogr.GetDriverByName('Memory')
memRasterDriver = gdal.GetDriverByName('MEM')

View File

@ -310,14 +310,14 @@ class TestGdalAlgorithms(unittest.TestCase):
'proj4: +proj=utm +zone=36 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs')),
'EPSG:20936')
crs = QgsCoordinateReferenceSystem()
crs.createFromProj4(
crs.createFromProj(
'+proj=utm +zone=36 +south +a=600000 +b=70000 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs')
self.assertTrue(crs.isValid())
self.assertEqual(GdalUtils.gdal_crs_string(crs),
'+proj=utm +zone=36 +south +a=600000 +b=70000 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs')
# check that newlines are stripped
crs = QgsCoordinateReferenceSystem()
crs.createFromProj4(
crs.createFromProj(
'+proj=utm +zone=36 +south\n +a=600000 +b=70000 \r\n +towgs84=-143,-90,-294,0,0,0,0 +units=m\n+no_defs')
self.assertTrue(crs.isValid())
self.assertEqual(GdalUtils.gdal_crs_string(crs),

View File

@ -75,8 +75,8 @@ QString displayIdentifierForCrs( const QgsCoordinateReferenceSystem &crs, bool s
}
else if ( !crs.description().isEmpty() )
return crs.description();
else if ( !crs.toProj4().isEmpty() )
return crs.toProj4();
else if ( !crs.toProj().isEmpty() )
return crs.toProj();
else
return crs.toWkt();
}

View File

@ -65,9 +65,9 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget *parent, Qt::Windo
leNameList->setSelectionMode( QAbstractItemView::ExtendedSelection );
mFormatComboBox->addItem( tr( "WKT (Recommended)" ), static_cast< int >( Format::Wkt ) );
mFormatComboBox->addItem( tr( "Proj String" ), static_cast< int >( Format::Proj ) );
mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( static_cast< int >( Format::Wkt ) ) );
mFormatComboBox->addItem( tr( "WKT (Recommended)" ), static_cast< int >( QgsCoordinateReferenceSystem::FormatWkt ) );
mFormatComboBox->addItem( tr( "Proj String" ), static_cast< int >( QgsCoordinateReferenceSystem::FormatProj ) );
mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( static_cast< int >( QgsCoordinateReferenceSystem::FormatWkt ) ) );
// user database is created at QGIS startup in QgisApp::createDB
// we just check whether there is our database [MD]
@ -83,7 +83,7 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget *parent, Qt::Windo
{
whileBlocking( leName )->setText( mDefinitions[0].name );
whileBlocking( teParameters )->setPlainText( mDefinitions[0].wkt.isEmpty() ? mDefinitions[0].proj : mDefinitions[0].wkt );
mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( static_cast< int >( mDefinitions[0].wkt.isEmpty() ? Format::Proj : Format::Wkt ) ) );
mFormatComboBox->setCurrentIndex( mFormatComboBox->findData( static_cast< int >( mDefinitions[0].wkt.isEmpty() ? QgsCoordinateReferenceSystem::FormatProj : QgsCoordinateReferenceSystem::FormatWkt ) ) );
leNameList->setCurrentItem( leNameList->topLevelItem( 0 ) );
}
@ -124,11 +124,11 @@ void QgsCustomProjectionDialog::populateList()
if ( !wkt.isEmpty() )
crs.createFromWkt( wkt );
else
crs.createFromProj4( parameters );
crs.createFromProj( parameters );
mExistingCRSnames[id] = name;
const QString actualWkt = crs.toWkt( QgsCoordinateReferenceSystem::WKT2_2018, false );
const QString actualProj = crs.toProj4();
const QString actualProj = crs.toProj();
mExistingCRSwkt[id] = wkt.isEmpty() ? QString() : actualWkt;
mExistingCRSproj[id] = wkt.isEmpty() ? actualProj : QString();
@ -243,7 +243,7 @@ void QgsCustomProjectionDialog::insertProjection( const QString &projectionAcro
}
}
bool QgsCustomProjectionDialog::saveCrs( QgsCoordinateReferenceSystem crs, const QString &name, const QString &existingId, bool newEntry, Format format )
bool QgsCustomProjectionDialog::saveCrs( QgsCoordinateReferenceSystem crs, const QString &name, const QString &existingId, bool newEntry, QgsCoordinateReferenceSystem::Format format )
{
QString id = existingId;
QString sql;
@ -252,7 +252,7 @@ bool QgsCustomProjectionDialog::saveCrs( QgsCoordinateReferenceSystem crs, const
QString ellipsoidAcronym = crs.ellipsoidAcronym();
if ( newEntry )
{
returnId = crs.saveAsUserCrs( name, format == Format::Wkt );
returnId = crs.saveAsUserCrs( name, format );
if ( returnId == -1 )
return false;
else
@ -264,9 +264,9 @@ bool QgsCustomProjectionDialog::saveCrs( QgsCoordinateReferenceSystem crs, const
+ QgsSqliteUtils::quotedString( name )
+ ",projection_acronym=" + ( !projectionAcronym.isEmpty() ? QgsSqliteUtils::quotedString( projectionAcronym ) : QStringLiteral( "''" ) )
+ ",ellipsoid_acronym=" + ( !ellipsoidAcronym.isEmpty() ? QgsSqliteUtils::quotedString( ellipsoidAcronym ) : QStringLiteral( "''" ) )
+ ",parameters=" + ( !crs.toProj4().isEmpty() ? QgsSqliteUtils::quotedString( crs.toProj4() ) : QStringLiteral( "''" ) )
+ ",parameters=" + ( !crs.toProj().isEmpty() ? QgsSqliteUtils::quotedString( crs.toProj() ) : QStringLiteral( "''" ) )
+ ",is_geo=0" // <--shamelessly hard coded for now
+ ",wkt=" + ( format == Format::Wkt ? QgsSqliteUtils::quotedString( crs.toWkt( QgsCoordinateReferenceSystem::WKT2_2018, false ) ) : QStringLiteral( "''" ) )
+ ",wkt=" + ( format == QgsCoordinateReferenceSystem::FormatWkt ? QgsSqliteUtils::quotedString( crs.toWkt( QgsCoordinateReferenceSystem::WKT2_2018, false ) ) : QStringLiteral( "''" ) )
+ " where srs_id=" + QgsSqliteUtils::quotedString( id )
;
QgsDebugMsgLevel( sql, 4 );
@ -291,8 +291,8 @@ bool QgsCustomProjectionDialog::saveCrs( QgsCoordinateReferenceSystem crs, const
if ( result != SQLITE_OK )
return false;
}
mExistingCRSwkt[id] = format == Format::Wkt ? crs.toWkt( QgsCoordinateReferenceSystem::WKT2_2018, false ) : QString();
mExistingCRSproj[id] = format == Format::Proj ? crs.toProj4() : QString();
mExistingCRSwkt[id] = format == QgsCoordinateReferenceSystem::FormatWkt ? crs.toWkt( QgsCoordinateReferenceSystem::WKT2_2018, false ) : QString();
mExistingCRSproj[id] = format == QgsCoordinateReferenceSystem::FormatProj ? crs.toProj() : QString();
mExistingCRSnames[id] = name;
QgsCoordinateReferenceSystem::invalidateCache();
@ -369,14 +369,14 @@ void QgsCustomProjectionDialog::leNameList_currentItemChanged( QTreeWidgetItem *
previousIndex = leNameList->indexOfTopLevelItem( previous );
mDefinitions[previousIndex].name = leName->text();
switch ( static_cast< Format >( mFormatComboBox->currentData().toInt() ) )
switch ( static_cast< QgsCoordinateReferenceSystem::Format >( mFormatComboBox->currentData().toInt() ) )
{
case Format::Wkt:
case QgsCoordinateReferenceSystem::FormatWkt:
mDefinitions[previousIndex].wkt = teParameters->toPlainText();
mDefinitions[previousIndex].proj.clear();
break;
case Format::Proj:
case QgsCoordinateReferenceSystem::FormatProj:
mDefinitions[previousIndex].proj = teParameters->toPlainText();
mDefinitions[previousIndex].wkt.clear();
break;
@ -391,14 +391,14 @@ void QgsCustomProjectionDialog::leNameList_currentItemChanged( QTreeWidgetItem *
currentIndex = leNameList->indexOfTopLevelItem( current );
whileBlocking( leName )->setText( mDefinitions[currentIndex].name );
whileBlocking( teParameters )->setPlainText( !mDefinitions[currentIndex].wkt.isEmpty() ? mDefinitions[currentIndex].wkt : mDefinitions[currentIndex].proj );
whileBlocking( mFormatComboBox )->setCurrentIndex( mFormatComboBox->findData( static_cast< int >( mDefinitions[currentIndex].wkt.isEmpty() ? Format::Proj : Format::Wkt ) ) );
whileBlocking( mFormatComboBox )->setCurrentIndex( mFormatComboBox->findData( static_cast< int >( mDefinitions[currentIndex].wkt.isEmpty() ? QgsCoordinateReferenceSystem::FormatProj : QgsCoordinateReferenceSystem::FormatWkt ) ) );
}
else
{
//Can happen that current is null, for example if we just deleted the last element
leName->clear();
teParameters->clear();
whileBlocking( mFormatComboBox )->setCurrentIndex( mFormatComboBox->findData( static_cast< int >( Format::Wkt ) ) );
whileBlocking( mFormatComboBox )->setCurrentIndex( mFormatComboBox->findData( static_cast< int >( QgsCoordinateReferenceSystem::FormatWkt ) ) );
return;
}
}
@ -414,7 +414,7 @@ void QgsCustomProjectionDialog::pbnCopyCRS_clicked()
pbnAdd_clicked();
}
whileBlocking( mFormatComboBox )->setCurrentIndex( mFormatComboBox->findData( static_cast< int >( Format::Wkt ) ) );
whileBlocking( mFormatComboBox )->setCurrentIndex( mFormatComboBox->findData( static_cast< int >( QgsCoordinateReferenceSystem::FormatWkt ) ) );
teParameters->setPlainText( srs.toWkt( QgsCoordinateReferenceSystem::WKT2_2018, true ) );
mDefinitions[leNameList->currentIndex().row()].wkt = srs.toWkt( QgsCoordinateReferenceSystem::WKT2_2018, false );
mDefinitions[leNameList->currentIndex().row()].proj.clear();
@ -436,7 +436,7 @@ void QgsCustomProjectionDialog::buttonBox_accepted()
if ( !def.wkt.isEmpty() )
crs.createFromWkt( def.wkt );
else
crs.createFromProj4( def.proj );
crs.createFromProj( def.proj );
if ( !crs.isValid() )
{
@ -479,12 +479,12 @@ void QgsCustomProjectionDialog::buttonBox_accepted()
if ( !def.wkt.isEmpty() )
crs.createFromWkt( def.wkt );
else
crs.createFromProj4( def.proj );
crs.createFromProj( def.proj );
//Test if we just added this CRS (if it has no existing ID)
if ( def.id.isEmpty() )
{
saveSuccess &= saveCrs( crs, def.name, QString(), true, !def.wkt.isEmpty() ? Format::Wkt : Format::Proj );
saveSuccess &= saveCrs( crs, def.name, QString(), true, !def.wkt.isEmpty() ? QgsCoordinateReferenceSystem::FormatWkt : QgsCoordinateReferenceSystem::FormatProj );
}
else
{
@ -493,7 +493,7 @@ void QgsCustomProjectionDialog::buttonBox_accepted()
|| ( !def.proj.isEmpty() && mExistingCRSproj[def.id] != def.proj )
)
{
saveSuccess &= saveCrs( crs, def.name, def.id, false, !def.wkt.isEmpty() ? Format::Wkt : Format::Proj );
saveSuccess &= saveCrs( crs, def.name, def.id, false, !def.wkt.isEmpty() ? QgsCoordinateReferenceSystem::FormatWkt : QgsCoordinateReferenceSystem::FormatProj );
}
}
if ( ! saveSuccess )
@ -527,14 +527,14 @@ void QgsCustomProjectionDialog::updateListFromCurrentItem()
return;
mDefinitions[currentIndex].name = leName->text();
switch ( static_cast< Format >( mFormatComboBox->currentData().toInt() ) )
switch ( static_cast< QgsCoordinateReferenceSystem::Format >( mFormatComboBox->currentData().toInt() ) )
{
case Format::Wkt:
case QgsCoordinateReferenceSystem::FormatWkt:
mDefinitions[currentIndex].wkt = teParameters->toPlainText();
mDefinitions[currentIndex].proj.clear();
break;
case Format::Proj:
case QgsCoordinateReferenceSystem::FormatProj:
mDefinitions[currentIndex].proj = teParameters->toPlainText();
mDefinitions[currentIndex].wkt.clear();
break;
@ -566,9 +566,9 @@ void QgsCustomProjectionDialog::validateCurrent()
proj_log_func( context, &projErrors, proj_collecting_logger );
QgsProjUtils::proj_pj_unique_ptr crs;
switch ( static_cast< Format >( mFormatComboBox->currentData().toInt() ) )
switch ( static_cast< QgsCoordinateReferenceSystem::Format >( mFormatComboBox->currentData().toInt() ) )
{
case Format::Wkt:
case QgsCoordinateReferenceSystem::FormatWkt:
{
PROJ_STRING_LIST warnings = nullptr;
PROJ_STRING_LIST grammerErrors = nullptr;
@ -595,7 +595,7 @@ void QgsCustomProjectionDialog::validateCurrent()
break;
}
case Format::Proj:
case QgsCoordinateReferenceSystem::FormatProj:
{
const QString projCrsString = projDef + ( projDef.contains( QStringLiteral( "+type=crs" ) ) ? QString() : QStringLiteral( " +type=crs" ) );
crs.reset( proj_create( context, projCrsString.toLatin1().constData() ) );
@ -669,19 +669,19 @@ void QgsCustomProjectionDialog::formatChanged()
{
QgsCoordinateReferenceSystem crs;
QString newFormatString;
switch ( static_cast< Format >( mFormatComboBox->currentData().toInt() ) )
switch ( static_cast< QgsCoordinateReferenceSystem::Format >( mFormatComboBox->currentData().toInt() ) )
{
case Format::Proj:
case QgsCoordinateReferenceSystem::FormatProj:
{
crs.createFromWkt( teParameters->toPlainText() );
if ( crs.isValid() )
newFormatString = crs.toProj4();
newFormatString = crs.toProj();
break;
}
case Format::Wkt:
case QgsCoordinateReferenceSystem::FormatWkt:
{
crs.createFromProj4( teParameters->toPlainText() );
crs.createFromProj( teParameters->toPlainText() );
if ( crs.isValid() )
newFormatString = crs.toWkt( QgsCoordinateReferenceSystem::WKT2_2018, false );
break;
@ -762,7 +762,7 @@ void QgsCustomProjectionDialog::pbnCalculate_clicked()
#endif
#if PROJ_VERSION_MAJOR>=6
if ( static_cast< Format >( mFormatComboBox->currentData().toInt() ) == Format::Proj )
if ( static_cast< QgsCoordinateReferenceSystem::Format >( mFormatComboBox->currentData().toInt() ) == QgsCoordinateReferenceSystem::FormatProj )
projDef = projDef + ( projDef.contains( QStringLiteral( "+type=crs" ) ) ? QString() : QStringLiteral( " +type=crs" ) );
QgsProjUtils::proj_pj_unique_ptr res( proj_create_crs_to_crs( pContext, "EPSG:4326", projDef.toUtf8(), nullptr ) );
if ( !res )

View File

@ -50,16 +50,10 @@ class APP_EXPORT QgsCustomProjectionDialog : public QDialog, private Ui::QgsCust
private:
enum class Format
{
Wkt = 0,
Proj
};
//helper functions
void populateList();
bool deleteCrs( const QString &id );
bool saveCrs( QgsCoordinateReferenceSystem crs, const QString &name, const QString &id, bool newEntry, Format format );
bool saveCrs( QgsCoordinateReferenceSystem crs, const QString &name, const QString &id, bool newEntry, QgsCoordinateReferenceSystem::Format format );
void insertProjection( const QString &projectionAcronym );
void showHelp();

View File

@ -996,7 +996,7 @@ void QgsProjectProperties::apply()
{
QgsDebugMsgLevel( QStringLiteral( "Selected CRS " ) + srs.description(), 4 );
// write the currently selected projections _proj string_ to project settings
QgsDebugMsgLevel( QStringLiteral( "SpatialRefSys/ProjectCRSProj4String: %1" ).arg( srs.toProj4() ), 4 );
QgsDebugMsgLevel( QStringLiteral( "SpatialRefSys/ProjectCRSProj4String: %1" ).arg( srs.toProj() ), 4 );
}
else
{

View File

@ -339,12 +339,12 @@ QgsExpressionContextScope *QgsExpressionContextUtils::mapSettingsScope( const Qg
// (rationale is described in QgsLayoutItemMap::createExpressionContext() )
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs" ), mapSettings.destinationCrs().authid(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_definition" ), mapSettings.destinationCrs().toProj4(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_definition" ), mapSettings.destinationCrs().toProj(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_units" ), QgsUnitTypes::toString( mapSettings.mapUnits() ), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_description" ), mapSettings.destinationCrs().description(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_acronym" ), mapSettings.destinationCrs().projectionAcronym(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_ellipsoid" ), mapSettings.destinationCrs().ellipsoidAcronym(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_proj4" ), mapSettings.destinationCrs().toProj4(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_proj4" ), mapSettings.destinationCrs().toProj(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_wkt" ), mapSettings.destinationCrs().toWkt(), true ) );
// IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()

View File

@ -4637,7 +4637,7 @@ static QVariant fcnGetLayerProperty( const QVariantList &values, const QgsExpres
else if ( QString::compare( layerProperty, QStringLiteral( "crs" ), Qt::CaseInsensitive ) == 0 )
return layer->crs().authid();
else if ( QString::compare( layerProperty, QStringLiteral( "crs_definition" ), Qt::CaseInsensitive ) == 0 )
return layer->crs().toProj4();
return layer->crs().toProj();
else if ( QString::compare( layerProperty, QStringLiteral( "crs_description" ), Qt::CaseInsensitive ) == 0 )
return layer->crs().description();
else if ( QString::compare( layerProperty, QStringLiteral( "extent" ), Qt::CaseInsensitive ) == 0 )

View File

@ -1489,12 +1489,12 @@ QgsExpressionContext QgsLayoutItemMap::createExpressionContext() const
QgsCoordinateReferenceSystem mapCrs = crs();
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs" ), mapCrs.authid(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_definition" ), mapCrs.toProj4(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_definition" ), mapCrs.toProj(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_description" ), mapCrs.description(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_units" ), QgsUnitTypes::toString( mapCrs.mapUnits() ), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_acronym" ), mapCrs.projectionAcronym(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_ellipsoid" ), mapCrs.ellipsoidAcronym(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_proj4" ), mapCrs.toProj4(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_proj4" ), mapCrs.toProj(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_wkt" ), mapCrs.toWkt(), true ) );
QVariantList layersIds;

View File

@ -75,7 +75,7 @@ bool QgsCoordinateReferenceSystem::sDisableOgcCache = false;
Q_GLOBAL_STATIC( QReadWriteLock, sProj4CacheLock )
Q_GLOBAL_STATIC( StringCrsCacheHash, sProj4Cache )
bool QgsCoordinateReferenceSystem::sDisableProj4Cache = false;
bool QgsCoordinateReferenceSystem::sDisableProjCache = false;
Q_GLOBAL_STATIC( QReadWriteLock, sCRSWktLock )
Q_GLOBAL_STATIC( StringCrsCacheHash, sWktCache )
@ -214,9 +214,14 @@ QgsCoordinateReferenceSystem QgsCoordinateReferenceSystem::fromEpsgId( long epsg
}
QgsCoordinateReferenceSystem QgsCoordinateReferenceSystem::fromProj4( const QString &proj4 )
{
return fromProj( proj4 );
}
QgsCoordinateReferenceSystem QgsCoordinateReferenceSystem::fromProj( const QString &proj )
{
QgsCoordinateReferenceSystem crs;
crs.createFromProj4( proj4 );
crs.createFromProj( proj );
return crs;
}
@ -307,12 +312,12 @@ bool QgsCoordinateReferenceSystem::createFromString( const QString &definition )
{
if ( match.captured( 1 ).compare( QLatin1String( "proj4" ), Qt::CaseInsensitive ) == 0 )
{
result = createFromProj4( match.captured( 2 ) );
result = createFromProj( match.captured( 2 ) );
if ( srsid() == 0 )
{
QString myName = QStringLiteral( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ),
toProj4() );
toProj() );
saveAsUserCrs( myName );
}
}
@ -671,7 +676,7 @@ bool QgsCoordinateReferenceSystem::loadFromDatabase( const QString &db, const QS
if ( !d->mWkt.isEmpty() )
setWktString( d->mWkt, false );
else
setProj4String( d->mProj4 );
setProjString( d->mProj4 );
}
}
else
@ -774,10 +779,15 @@ bool QgsCoordinateReferenceSystem::isValid() const
}
bool QgsCoordinateReferenceSystem::createFromProj4( const QString &proj4String )
{
return createFromProj( proj4String );
}
bool QgsCoordinateReferenceSystem::createFromProj( const QString &projString )
{
d.detach();
if ( proj4String.trimmed().isEmpty() )
if ( projString.trimmed().isEmpty() )
{
d->mIsValid = false;
d->mWkt.clear();
@ -786,9 +796,9 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString &proj4String )
}
QgsReadWriteLocker locker( *sProj4CacheLock(), QgsReadWriteLocker::Read );
if ( !sDisableProj4Cache )
if ( !sDisableProjCache )
{
QHash< QString, QgsCoordinateReferenceSystem >::const_iterator crsIt = sProj4Cache()->constFind( proj4String );
QHash< QString, QgsCoordinateReferenceSystem >::const_iterator crsIt = sProj4Cache()->constFind( projString );
if ( crsIt != sProj4Cache()->constEnd() )
{
// found a match in the cache
@ -806,7 +816,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString &proj4String )
// +proj=lcc +lat_1=46.8 +lat_0=46.8 +lon_0=2.337229166666664 +k_0=0.99987742
// +x_0=600000 +y_0=2200000 +a=6378249.2 +b=6356515.000000472 +units=m +no_defs
//
QString myProj4String = proj4String.trimmed();
QString myProj4String = projString.trimmed();
myProj4String.remove( QStringLiteral( "+type=crs" ) );
myProj4String = myProj4String.trimmed();
@ -836,8 +846,8 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString &proj4String )
if ( createFromOgcWmsCrs( authid ) )
{
locker.changeMode( QgsReadWriteLocker::Write );
if ( !sDisableProj4Cache )
sProj4Cache()->insert( proj4String, *this );
if ( !sDisableProjCache )
sProj4Cache()->insert( projString, *this );
return true;
}
}
@ -855,8 +865,8 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString &proj4String )
if ( myStart == -1 )
{
locker.changeMode( QgsReadWriteLocker::Write );
if ( !sDisableProj4Cache )
sProj4Cache()->insert( proj4String, *this );
if ( !sDisableProjCache )
sProj4Cache()->insert( projString, *this );
return d->mIsValid;
}
@ -920,7 +930,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString &proj4String )
proj4StringModified.replace( myStart1 + LAT_PREFIX_LEN, myLength1 - LAT_PREFIX_LEN, lat2Str );
// Now we have to find the lat_2 location again since it has potentially moved...
myStart2 = 0;
myStart2 = myLat2RegExp.indexIn( proj4String, myStart2 );
myStart2 = myLat2RegExp.indexIn( projString, myStart2 );
proj4StringModified.replace( myStart2 + LAT_PREFIX_LEN, myLength2 - LAT_PREFIX_LEN, lat1Str );
QgsDebugMsgLevel( QStringLiteral( "trying proj4string match with swapped lat_1,lat_2" ), 4 );
myRecord = getRecord( "select * from tbl_srs where parameters=" + QgsSqliteUtils::quotedString( proj4StringModified.trimmed() ) + " order by deprecated" );
@ -1001,8 +1011,10 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString &proj4String )
else
{
// Last ditch attempt to piece together what we know of the projection to find a match...
setProj4String( myProj4String );
setProjString( myProj4String );
Q_NOWARN_DEPRECATED_PUSH
mySrsId = findMatchingProj();
Q_NOWARN_DEPRECATED_POP
if ( mySrsId > 0 )
{
createFromSrsId( mySrsId );
@ -1019,12 +1031,12 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString &proj4String )
{
QgsDebugMsgLevel( QStringLiteral( "Projection is not found in databases." ), 4 );
//setProj4String will set mIsValidFlag to true if there is no issue
setProj4String( myProj4String );
setProjString( myProj4String );
}
locker.changeMode( QgsReadWriteLocker::Write );
if ( !sDisableProj4Cache )
sProj4Cache()->insert( proj4String, *this );
if ( !sDisableProjCache )
sProj4Cache()->insert( projString, *this );
return d->mIsValid;
}
@ -1211,6 +1223,11 @@ QString QgsCoordinateReferenceSystem::ellipsoidAcronym() const
}
QString QgsCoordinateReferenceSystem::toProj4() const
{
return toProj();
}
QString QgsCoordinateReferenceSystem::toProj() const
{
if ( !d->mIsValid )
return QString();
@ -1335,7 +1352,7 @@ void QgsCoordinateReferenceSystem::setDescription( const QString &description )
d.detach();
d->mDescription = description;
}
void QgsCoordinateReferenceSystem::setProj4String( const QString &proj4String )
void QgsCoordinateReferenceSystem::setProjString( const QString &proj4String )
{
d.detach();
d->mProj4 = proj4String;
@ -1398,14 +1415,14 @@ void QgsCoordinateReferenceSystem::setProj4String( const QString &proj4String )
setMapUnits();
}
bool QgsCoordinateReferenceSystem::setWktString( const QString &wkt, bool allowProj4Fallback )
bool QgsCoordinateReferenceSystem::setWktString( const QString &wkt, bool allowProjFallback )
{
bool res = false;
d->mIsValid = false;
#if PROJ_VERSION_MAJOR>=6
// TODO - remove allowProj4Fallback when we require proj 6+ to build
( void )allowProj4Fallback;
// TODO - remove allowProjFallback when we require proj 6+ to build
( void )allowProjFallback;
PROJ_STRING_LIST warnings = nullptr;
PROJ_STRING_LIST grammerErrors = nullptr;
@ -1512,10 +1529,10 @@ bool QgsCoordinateReferenceSystem::setWktString( const QString &wkt, bool allowP
char *proj4src = nullptr;
OSRExportToProj4( d->mCRS, &proj4src );
//now that we have the proj4string, delegate to createFromProj4 so
//now that we have the proj4string, delegate to createFromProj so
// that we can try to fill in the remaining class members...
//create from Proj will set the isValidFlag
if ( !createFromProj4( proj4src ) )
if ( !createFromProj( proj4src ) )
{
CPLFree( proj4src );
@ -1526,7 +1543,7 @@ bool QgsCoordinateReferenceSystem::setWktString( const QString &wkt, bool allowP
OSRExportToProj4( d->mCRS, &proj4src );
createFromProj4( proj4src );
createFromProj( proj4src );
}
CPLFree( proj4src );
}
@ -1731,7 +1748,7 @@ long QgsCoordinateReferenceSystem::findMatchingProj()
{
QString mySrsId = statement.columnAsText( 0 );
QString myProj4String = statement.columnAsText( 1 );
if ( toProj4() == myProj4String.trimmed() )
if ( toProj() == myProj4String.trimmed() )
{
return mySrsId.toLong();
}
@ -1758,7 +1775,7 @@ long QgsCoordinateReferenceSystem::findMatchingProj()
{
QString mySrsId = statement.columnAsText( 0 );
QString myProj4String = statement.columnAsText( 1 );
if ( toProj4() == myProj4String.trimmed() )
if ( toProj() == myProj4String.trimmed() )
{
return mySrsId.toLong();
}
@ -1881,7 +1898,7 @@ bool QgsCoordinateReferenceSystem::readXml( const QDomNode &node )
{
node = srsNode.namedItem( QStringLiteral( "proj4" ) );
const QString proj4 = node.toElement().text();
initialized = createFromProj4( proj4 );
initialized = createFromProj( proj4 );
}
if ( !initialized )
@ -1890,7 +1907,7 @@ bool QgsCoordinateReferenceSystem::readXml( const QDomNode &node )
node = srsNode.namedItem( QStringLiteral( "proj4" ) );
const QString proj4 = node.toElement().text();
if ( !proj4.trimmed().isEmpty() )
setProj4String( node.toElement().text() );
setProjString( node.toElement().text() );
node = srsNode.namedItem( QStringLiteral( "srsid" ) );
setInternalId( node.toElement().text().toLong() );
@ -1928,7 +1945,7 @@ bool QgsCoordinateReferenceSystem::readXml( const QDomNode &node )
{
QString myName = QStringLiteral( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ),
toProj4() );
toProj() );
saveAsUserCrs( myName );
}
}
@ -1951,7 +1968,7 @@ bool QgsCoordinateReferenceSystem::writeXml( QDomNode &node, QDomDocument &doc )
srsElement.appendChild( wktElement );
QDomElement proj4Element = doc.createElement( QStringLiteral( "proj4" ) );
proj4Element.appendChild( doc.createTextNode( toProj4() ) );
proj4Element.appendChild( doc.createTextNode( toProj() ) );
srsElement.appendChild( proj4Element );
QDomElement srsIdElement = doc.createElement( QStringLiteral( "srsid" ) );
@ -2000,7 +2017,7 @@ bool QgsCoordinateReferenceSystem::writeXml( QDomNode &node, QDomDocument &doc )
// Returns the whole proj4 string for the selected srsid
//this is a static method! NOTE I've made it private for now to reduce API clutter TS
QString QgsCoordinateReferenceSystem::proj4FromSrsId( const int srsId )
QString QgsCoordinateReferenceSystem::projFromSrsId( const int srsId )
{
QString myDatabaseFileName;
QString myProjString;
@ -2086,7 +2103,7 @@ void QgsCoordinateReferenceSystem::debugPrint()
QgsDebugMsg( QStringLiteral( "***SpatialRefSystem***" ) );
QgsDebugMsg( "* Valid : " + ( d->mIsValid ? QString( "true" ) : QString( "false" ) ) );
QgsDebugMsg( "* SrsId : " + QString::number( d->mSrsId ) );
QgsDebugMsg( "* Proj4 : " + toProj4() );
QgsDebugMsg( "* Proj4 : " + toProj() );
QgsDebugMsg( "* WKT : " + toWkt() );
QgsDebugMsg( "* Desc. : " + d->mDescription );
if ( mapUnits() == QgsUnitTypes::DistanceMeters )
@ -2117,7 +2134,7 @@ QString QgsCoordinateReferenceSystem::validationHint()
/// Copied from QgsCustomProjectionDialog ///
/// Please refactor into SQL handler !!! ///
long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name, bool storeWkt )
long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name, Format nativeFormat )
{
if ( !d->mIsValid )
{
@ -2130,7 +2147,7 @@ long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name, bool stor
QString proj4String = d->mProj4;
if ( proj4String.isEmpty() )
{
proj4String = toProj4();
proj4String = toProj();
}
QString wktString = d->mWkt;
if ( wktString.isEmpty() )
@ -2155,7 +2172,7 @@ long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name, bool stor
+ ',' + quotedEllipsoidString
+ ',' + ( !proj4String.isEmpty() ? QgsSqliteUtils::quotedString( proj4String ) : QStringLiteral( "''" ) )
+ ",0," // <-- is_geo shamelessly hard coded for now
+ ( storeWkt ? QgsSqliteUtils::quotedString( wktString ) : QStringLiteral( "''" ) )
+ ( nativeFormat == FormatWkt ? QgsSqliteUtils::quotedString( wktString ) : QStringLiteral( "''" ) )
+ ')';
}
else
@ -2166,7 +2183,7 @@ long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name, bool stor
+ ',' + quotedEllipsoidString
+ ',' + ( !proj4String.isEmpty() ? QgsSqliteUtils::quotedString( proj4String ) : QStringLiteral( "''" ) )
+ ",0," // <-- is_geo shamelessly hard coded for now
+ ( storeWkt ? QgsSqliteUtils::quotedString( wktString ) : QStringLiteral( "''" ) )
+ ( nativeFormat == FormatWkt ? QgsSqliteUtils::quotedString( wktString ) : QStringLiteral( "''" ) )
+ ')';
}
sqlite3_database_unique_ptr database;
@ -2185,7 +2202,7 @@ long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name, bool stor
qint64 returnId = -1;
if ( myResult == SQLITE_OK && statement.step() == SQLITE_DONE )
{
QgsMessageLog::logMessage( QObject::tr( "Saved user CRS [%1]" ).arg( toProj4() ), QObject::tr( "CRS" ) );
QgsMessageLog::logMessage( QObject::tr( "Saved user CRS [%1]" ).arg( toProj() ), QObject::tr( "CRS" ) );
returnId = sqlite3_last_insert_rowid( database.get() );
setInternalId( returnId );
@ -2200,7 +2217,7 @@ long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name, bool stor
QStringList projectionsAuthId = settings.value( QStringLiteral( "UI/recentProjectionsAuthId" ) ).toStringList();
//recentProjections.append();
//settings.setValue( "/UI/recentProjections", recentProjections );
projectionsProj4.append( toProj4() );
projectionsProj4.append( toProj() );
projectionsAuthId.append( authid() );
settings.setValue( QStringLiteral( "UI/recentProjectionsProj4" ), projectionsProj4 );
settings.setValue( QStringLiteral( "UI/recentProjectionsAuthId" ), projectionsAuthId );
@ -3227,7 +3244,7 @@ const QHash<QString, QgsCoordinateReferenceSystem> &QgsCoordinateReferenceSystem
return *sStringCache();
}
const QHash<QString, QgsCoordinateReferenceSystem> &QgsCoordinateReferenceSystem::proj4Cache()
const QHash<QString, QgsCoordinateReferenceSystem> &QgsCoordinateReferenceSystem::projCache()
{
return *sProj4Cache();
}
@ -3308,7 +3325,7 @@ QStringList QgsCoordinateReferenceSystem::recentProjections()
if ( ! crs.isValid() )
{
// Couldn't create from EPSG, try the Proj4 string instead
if ( i >= projectionsProj4.size() || !crs.createFromProj4( projectionsProj4.at( i ) ) )
if ( i >= projectionsProj4.size() || !crs.createFromProj( projectionsProj4.at( i ) ) )
{
// No? Skip this entry
continue;
@ -3346,10 +3363,10 @@ void QgsCoordinateReferenceSystem::invalidateCache( bool disableCache )
sOgcLock()->unlock();
sProj4CacheLock()->lockForWrite();
if ( !sDisableProj4Cache )
if ( !sDisableProjCache )
{
if ( disableCache )
sDisableProj4Cache = true;
sDisableProjCache = true;
sProj4Cache()->clear();
}
sProj4CacheLock()->unlock();

View File

@ -77,12 +77,12 @@ typedef void ( *CUSTOM_CRS_VALIDATION )( QgsCoordinateReferenceSystem & ) SIP_SK
* typically using meters or feet as units. Common projected coordinate systems are Universal
* Transverse Mercator or Albers Equal Area.
*
* Internally QGIS uses proj4 library for all the math behind coordinate transformations, so in case
* Internally QGIS uses proj library for all the math behind coordinate transformations, so in case
* of any troubles with projections it is best to examine the PROJ representation within the object,
* as that is the representation that will be ultimately used.
*
* Methods that allow inspection of CRS instances include isValid(), authid(), description(),
* toWkt(), toProj4(), mapUnits() and others.
* toWkt(), toProj(), mapUnits() and others.
* Creation of CRS instances is further described in \ref crs_construct_and_copy section below.
* Transformations between coordinate reference systems are done using QgsCoordinateTransform class.
*
@ -92,7 +92,7 @@ typedef void ( *CUSTOM_CRS_VALIDATION )( QgsCoordinateReferenceSystem & ) SIP_SK
* crs = QgsCoordinateReferenceSystem("EPSG:27700")
* if crs.isValid():
* print("CRS Description: {}".format(crs.description()))
* print("CRS PROJ text: {}".format(crs.toProj4()))
* print("CRS PROJ text: {}".format(crs.toProj()))
* else:
* print("Invalid CRS!")
* \endcode
@ -126,11 +126,11 @@ typedef void ( *CUSTOM_CRS_VALIDATION )( QgsCoordinateReferenceSystem & ) SIP_SK
*
* 2. **PROJ string.** This is a string consisting of a series of key/value pairs in the following
* format: `+param1=value1 +param2=value2 [...]`. This is the format natively used by the
* underlying proj4 library. For example, the definition of WGS84 looks like this:
* underlying proj library. For example, the definition of WGS84 looks like this:
*
* +proj=longlat +datum=WGS84 +no_defs
*
* See toProj4() and createFromProj4() methods.
* See toProj() and createFromProj() methods.
*
* 3. **Well-known text (WKT).** Defined by Open Geospatial Consortium (OGC), this is another common
* format to define CRS. For WGS84 the OGC WKT definition is the following:
@ -212,6 +212,13 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
EpsgCrsId //!< EPSG code
};
//! Projection definition formats
enum Format
{
FormatWkt = 0, //!< WKT format (always recommended over proj string format)
FormatProj, //!< Proj string format
};
//! Constructs an invalid CRS object
QgsCoordinateReferenceSystem();
@ -226,7 +233,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* - "EPSG:<code>" - handled with createFromOgcWms()
* - "POSTGIS:<srid>" - handled with createFromSrid()
* - "INTERNAL:<srsid>" - handled with createFromSrsId()
* - "PROJ4:<proj4>" - handled with createFromProj4()
* - "PROJ4:<proj4>" - handled with createFromProj()
* - "WKT:<wkt>" - handled with createFromWkt()
*
* If no prefix is specified, WKT definition is assumed.
@ -239,8 +246,9 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
/**
* Constructor a CRS object using a PostGIS SRID, an EPSG code or an internal QGIS CRS ID.
* \note We encourage you to use EPSG code, WKT or Proj4 to describe CRS's in your code
* wherever possible. Internal QGIS CRS IDs are not guaranteed to be permanent / involatile.
* \note 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.
* \param id The ID valid for the chosen CRS ID type
* \param type One of the types described in CrsType
*/
@ -287,13 +295,22 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
Q_INVOKABLE static QgsCoordinateReferenceSystem fromEpsgId( long epsg );
/**
* Creates a CRS from a proj4 style formatted string.
* \param proj4 proj4 format string
* Creates a CRS from a proj style formatted string.
* \param proj proj format string
* \returns matching CRS, or an invalid CRS if string could not be matched
* \see createFromProj4()
* \since QGIS 3.0
* \see createFromProj()
* \deprecated Use fromProj() instead.
*/
static QgsCoordinateReferenceSystem fromProj4( const QString &proj4 );
Q_DECL_DEPRECATED static QgsCoordinateReferenceSystem fromProj4( const QString &proj4 ) SIP_DEPRECATED;
/**
* Creates a CRS from a proj style formatted string.
* \param proj proj format string
* \returns matching CRS, or an invalid CRS if string could not be matched
* \see createFromProj()
* \since QGIS 3.10.3
*/
static QgsCoordinateReferenceSystem fromProj( const QString &proj );
/**
* Creates a CRS from a WKT spatial ref sys definition string.
@ -321,8 +338,9 @@ 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, WKT or Proj4 to describe CRS's in your code
* wherever possible. Internal QGIS CRS IDs are not guaranteed to be permanent / involatile.
* \note 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 );
@ -354,8 +372,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
*
* If EPSG code of the WKT definition can be determined, it is extracted
* and createFromOgcWmsCrs() is used to initialize the object.
* Otherwise the WKT will be converted to a proj4 string and createFromProj4()
* set up the object.
*
* \param wkt The WKT for the desired spatial reference system.
* \returns TRUE on success else FALSE
* \note Some members may be left blank if no match can be found in CRS database.
@ -380,26 +397,55 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* Sets this CRS by passing it a PROJ style formatted string.
*
* The string will be parsed and the projection and ellipsoid
* members set and the remainder of the proj4 string will be stored
* members set and the remainder of the Proj string will be stored
* in the parameters member. The reason for this is so that we
* can easily present the user with 'natural language' representation
* of the projection and ellipsoid by looking them up in the srs.db sqlite
* database.
*
* We try to match the proj4 string to internal QGIS CRS ID using the following logic:
* We try to match the Proj string to internal QGIS CRS ID using the following logic:
*
* - perform a whole text search on proj4 string (if not null)
* - if not match is found, split proj4 into individual parameters and try to find
* a match where the parameters are in a different order
* - if none of the above match, use findMatchingProj()
* - ask the Proj library to identify the CRS to a standard registered CRS (e.g. EPSG codes)
* - if no match is found, compare the CRS to all user CRSes, using the Proj library
* to determine CRS equivalence (hence making the match parameter order insensitive)
* - if none of the above match, use the Proj string to create the CRS and do not
* associated an internal CRS ID to it.
*
* \param projString A proj4 format string
* \param projString A Proj format string
* \returns TRUE on success else FALSE
* \note Some members may be left blank if no match can be found in CRS database.
* \note this method uses an internal cache. Call invalidateCache() to clear the cache.
* \see fromProj4()
* \see fromProj()
* \deprecated Use createFromProj() instead
*/
bool createFromProj4( const QString &projString );
Q_DECL_DEPRECATED bool createFromProj4( const QString &projString ) SIP_DEPRECATED;
/**
* Sets this CRS by passing it a PROJ style formatted string.
*
* The string will be parsed and the projection and ellipsoid
* members set and the remainder of the Proj string will be stored
* in the parameters member. The reason for this is so that we
* can easily present the user with 'natural language' representation
* of the projection and ellipsoid by looking them up in the srs.db sqlite
* database.
*
* We try to match the Proj string to internal QGIS CRS ID using the following logic:
*
* - ask the Proj library to identify the CRS to a standard registered CRS (e.g. EPSG codes)
* - if no match is found, compare the CRS to all user CRSes, using the Proj library
* to determine CRS equivalence (hence making the match parameter order insensitive)
* - if none of the above match, use the Proj string to create the CRS and do not
* associated an internal CRS ID to it.
*
* \param projString A Proj format string
* \returns TRUE on success else FALSE
* \note Some members may be left blank if no match can be found in CRS database.
* \note this method uses an internal cache. Call invalidateCache() to clear the cache.
* \see fromProj()
* \since QGIS 3.10.3
*/
bool createFromProj( const QString &projString );
/**
* Set up this CRS from a string definition.
@ -408,7 +454,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* - "EPSG:<code>" - handled with createFromOgcWms()
* - "POSTGIS:<srid>" - handled with createFromSrid()
* - "INTERNAL:<srsid>" - handled with createFromSrsId()
* - "PROJ4:<proj4>" - handled with createFromProj4()
* - "PROJ4:<proj4>" - handled with createFromProj()
* - "WKT:<wkt>" - handled with createFromWkt()
*
* If no prefix is specified, WKT definition is assumed.
@ -467,10 +513,11 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* Walks the CRS databases (both system and user database) trying to match
* stored PROJ string to a database entry in order to fill in further
* pieces of information about CRS.
* \note The ellipsoid and projection acronyms must be set as well as the proj4string!
* \note The ellipsoid and projection acronyms must be set as well as the proj string!
* \returns long the SrsId of the matched CRS, zero if no match was found
* \deprecated Not used in Proj >= 6 based builds
*/
long findMatchingProj();
Q_DECL_DEPRECATED long findMatchingProj() SIP_DEPRECATED;
/**
* Overloaded == operator used to compare to CRS's.
@ -557,7 +604,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
/**
* Returns the projection acronym for the projection used by the CRS.
* \returns the official proj4 acronym for the projection family
* \returns the official Proj acronym for the projection family
* \note an empty string will be returned if the projectionAcronym is not available for the CRS
* \see ellipsoidAcronym()
*/
@ -565,7 +612,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
/**
* Returns the ellipsoid acronym for the ellipsoid used by the CRS.
* \returns the official proj4 acronym for the ellipoid
* \returns the official authority:code identifier for the ellipoid, or PARAMETER:MAJOR:MINOR for custom ellipsoids
* \note an empty string will be returned if the ellipsoidAcronym is not available for the CRS
* \see projectionAcronym()
*/
@ -591,21 +638,37 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* If \a multiline is TRUE then a formatted multiline string will be returned, using the specified \a indentationWidth.
* This is only used on builds based on Proj >= 6.
*
* \see toProj4()
* \see toProj()
*/
QString toWkt( WktVariant variant = WKT1_GDAL, bool multiline = false, int indentationWidth = 4 ) const;
/**
* Returns a Proj4 string representation of this CRS.
* Returns a Proj string representation of this CRS.
*
* If proj and ellps keys are found in the parameters,
* they will be stripped out and the projection and ellipsoid acronyms will be
* overridden with these.
* \returns Proj4 format string that defines this CRS.
* \note an empty string will be returned if the CRS could not be represented by a Proj4 string
* \returns Proj format string that defines this CRS.
* \warning Not all CRS definitions can be represented by Proj strings. An empty
* string will be returned if the CRS could not be represented by a Proj string.
* \see toWkt()
* \deprecated use toProj() instead.
*/
QString toProj4() const;
Q_DECL_DEPRECATED QString toProj4() const SIP_DEPRECATED;
/**
* Returns a Proj string representation of this CRS.
*
* If proj and ellps keys are found in the parameters,
* they will be stripped out and the projection and ellipsoid acronyms will be
* overridden with these.
* \returns Proj format string that defines this CRS.
* \warning Not all CRS definitions can be represented by Proj strings. An empty
* string will be returned if the CRS could not be represented by a Proj string.
* \see toWkt()
* \since QGIS 3.10.3
*/
QString toProj() const;
/**
* Returns whether the CRS is a geographic CRS (using lat/lon coordinates)
@ -659,10 +722,13 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
*
* Returns the new CRS srsid(), or -1 if the CRS could not be saved.
*
* If \a storeWkt is TRUE then the WKT representation of the CRS will be stored in the database.
* If it is FALSE, then only the lossy PROJ string representation of the CRS will be stored (not recommended).
* The \a nativeFormat argument specifies the format to use when saving the CRS
* definition. FormatWkt is recommended as it is a lossless format.
*
* \warning Not all CRS definitions can be represented as a Proj string, so
* take care when using the FormatProj option.
*/
long saveAsUserCrs( const QString &name, bool storeWkt = true );
long saveAsUserCrs( const QString &name, Format nativeFormat = FormatWkt );
//! Returns auth id of related geographic CRS
QString geographicCrsAuthId() const;
@ -729,11 +795,11 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
private:
/**
* A static helper function to find out the proj4 string for a srsid
* A static helper function to find out the proj string for a srsid
* \param srsId The srsid used for the lookup
* \returns QString The proj4 string
* \returns QString The proj string
*/
static QString proj4FromSrsId( int srsId );
static QString projFromSrsId( int srsId );
/**
* Set the QGIS SrsId
@ -754,22 +820,16 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
void setDescription( const QString &description );
/**
* Set the Proj Proj4String.
* \param proj4String Proj4 format specifies
* Set the Proj string.
* \param projString Proj format specifies
* (excluding proj and ellips) that define this CRS.
* \note some content of the PROJ4 string may be stripped off by this
* method due to the parsing of the string by OSRNewSpatialReference .
* For example input:
* +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
* Gets stored in the CRS as:
* +proj=longlat +datum=WGS84 +no_defs
*/
void setProj4String( const QString &proj4String );
void setProjString( const QString &projString );
/**
* Set the WKT string
*/
bool setWktString( const QString &wkt, bool allowProj4Fallback = true );
bool setWktString( const QString &wkt, bool allowProjFallback = true );
/**
* Set this Geographic? flag
@ -791,13 +851,14 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
/**
* Set the projection acronym
* \param projectionAcronym the acronym (must be a valid proj4 projection acronym)
* \param projectionAcronym the acronym (must be a valid Proj projection acronym)
*/
void setProjectionAcronym( const QString &projectionAcronym );
/**
* Set the ellipsoid acronym
* \param ellipsoidAcronym the acronym (must be a valid proj4 ellipsoid acronym)
* \param ellipsoidAcronym the acronym (must be a valid Proj ellipsoid acronym or
* authority:code identifier on Proj version 6+ builds)
*/
void setEllipsoidAcronym( const QString &ellipsoidAcronym );
@ -858,14 +919,14 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
static bool sDisableSrIdCache;
static bool sDisableOgcCache;
static bool sDisableProj4Cache;
static bool sDisableProjCache;
static bool sDisableWktCache;
static bool sDisableSrsIdCache;
static bool sDisableStringCache;
// for tests
static const QHash< QString, QgsCoordinateReferenceSystem > &stringCache();
static const QHash< QString, QgsCoordinateReferenceSystem > &proj4Cache();
static const QHash< QString, QgsCoordinateReferenceSystem > &projCache();
static const QHash< QString, QgsCoordinateReferenceSystem > &ogcCache();
static const QHash< QString, QgsCoordinateReferenceSystem > &wktCache();
static const QHash< long, QgsCoordinateReferenceSystem > &srsIdCache();
@ -910,10 +971,10 @@ inline std::ostream &operator << ( std::ostream &os, const QgsCoordinateReferenc
mySummary += QLatin1String( "Undefined" );
}
mySummary += QLatin1String( "\n\t\tProj4String : " );
if ( !r.toProj4().isNull() )
mySummary += QLatin1String( "\n\t\tProjString : " );
if ( !r.toProj().isNull() )
{
mySummary += r.toProj4();
mySummary += r.toProj();
}
else
{

View File

@ -627,13 +627,13 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
{
QgsMessageLog::logMessage( QObject::tr( "The source spatial reference system (CRS) is not valid. "
"The coordinates can not be reprojected. The CRS is: %1" )
.arg( d->mSourceCRS.toProj4() ), QObject::tr( "CRS" ) );
.arg( d->mSourceCRS.toProj() ), QObject::tr( "CRS" ) );
return;
}
if ( !d->mDestCRS.isValid() )
{
QgsMessageLog::logMessage( QObject::tr( "The destination spatial reference system (CRS) is not valid. "
"The coordinates can not be reprojected. The CRS is: %1" ).arg( d->mDestCRS.toProj4() ), QObject::tr( "CRS" ) );
"The coordinates can not be reprojected. The CRS is: %1" ).arg( d->mDestCRS.toProj() ), QObject::tr( "CRS" ) );
return;
}

View File

@ -171,7 +171,7 @@ bool QgsCoordinateTransformPrivate::initialize()
int destDatumTransform = mDestinationDatumTransform;
bool useDefaultDatumTransform = ( sourceDatumTransform == - 1 && destDatumTransform == -1 );
mSourceProjString = mSourceCRS.toProj4();
mSourceProjString = mSourceCRS.toProj();
if ( !useDefaultDatumTransform )
{
mSourceProjString = stripDatumTransform( mSourceProjString );
@ -181,7 +181,7 @@ bool QgsCoordinateTransformPrivate::initialize()
mSourceProjString += ( ' ' + QgsDatumTransform::datumTransformToProj( sourceDatumTransform ) );
}
mDestProjString = mDestCRS.toProj4();
mDestProjString = mDestCRS.toProj();
if ( !useDefaultDatumTransform )
{
mDestProjString = stripDatumTransform( mDestProjString );
@ -202,8 +202,8 @@ bool QgsCoordinateTransformPrivate::initialize()
ProjData res = threadLocalProjData();
#ifdef COORDINATE_TRANSFORM_VERBOSE
QgsDebugMsg( "From proj : " + mSourceCRS.toProj4() );
QgsDebugMsg( "To proj : " + mDestCRS.toProj4() );
QgsDebugMsg( "From proj : " + mSourceCRS.toProj() );
QgsDebugMsg( "To proj : " + mDestCRS.toProj() );
#endif
#if PROJ_VERSION_MAJOR>=6
@ -240,7 +240,7 @@ bool QgsCoordinateTransformPrivate::initialize()
//XXX todo overload == operator for QgsCoordinateReferenceSystem
//at the moment srs.parameters contains the whole proj def...soon it won't...
//if (mSourceCRS->toProj4() == mDestCRS->toProj4())
//if (mSourceCRS->toProj() == mDestCRS->toProj())
if ( mSourceCRS == mDestCRS )
{
// If the source and destination projection are the same, set the short

View File

@ -324,8 +324,8 @@ double QgsDistanceArea::measureLine( const QgsPointXY &p1, const QgsPointXY &p2
if ( willUseEllipsoid() )
{
QgsDebugMsgLevel( QStringLiteral( "Ellipsoidal calculations is enabled, using ellipsoid %1" ).arg( mEllipsoid ), 4 );
QgsDebugMsgLevel( QStringLiteral( "From proj4 : %1" ).arg( mCoordTransform.sourceCrs().toProj4() ), 4 );
QgsDebugMsgLevel( QStringLiteral( "To proj4 : %1" ).arg( mCoordTransform.destinationCrs().toProj4() ), 4 );
QgsDebugMsgLevel( QStringLiteral( "From proj4 : %1" ).arg( mCoordTransform.sourceCrs().toProj() ), 4 );
QgsDebugMsgLevel( QStringLiteral( "To proj4 : %1" ).arg( mCoordTransform.destinationCrs().toProj() ), 4 );
pp1 = mCoordTransform.transform( p1 );
pp2 = mCoordTransform.transform( p2 );
QgsDebugMsgLevel( QStringLiteral( "New points are %1 and %2, calculating..." ).arg( pp1.toString( 4 ), pp2.toString( 4 ) ), 4 );

View File

@ -324,8 +324,8 @@ QgsEllipsoidUtils::EllipsoidParameters QgsEllipsoidUtils::ellipsoidParameters( c
// get spatial ref system for ellipsoid
QString proj4 = "+proj=longlat +ellps=" + ellipsoid + " +no_defs";
QgsCoordinateReferenceSystem destCRS = QgsCoordinateReferenceSystem::fromProj4( proj4 );
//TODO: createFromProj4 used to save to the user database any new CRS
QgsCoordinateReferenceSystem destCRS = QgsCoordinateReferenceSystem::fromProj( proj4 );
//TODO: createFromProj used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
@ -333,7 +333,7 @@ QgsEllipsoidUtils::EllipsoidParameters QgsEllipsoidUtils::ellipsoidParameters( c
{
QString name = QStringLiteral( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ),
destCRS.toProj4() );
destCRS.toProj() );
destCRS.saveAsUserCrs( name );
}
//
@ -403,11 +403,11 @@ QList<QgsEllipsoidUtils::EllipsoidDefinition> QgsEllipsoidUtils::definitions()
def.parameters.semiMinor = semiMinor;
def.parameters.inverseFlattening = invFlattening;
if ( !semiMinorComputed )
def.parameters.crs = QgsCoordinateReferenceSystem::fromProj4( QStringLiteral( "+proj=longlat +a=%1 +b=%2 +no_defs +type=crs" ).arg( def.parameters.semiMajor, 0, 'g', 17 ).arg( def.parameters.semiMinor, 0, 'g', 17 ) );
def.parameters.crs = QgsCoordinateReferenceSystem::fromProj( QStringLiteral( "+proj=longlat +a=%1 +b=%2 +no_defs +type=crs" ).arg( def.parameters.semiMajor, 0, 'g', 17 ).arg( def.parameters.semiMinor, 0, 'g', 17 ) );
else if ( !qgsDoubleNear( def.parameters.inverseFlattening, 0.0 ) )
def.parameters.crs = QgsCoordinateReferenceSystem::fromProj4( QStringLiteral( "+proj=longlat +a=%1 +rf=%2 +no_defs +type=crs" ).arg( def.parameters.semiMajor, 0, 'g', 17 ).arg( def.parameters.inverseFlattening, 0, 'g', 17 ) );
def.parameters.crs = QgsCoordinateReferenceSystem::fromProj( QStringLiteral( "+proj=longlat +a=%1 +rf=%2 +no_defs +type=crs" ).arg( def.parameters.semiMajor, 0, 'g', 17 ).arg( def.parameters.inverseFlattening, 0, 'g', 17 ) );
else
def.parameters.crs = QgsCoordinateReferenceSystem::fromProj4( QStringLiteral( "+proj=longlat +a=%1 +no_defs +type=crs" ).arg( def.parameters.semiMajor, 0, 'g', 17 ) );
def.parameters.crs = QgsCoordinateReferenceSystem::fromProj( QStringLiteral( "+proj=longlat +a=%1 +no_defs +type=crs" ).arg( def.parameters.semiMajor, 0, 'g', 17 ) );
}
else
{
@ -485,8 +485,9 @@ QList<QgsEllipsoidUtils::EllipsoidDefinition> QgsEllipsoidUtils::definitions()
QStringList QgsEllipsoidUtils::acronyms()
{
QStringList result;
const auto constDefinitions = definitions();
for ( const QgsEllipsoidUtils::EllipsoidDefinition &def : constDefinitions )
const QList<QgsEllipsoidUtils::EllipsoidDefinition> defs = definitions();
result.reserve( defs.size() );
for ( const QgsEllipsoidUtils::EllipsoidDefinition &def : defs )
{
result << def.acronym;
}

View File

@ -1282,9 +1282,9 @@ bool QgsProject::readProjectFile( const QString &filename, QgsProject::ReadFlags
}
// if that didn't produce a match, try the proj.4 string
if ( !projCrsString.isEmpty() && ( !projectCrs.isValid() || projectCrs.toProj4() != projCrsString ) )
if ( !projCrsString.isEmpty() && ( !projectCrs.isValid() || projectCrs.toProj() != projCrsString ) )
{
projectCrs = QgsCoordinateReferenceSystem::fromProj4( projCrsString );
projectCrs = QgsCoordinateReferenceSystem::fromProj( projCrsString );
}
// last just take the given id
@ -1701,7 +1701,7 @@ QgsExpressionContextScope *QgsProject::createExpressionContextScope() const
mProjectScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_home" ), QDir::toNativeSeparators( homePath() ), true, true ) );
QgsCoordinateReferenceSystem projectCrs = crs();
mProjectScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs" ), projectCrs.authid(), true, true ) );
mProjectScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs_definition" ), projectCrs.toProj4(), true, true ) );
mProjectScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs_definition" ), projectCrs.toProj(), true, true ) );
mProjectScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_ellipsoid" ), ellipsoid(), true, true ) );
mProjectScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "_project_transform_context" ), QVariant::fromValue<QgsCoordinateTransformContext>( transformContext() ), true, true ) );

View File

@ -127,7 +127,7 @@ QgsProjectionSelectionTreeWidget::~QgsProjectionSelectionTreeWidget()
// No? Skip this entry
continue;
}
projectionsProj4 << crs.toProj4();
projectionsProj4 << crs.toProj();
projectionsAuthId << crs.authid();
}
settings.setValue( QStringLiteral( "/UI/recentProjectionsProj4" ), projectionsProj4 );
@ -345,7 +345,7 @@ QString QgsProjectionSelectionTreeWidget::selectedProj4String()
long srsId = item->text( QgisCrsIdColumn ).toLong();
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromSrsId( srsId );
return crs.toProj4();
return crs.toProj();
}
QString QgsProjectionSelectionTreeWidget::selectedWktString()

View File

@ -1173,7 +1173,7 @@ void QgsGeorefPluginGui::addRaster( const QString &file )
{
QString authid = mLayer->crs().authid();
mEPSG->setText( authid );
mEPSG->setToolTip( mLayer->crs().toProj4() );
mEPSG->setToolTip( mLayer->crs().toProj() );
}
else
{
@ -1905,7 +1905,7 @@ QString QgsGeorefPluginGui::generateGDALwarpCommand( const QString &resampling,
}
else
{
gdalCommand << QStringLiteral( "-t_srs \"%1\"" ).arg( mProjection.toProj4().simplified() );
gdalCommand << QStringLiteral( "-t_srs \"%1\"" ).arg( mProjection.toProj().simplified() );
}
gdalCommand << QStringLiteral( "\"%1\"" ).arg( mTranslatedRasterFileName ) << QStringLiteral( "\"%1\"" ).arg( mModifiedRasterFileName );

View File

@ -97,7 +97,7 @@ bool QgsImageWarper::createDestinationDataset( const QString &outputName, GDALDa
if ( crs.isValid() )
{
OGRSpatialReference oTargetSRS;
oTargetSRS.importFromProj4( crs.toProj4().toLatin1().data() );
oTargetSRS.importFromProj4( crs.toProj().toLatin1().data() );
char *wkt = nullptr;
OGRErr err = oTargetSRS.exportToWkt( &wkt );

View File

@ -613,7 +613,7 @@ void QgsGrassModule::run()
environment.insert( QStringLiteral( "QGIS_PREFIX_PATH" ), QgsApplication::prefixPath() );
if ( crs.isValid() ) // it should always be valid
{
environment.insert( QStringLiteral( "QGIS_GRASS_CRS" ), crs.toProj4() );
environment.insert( QStringLiteral( "QGIS_GRASS_CRS" ), crs.toProj() );
}
// Suppress debug output
environment.insert( QStringLiteral( "QGIS_DEBUG" ), QStringLiteral( "-1" ) );

View File

@ -407,7 +407,7 @@ void QgsGrassNewMapset::setGrassProjection()
{
setError( mProjErrorLabel );
QString proj4 = mProjectionSelector->crs().toProj4();
QString proj4 = mProjectionSelector->crs().toProj();
// Not defined
if ( mNoProjRadioButton->isChecked() )

View File

@ -206,11 +206,11 @@ int GRASS_LIB_EXPORT QgsGrassGisLib::G__gisinit( const char *version, const char
if ( !crsStr.isEmpty() )
{
if ( !mCrs.createFromProj4( crsStr ) )
if ( !mCrs.createFromProj( crsStr ) )
{
fatal( "Cannot create CRS from QGIS_GRASS_CRS: " + crsStr );
}
//TODO: createFromProj4 used to save to the user database any new CRS
//TODO: createFromProj used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
@ -218,7 +218,7 @@ int GRASS_LIB_EXPORT QgsGrassGisLib::G__gisinit( const char *version, const char
{
QString myName = QString( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
.arg( mCrs.toProj4() );
.arg( mCrs.toProj() );
mCrs.saveAsUserCRS( myName );
}
}
@ -512,8 +512,8 @@ QgsGrassGisLib::Raster QgsGrassGisLib::raster( QString name )
fatal( "Band out of range" );
}
QgsDebugMsg( QString( "mCrs valid = %1 = %2" ).arg( mCrs.isValid() ).arg( mCrs.toProj4() ) );
QgsDebugMsg( QString( "crs valid = %1 = %2" ).arg( raster.provider->crs().isValid() ).arg( raster.provider->crs().toProj4() ) );
QgsDebugMsg( QString( "mCrs valid = %1 = %2" ).arg( mCrs.isValid() ).arg( mCrs.toProj() ) );
QgsDebugMsg( QString( "crs valid = %1 = %2" ).arg( raster.provider->crs().isValid() ).arg( raster.provider->crs().toProj() ) );
if ( mCrs.isValid() )
{
// GDAL provider loads data without CRS as EPSG:4326!!! Verify, it should give

View File

@ -1880,7 +1880,7 @@ QgsVectorLayerExporter::ExportError QgsMssqlProvider::createEmptyLayer( const QS
.arg( auth_name,
auth_srid,
srs.toWkt(),
srs.toProj4() );
srs.toProj() );
if ( !q.exec( sql ) )
{
if ( errorMessage )

View File

@ -4344,7 +4344,7 @@ QgsCoordinateReferenceSystem QgsPostgresProvider::crs() const
QgsPostgresResult result( conn->PQexec( QStringLiteral( "SELECT proj4text FROM spatial_ref_sys WHERE srid=%1" ).arg( srid ) ) );
if ( result.PQresultStatus() == PGRES_TUPLES_OK )
{
srs = QgsCoordinateReferenceSystem::fromProj4( result.PQgetvalue( 0, 0 ) );
srs = QgsCoordinateReferenceSystem::fromProj( result.PQgetvalue( 0, 0 ) );
sCrsCache.insert( srid, srs );
}
}

View File

@ -3610,7 +3610,7 @@ QgsCoordinateReferenceSystem QgsSpatiaLiteProvider::crs() const
QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( mAuthId );
if ( !srs.isValid() )
{
srs = QgsCoordinateReferenceSystem::fromProj4( mProj4text );
srs = QgsCoordinateReferenceSystem::fromProj( mProj4text );
//TODO: createFromProj4 used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
@ -3619,7 +3619,7 @@ QgsCoordinateReferenceSystem QgsSpatiaLiteProvider::crs() const
{
QString myName = QStringLiteral( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ),
srs.toProj4() );
srs.toProj() );
srs.saveAsUserCrs( myName );
}

View File

@ -59,8 +59,8 @@ class TestQgsCoordinateReferenceSystem: public QObject
void createFromSrId();
void fromSrsId();
void srsIdCache();
void createFromProj4();
void fromProj4();
void createFromProj();
void fromProj();
void proj4Cache();
void fromString();
void fromStringCache();
@ -75,12 +75,12 @@ class TestQgsCoordinateReferenceSystem: public QObject
void postgisSrid();
void ellipsoidAcronym();
void toWkt();
void toProj4();
void toProj();
void isGeographic();
void mapUnits();
void setValidationHint();
void hasAxisInverted();
void createFromProj4Invalid();
void createFromProjInvalid();
void validSrsIds();
void asVariant();
void bounds();
@ -197,14 +197,14 @@ void TestQgsCoordinateReferenceSystem::copyCtor()
QgsCoordinateReferenceSystem myCrs2( myCrs );
debugPrint( myCrs2 );
QVERIFY( myCrs2.isValid() );
QCOMPARE( myCrs2.authid(), QString( "EPSG:4326" ) );
QCOMPARE( myCrs2.authid(), QStringLiteral( "EPSG:4326" ) );
//test implicit sharing detachment - modify original
myCrs.createFromId( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QVERIFY( myCrs.isValid() );
QCOMPARE( myCrs.authid(), QString( "EPSG:3111" ) );
QCOMPARE( myCrs.authid(), QStringLiteral( "EPSG:3111" ) );
QVERIFY( myCrs2.isValid() );
QCOMPARE( myCrs2.authid(), QString( "EPSG:4326" ) );
QCOMPARE( myCrs2.authid(), QStringLiteral( "EPSG:4326" ) );
}
void TestQgsCoordinateReferenceSystem::assignmentCtor()
@ -214,14 +214,14 @@ void TestQgsCoordinateReferenceSystem::assignmentCtor()
QgsCoordinateReferenceSystem myCrs2 = myCrs;
debugPrint( myCrs2 );
QVERIFY( myCrs2.isValid() );
QCOMPARE( myCrs2.authid(), QString( "EPSG:4326" ) );
QCOMPARE( myCrs2.authid(), QStringLiteral( "EPSG:4326" ) );
//test implicit sharing detachment - modify original
myCrs.createFromId( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
QVERIFY( myCrs.isValid() );
QCOMPARE( myCrs.authid(), QString( "EPSG:3111" ) );
QCOMPARE( myCrs.authid(), QStringLiteral( "EPSG:3111" ) );
QVERIFY( myCrs2.isValid() );
QCOMPARE( myCrs2.authid(), QString( "EPSG:4326" ) );
QCOMPARE( myCrs2.authid(), QStringLiteral( "EPSG:4326" ) );
}
void TestQgsCoordinateReferenceSystem::createFromId()
@ -267,15 +267,15 @@ void TestQgsCoordinateReferenceSystem::createFromOgcWmsCrs()
myCrs.createFromOgcWmsCrs( QStringLiteral( "EPSG:4326" ) );
QVERIFY( myCrs.isValid() );
QCOMPARE( myCrs.authid(), QString( "EPSG:4326" ) );
QCOMPARE( myCrs.authid(), QStringLiteral( "EPSG:4326" ) );
myCrs.createFromOgcWmsCrs( QStringLiteral( "http://www.opengis.net/def/crs/EPSG/0/4326" ) );
QVERIFY( myCrs.isValid() );
QCOMPARE( myCrs.authid(), QString( "EPSG:4326" ) );
QCOMPARE( myCrs.authid(), QStringLiteral( "EPSG:4326" ) );
myCrs.createFromOgcWmsCrs( QStringLiteral( "urn:ogc:def:crs:EPSG::4326" ) );
QVERIFY( myCrs.isValid() );
QCOMPARE( myCrs.authid(), QString( "EPSG:4326" ) );
QCOMPARE( myCrs.authid(), QStringLiteral( "EPSG:4326" ) );
myCrs.createFromOgcWmsCrs( QStringLiteral( "i am not a CRS" ) );
QVERIFY( !myCrs.isValid() );
@ -284,7 +284,7 @@ void TestQgsCoordinateReferenceSystem::createFromOgcWmsCrs()
QVERIFY( myCrs.isValid() );
QVERIFY( !myCrs.hasAxisInverted() );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( myCrs.authid(), QString( "OGC:CRS84" ) );
QCOMPARE( myCrs.authid(), QStringLiteral( "OGC:CRS84" ) );
#endif
#if PROJ_VERSION_MAJOR>=6
@ -298,7 +298,7 @@ void TestQgsCoordinateReferenceSystem::fromOgcWmsCrs()
{
QgsCoordinateReferenceSystem myCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( QStringLiteral( "EPSG:4326" ) );
QVERIFY( myCrs.isValid() );
QCOMPARE( myCrs.authid(), QString( "EPSG:4326" ) );
QCOMPARE( myCrs.authid(), QStringLiteral( "EPSG:4326" ) );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( myCrs.ellipsoidAcronym(), QStringLiteral( "EPSG:7030" ) );
@ -315,23 +315,23 @@ void TestQgsCoordinateReferenceSystem::ogcWmsCrsCache()
// test that crs can be retrieved correctly from cache
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( QStringLiteral( "EPSG:4326" ) );
QVERIFY( crs.isValid() );
QCOMPARE( crs.authid(), QString( "EPSG:4326" ) );
QVERIFY( QgsCoordinateReferenceSystem::ogcCache().contains( "EPSG:4326" ) );
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:4326" ) );
QVERIFY( QgsCoordinateReferenceSystem::ogcCache().contains( QStringLiteral( "EPSG:4326" ) ) );
// a second time, so crs is fetched from cache
QgsCoordinateReferenceSystem crs2 = QgsCoordinateReferenceSystem::fromOgcWmsCrs( QStringLiteral( "EPSG:4326" ) );
QVERIFY( crs2.isValid() );
QCOMPARE( crs2.authid(), QString( "EPSG:4326" ) );
QCOMPARE( crs2.authid(), QStringLiteral( "EPSG:4326" ) );
// invalid
QgsCoordinateReferenceSystem crs3 = QgsCoordinateReferenceSystem::fromOgcWmsCrs( QStringLiteral( "not a CRS" ) );
QVERIFY( !crs3.isValid() );
QVERIFY( QgsCoordinateReferenceSystem::ogcCache().contains( "not a CRS" ) );
QVERIFY( QgsCoordinateReferenceSystem::ogcCache().contains( QStringLiteral( "not a CRS" ) ) );
// a second time, so invalid crs is fetched from cache
QgsCoordinateReferenceSystem crs4 = QgsCoordinateReferenceSystem::fromOgcWmsCrs( QStringLiteral( "not a CRS" ) );
QVERIFY( !crs4.isValid() );
QgsCoordinateReferenceSystem::invalidateCache();
QVERIFY( !QgsCoordinateReferenceSystem::ogcCache().contains( "EPSG:4326" ) );
QVERIFY( !QgsCoordinateReferenceSystem::ogcCache().contains( QStringLiteral( "EPSG:4326" ) ) );
}
void TestQgsCoordinateReferenceSystem::createFromSrid()
@ -355,13 +355,13 @@ void TestQgsCoordinateReferenceSystem::sridCache()
QgsCoordinateReferenceSystem crs;
crs.createFromSrid( 3112 );
QVERIFY( crs.isValid() );
QCOMPARE( crs.authid(), QString( "EPSG:3112" ) );
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:3112" ) );
QVERIFY( QgsCoordinateReferenceSystem::srIdCache().contains( 3112 ) );
// a second time, so crs is fetched from cache
QgsCoordinateReferenceSystem crs2;
crs2.createFromSrid( 3112 );
QVERIFY( crs2.isValid() );
QCOMPARE( crs2.authid(), QString( "EPSG:3112" ) );
QCOMPARE( crs2.authid(), QStringLiteral( "EPSG:3112" ) );
// invalid
QgsCoordinateReferenceSystem crs3;
@ -487,7 +487,7 @@ void TestQgsCoordinateReferenceSystem::wktCache()
QgsCoordinateReferenceSystem crs3;
crs3.createFromWkt( QStringLiteral( "bad wkt" ) );
QVERIFY( !crs3.isValid() );
QVERIFY( QgsCoordinateReferenceSystem::wktCache().contains( "bad wkt" ) );
QVERIFY( QgsCoordinateReferenceSystem::wktCache().contains( QStringLiteral( "bad wkt" ) ) );
// a second time, so invalid crs is fetched from cache
QgsCoordinateReferenceSystem crs4;
crs4.createFromWkt( QStringLiteral( "bad wkt" ) );
@ -504,13 +504,13 @@ QString TestQgsCoordinateReferenceSystem::testESRIWkt( int i, QgsCoordinateRefer
if ( ! myCrs.isValid() )
return QStringLiteral( "test %1 crs is invalid" );
#if 0
if ( myCrs.toProj4() != myProj4Strings[i] )
if ( myCrs.toProj() != myProj4Strings[i] )
return QString( "test %1 PROJ = [ %2 ] expecting [ %3 ]"
).arg( i ).arg( myCrs.toProj4() ).arg( myProj4Strings[i] );
).arg( i ).arg( myCrs.toProj() ).arg( myProj4Strings[i] );
#endif
if ( myCrs.toProj4().indexOf( myTOWGS84Strings[i] ) == -1 )
if ( myCrs.toProj().indexOf( myTOWGS84Strings[i] ) == -1 )
return QStringLiteral( "test %1 [%2] not found, PROJ = [%3] expecting [%4]"
).arg( i ).arg( myTOWGS84Strings[i], myCrs.toProj4(), myProj4Strings[i] );
).arg( i ).arg( myTOWGS84Strings[i], myCrs.toProj(), myProj4Strings[i] );
if ( myCrs.authid() != myAuthIdStrings[i] )
return QStringLiteral( "test %1 AUTHID = [%2] expecting [%3]"
).arg( i ).arg( myCrs.authid(), myAuthIdStrings[i] );
@ -656,13 +656,13 @@ void TestQgsCoordinateReferenceSystem::srsIdCache()
}
void TestQgsCoordinateReferenceSystem::createFromProj4()
void TestQgsCoordinateReferenceSystem::createFromProj()
{
QgsCoordinateReferenceSystem myCrs;
QVERIFY( !myCrs.createFromProj4( QString() ) );
QVERIFY( !myCrs.createFromProj( QString() ) );
QVERIFY( !myCrs.isValid() );
QVERIFY( myCrs.createFromProj4( geoProj4() ) );
QVERIFY( myCrs.createFromProj( geoProj4() ) );
debugPrint( myCrs );
QVERIFY( myCrs.isValid() );
QCOMPARE( myCrs.srsid(), GEOCRS_ID );
@ -674,17 +674,17 @@ void TestQgsCoordinateReferenceSystem::createFromProj4()
#endif
}
void TestQgsCoordinateReferenceSystem::fromProj4()
void TestQgsCoordinateReferenceSystem::fromProj()
{
QgsCoordinateReferenceSystem myCrs = QgsCoordinateReferenceSystem::fromProj4( geoProj4() );
QgsCoordinateReferenceSystem myCrs = QgsCoordinateReferenceSystem::fromProj( geoProj4() );
debugPrint( myCrs );
QVERIFY( myCrs.isValid() );
QCOMPARE( myCrs.srsid(), GEOCRS_ID );
myCrs = QgsCoordinateReferenceSystem::fromProj4( QString() );
myCrs = QgsCoordinateReferenceSystem::fromProj( QString() );
QVERIFY( !myCrs.isValid() );
myCrs = QgsCoordinateReferenceSystem::fromProj4( "+proj=utm +zone=36 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs" );
myCrs = QgsCoordinateReferenceSystem::fromProj( QStringLiteral( "+proj=utm +zone=36 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs" ) );
QCOMPARE( myCrs.authid(), QStringLiteral( "EPSG:20936" ) );
#if PROJ_VERSION_MAJOR>=6
@ -696,28 +696,28 @@ void TestQgsCoordinateReferenceSystem::proj4Cache()
{
// test that crs can be retrieved correctly from cache
QgsCoordinateReferenceSystem crs;
crs.createFromProj4( geoProj4() );
crs.createFromProj( geoProj4() );
QVERIFY( crs.isValid() );
QCOMPARE( crs.srsid(), GEOCRS_ID );
QVERIFY( QgsCoordinateReferenceSystem::proj4Cache().contains( geoProj4() ) );
QVERIFY( QgsCoordinateReferenceSystem::projCache().contains( geoProj4() ) );
// a second time, so crs is fetched from cache
QgsCoordinateReferenceSystem crs2;
crs2.createFromProj4( geoProj4() );
crs2.createFromProj( geoProj4() );
QVERIFY( crs2.isValid() );
QCOMPARE( crs2.srsid(), GEOCRS_ID );
// invalid
QgsCoordinateReferenceSystem crs3;
crs3.createFromProj4( QStringLiteral( "bad proj4" ) );
crs3.createFromProj( QStringLiteral( "bad proj4" ) );
QVERIFY( !crs3.isValid() );
QVERIFY( QgsCoordinateReferenceSystem::proj4Cache().contains( "bad proj4" ) );
QVERIFY( QgsCoordinateReferenceSystem::projCache().contains( QStringLiteral( "bad proj4" ) ) );
// a second time, so invalid crs is fetched from cache
QgsCoordinateReferenceSystem crs4;
crs4.createFromProj4( QStringLiteral( "bad proj4" ) );
crs4.createFromProj( QStringLiteral( "bad proj4" ) );
QVERIFY( !crs4.isValid() );
QgsCoordinateReferenceSystem::invalidateCache();
QVERIFY( !QgsCoordinateReferenceSystem::proj4Cache().contains( geoProj4() ) );
QVERIFY( !QgsCoordinateReferenceSystem::projCache().contains( geoProj4() ) );
}
void TestQgsCoordinateReferenceSystem::fromString()
@ -754,26 +754,26 @@ void TestQgsCoordinateReferenceSystem::fromStringCache()
QgsCoordinateReferenceSystem crs;
crs.createFromString( QStringLiteral( "EPSG:3113" ) );
QVERIFY( crs.isValid() );
QCOMPARE( crs.authid(), QString( "EPSG:3113" ) );
QVERIFY( QgsCoordinateReferenceSystem::stringCache().contains( "EPSG:3113" ) );
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:3113" ) );
QVERIFY( QgsCoordinateReferenceSystem::stringCache().contains( QStringLiteral( "EPSG:3113" ) ) );
// a second time, so crs is fetched from cache
QgsCoordinateReferenceSystem crs2;
crs2.createFromString( QStringLiteral( "EPSG:3113" ) );
QVERIFY( crs2.isValid() );
QCOMPARE( crs2.authid(), QString( "EPSG:3113" ) );
QCOMPARE( crs2.authid(), QStringLiteral( "EPSG:3113" ) );
// invalid
QgsCoordinateReferenceSystem crs3;
crs3.createFromString( QStringLiteral( "bad string" ) );
QVERIFY( !crs3.isValid() );
QVERIFY( QgsCoordinateReferenceSystem::stringCache().contains( "bad string" ) );
QVERIFY( QgsCoordinateReferenceSystem::stringCache().contains( QStringLiteral( "bad string" ) ) );
// a second time, so invalid crs is fetched from cache
QgsCoordinateReferenceSystem crs4;
crs4.createFromString( QStringLiteral( "bad string" ) );
QVERIFY( !crs4.isValid() );
QgsCoordinateReferenceSystem::invalidateCache();
QVERIFY( !QgsCoordinateReferenceSystem::stringCache().contains( "EPSG:3113" ) );
QVERIFY( !QgsCoordinateReferenceSystem::stringCache().contains( QStringLiteral( "EPSG:3113" ) ) );
}
void TestQgsCoordinateReferenceSystem::isValid()
@ -843,7 +843,7 @@ void TestQgsCoordinateReferenceSystem::readWriteXml()
QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrid( GEOSRID );
QVERIFY( myCrs.isValid() );
QDomDocument document( "test" );
QDomDocument document( QStringLiteral( "test" ) );
QDomElement node = document.createElement( QStringLiteral( "crs" ) );
document.appendChild( node );
@ -866,7 +866,7 @@ void TestQgsCoordinateReferenceSystem::readWriteXml()
// Empty XML made from writeXml operation
QgsCoordinateReferenceSystem myCrs3;
QDomDocument document2( "test" );
QDomDocument document2( QStringLiteral( "test" ) );
QDomElement node2 = document2.createElement( QStringLiteral( "crs" ) );
document2.appendChild( node2 );
QVERIFY( ! myCrs3.isValid() );
@ -877,7 +877,7 @@ void TestQgsCoordinateReferenceSystem::readWriteXml()
QVERIFY( myCrs3 == myCrs4 );
// Empty XML node
QDomDocument document3( "test" );
QDomDocument document3( QStringLiteral( "test" ) );
QDomElement node3 = document3.createElement( QStringLiteral( "crs" ) );
document3.appendChild( node3 );
QgsCoordinateReferenceSystem myCrs5;
@ -893,16 +893,16 @@ void TestQgsCoordinateReferenceSystem::readWriteXml()
QVERIFY( myCrs7.readXml( node ) );
QCOMPARE( myCrs7.authid(), QStringLiteral( "EPSG:3111" ) );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( myCrs7.toProj4(), QStringLiteral( "+proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QCOMPARE( myCrs7.toProj(), QStringLiteral( "+proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QCOMPARE( myCrs7.toWkt(), QStringLiteral( R"""(PROJCS["GDA94 / Vicgrid",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["latitude_of_origin",-37],PARAMETER["central_meridian",145],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["false_easting",2500000],PARAMETER["false_northing",2500000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","3111"]])""" ) );
#else
QCOMPARE( myCrs7.toProj4(), QStringLiteral( "+proj=lcc +lat_1=-36 +lat_2=-38 +lat_0=-37 +lon_0=145 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QCOMPARE( myCrs7.toProj(), QStringLiteral( "+proj=lcc +lat_1=-36 +lat_2=-38 +lat_0=-37 +lon_0=145 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QCOMPARE( myCrs7.toWkt(), QStringLiteral( R"""(PROJCS["GDA94 / Vicgrid",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37],PARAMETER["central_meridian",145],PARAMETER["false_easting",2500000],PARAMETER["false_northing",2500000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","3111"]])""" ) );
#endif
// valid CRS from proj string
QgsCoordinateReferenceSystem myCrs8;
myCrs8.createFromProj4( QStringLiteral( "+proj=aea +lat_1=20 +lat_2=-23 +lat_0=4 +lon_0=29 +x_0=10.123 +y_0=3 +datum=WGS84 +units=m +no_defs" ) );
myCrs8.createFromProj( QStringLiteral( "+proj=aea +lat_1=20 +lat_2=-23 +lat_0=4 +lon_0=29 +x_0=10.123 +y_0=3 +datum=WGS84 +units=m +no_defs" ) );
node = document.createElement( QStringLiteral( "crs" ) );
document.appendChild( node );
QVERIFY( myCrs8.writeXml( node, document ) );
@ -910,18 +910,18 @@ void TestQgsCoordinateReferenceSystem::readWriteXml()
QVERIFY( myCrs9.readXml( node ) );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( myCrs9.toProj4(), QStringLiteral( "+proj=aea +lat_0=4 +lon_0=29 +lat_1=20 +lat_2=-23 +x_0=10.123 +y_0=3 +datum=WGS84 +units=m +no_defs +type=crs" ) );
QCOMPARE( myCrs9.toProj(), QStringLiteral( "+proj=aea +lat_0=4 +lon_0=29 +lat_1=20 +lat_2=-23 +x_0=10.123 +y_0=3 +datum=WGS84 +units=m +no_defs +type=crs" ) );
QCOMPARE( myCrs9.authid(), QStringLiteral( "USER:100003" ) );
QCOMPARE( myCrs9.toWkt(), QStringLiteral( R"""(PROJCS["unknown",GEOGCS["unknown",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]]],PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["latitude_of_center",4],PARAMETER["longitude_of_center",29],PARAMETER["standard_parallel_1",20],PARAMETER["standard_parallel_2",-23],PARAMETER["false_easting",10.123],PARAMETER["false_northing",3],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH]])""" ) );
#else
QCOMPARE( myCrs9.toProj4(), QStringLiteral( "+proj=aea +lat_1=20 +lat_2=-23 +lat_0=4 +lon_0=29 +x_0=10.123 +y_0=3 +datum=WGS84 +units=m +no_defs" ) );
QCOMPARE( myCrs9.toProj(), QStringLiteral( "+proj=aea +lat_1=20 +lat_2=-23 +lat_0=4 +lon_0=29 +x_0=10.123 +y_0=3 +datum=WGS84 +units=m +no_defs" ) );
QCOMPARE( myCrs9.authid(), QStringLiteral( "USER:100002" ) );
QCOMPARE( myCrs9.toWkt(), QStringLiteral( R"""(PROJCS["unnamed",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["standard_parallel_1",20],PARAMETER["standard_parallel_2",-23],PARAMETER["latitude_of_center",4],PARAMETER["longitude_of_center",29],PARAMETER["false_easting",10.123],PARAMETER["false_northing",3],UNIT["Meter",1]])""" ) );
#endif
// valid CRS from WKT string
QgsCoordinateReferenceSystem myCrs10;
myCrs10.createFromWkt( R"""(PROJCS["xxx",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[1,2,3,4,5,6,7],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37.2],PARAMETER["central_meridian",145.1],PARAMETER["false_easting",2510000],PARAMETER["false_northing",2520000],AXIS["Easting",EAST],AXIS["Northing",NORTH]])""" );
myCrs10.createFromWkt( QStringLiteral( R"""(PROJCS["xxx",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[1,2,3,4,5,6,7],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37.2],PARAMETER["central_meridian",145.1],PARAMETER["false_easting",2510000],PARAMETER["false_northing",2520000],AXIS["Easting",EAST],AXIS["Northing",NORTH]])""" ) );
node = document.createElement( QStringLiteral( "crs" ) );
document.appendChild( node );
QVERIFY( myCrs10.writeXml( node, document ) );
@ -929,11 +929,11 @@ void TestQgsCoordinateReferenceSystem::readWriteXml()
QVERIFY( myCrs11.readXml( node ) );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( myCrs11.authid(), QStringLiteral( "USER:100005" ) );
QCOMPARE( myCrs11.toProj4(), QStringLiteral( "+proj=lcc +lat_0=-37.2 +lon_0=145.1 +lat_1=-36 +lat_2=-38 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs +type=crs" ) );
QCOMPARE( myCrs11.toProj(), QStringLiteral( "+proj=lcc +lat_0=-37.2 +lon_0=145.1 +lat_1=-36 +lat_2=-38 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs +type=crs" ) );
QCOMPARE( myCrs11.toWkt(), QStringLiteral( R"""(PROJCS["xxx",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[1,2,3,4,5,6,7],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37.2],PARAMETER["central_meridian",145.1],PARAMETER["false_easting",2510000],PARAMETER["false_northing",2520000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH]])""" ) );
#else
QCOMPARE( myCrs11.authid(), QStringLiteral( "USER:100003" ) );
QCOMPARE( myCrs11.toProj4(), QStringLiteral( "+proj=lcc +lat_1=-36 +lat_2=-38 +lat_0=-37.2 +lon_0=145.1 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs" ) );
QCOMPARE( myCrs11.toProj(), QStringLiteral( "+proj=lcc +lat_1=-36 +lat_2=-38 +lat_0=-37.2 +lon_0=145.1 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs" ) );
QCOMPARE( myCrs11.toWkt(), QStringLiteral( R"""(PROJCS["unnamed",GEOGCS["GRS 1980(IUGG, 1980)",DATUM["unknown",SPHEROID["GRS80",6378137,298.257222101],TOWGS84[1,2,3,4,5,6,7]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37.2],PARAMETER["central_meridian",145.1],PARAMETER["false_easting",2510000],PARAMETER["false_northing",2520000],UNIT["Meter",1]])""" ) );
#endif
@ -942,17 +942,17 @@ void TestQgsCoordinateReferenceSystem::readWriteXml()
QVERIFY( myCrs11b.readXml( node ) );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( myCrs11b.authid(), QStringLiteral( "USER:100005" ) );
QCOMPARE( myCrs11b.toProj4(), QStringLiteral( "+proj=lcc +lat_0=-37.2 +lon_0=145.1 +lat_1=-36 +lat_2=-38 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs +type=crs" ) );
QCOMPARE( myCrs11b.toProj(), QStringLiteral( "+proj=lcc +lat_0=-37.2 +lon_0=145.1 +lat_1=-36 +lat_2=-38 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs +type=crs" ) );
QCOMPARE( myCrs11b.toWkt(), QStringLiteral( R"""(PROJCS["xxx",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[1,2,3,4,5,6,7],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37.2],PARAMETER["central_meridian",145.1],PARAMETER["false_easting",2510000],PARAMETER["false_northing",2520000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH]])""" ) );
#else
QCOMPARE( myCrs11b.authid(), QStringLiteral( "USER:100003" ) );
QCOMPARE( myCrs11b.toProj4(), QStringLiteral( "+proj=lcc +lat_1=-36 +lat_2=-38 +lat_0=-37.2 +lon_0=145.1 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs" ) );
QCOMPARE( myCrs11b.toProj(), QStringLiteral( "+proj=lcc +lat_1=-36 +lat_2=-38 +lat_0=-37.2 +lon_0=145.1 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs" ) );
QCOMPARE( myCrs11b.toWkt(), QStringLiteral( R"""(PROJCS["unnamed",GEOGCS["GRS 1980(IUGG, 1980)",DATUM["unknown",SPHEROID["GRS80",6378137,298.257222101],TOWGS84[1,2,3,4,5,6,7]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37.2],PARAMETER["central_meridian",145.1],PARAMETER["false_easting",2510000],PARAMETER["false_northing",2520000],UNIT["Meter",1]])""" ) );
#endif
// fudge an dom element without the wkt element
QgsCoordinateReferenceSystem myCrs12;
myCrs12.createFromWkt( R"""(PROJCS["xxx",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[1,2,3,4,5,6,7],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37.2],PARAMETER["central_meridian",145.1],PARAMETER["false_easting",2510000],PARAMETER["false_northing",2520000],AXIS["Easting",EAST],AXIS["Northing",NORTH]])""" );
myCrs12.createFromWkt( QStringLiteral( R"""(PROJCS["xxx",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[1,2,3,4,5,6,7],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37.2],PARAMETER["central_meridian",145.1],PARAMETER["false_easting",2510000],PARAMETER["false_northing",2520000],AXIS["Easting",EAST],AXIS["Northing",NORTH]])""" ) );
node = document.createElement( QStringLiteral( "crs" ) );
document.appendChild( node );
QVERIFY( myCrs12.writeXml( node, document ) );
@ -962,17 +962,17 @@ void TestQgsCoordinateReferenceSystem::readWriteXml()
QVERIFY( myCrs13.readXml( node ) );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( myCrs13.authid(), QStringLiteral( "USER:100007" ) );
QCOMPARE( myCrs13.toProj4(), QStringLiteral( "+proj=lcc +lat_0=-37.2 +lon_0=145.1 +lat_1=-36 +lat_2=-38 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs" ) );
QCOMPARE( myCrs13.toProj(), QStringLiteral( "+proj=lcc +lat_0=-37.2 +lon_0=145.1 +lat_1=-36 +lat_2=-38 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs" ) );
QCOMPARE( myCrs13.toWkt(), QStringLiteral( R"""(PROJCS["unknown",GEOGCS["unknown",DATUM["Unknown_based_on_GRS80_ellipsoid",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[1,2,3,4,5,6,7]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["latitude_of_origin",-37.2],PARAMETER["central_meridian",145.1],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["false_easting",2510000],PARAMETER["false_northing",2520000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH]])""" ) );
#else
QCOMPARE( myCrs13.authid(), QStringLiteral( "USER:100003" ) );
QCOMPARE( myCrs13.toProj4(), QStringLiteral( "+proj=lcc +lat_1=-36 +lat_2=-38 +lat_0=-37.2 +lon_0=145.1 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs" ) );
QCOMPARE( myCrs13.toProj(), QStringLiteral( "+proj=lcc +lat_1=-36 +lat_2=-38 +lat_0=-37.2 +lon_0=145.1 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs" ) );
QCOMPARE( myCrs13.toWkt(), QStringLiteral( R"""(PROJCS["unnamed",GEOGCS["GRS 1980(IUGG, 1980)",DATUM["unknown",SPHEROID["GRS80",6378137,298.257222101],TOWGS84[1,2,3,4,5,6,7]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37.2],PARAMETER["central_meridian",145.1],PARAMETER["false_easting",2510000],PARAMETER["false_northing",2520000],UNIT["Meter",1]])""" ) );
#endif
// fudge a dom element with conflicting proj and wkt, wkt should be preferred
QgsCoordinateReferenceSystem myCrs14;
myCrs14.createFromWkt( R"""(PROJCS["xxx",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[1,2,3,4,5,6,7],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37.2],PARAMETER["central_meridian",145.1],PARAMETER["false_easting",2510000],PARAMETER["false_northing",2520000],AXIS["Easting",EAST],AXIS["Northing",NORTH]])""" );
myCrs14.createFromWkt( QStringLiteral( R"""(PROJCS["xxx",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[1,2,3,4,5,6,7],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37.2],PARAMETER["central_meridian",145.1],PARAMETER["false_easting",2510000],PARAMETER["false_northing",2520000],AXIS["Easting",EAST],AXIS["Northing",NORTH]])""" ) );
node = document.createElement( QStringLiteral( "crs" ) );
document.appendChild( node );
QVERIFY( myCrs14.writeXml( node, document ) );
@ -985,11 +985,11 @@ void TestQgsCoordinateReferenceSystem::readWriteXml()
QVERIFY( myCrs15.readXml( node ) );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( myCrs15.authid(), QStringLiteral( "USER:100009" ) );
QCOMPARE( myCrs15.toProj4(), QStringLiteral( "+proj=lcc +lat_0=-37.2 +lon_0=145.1 +lat_1=-36 +lat_2=-38 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs +type=crs" ) );
QCOMPARE( myCrs15.toProj(), QStringLiteral( "+proj=lcc +lat_0=-37.2 +lon_0=145.1 +lat_1=-36 +lat_2=-38 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs +type=crs" ) );
QCOMPARE( myCrs15.toWkt(), QStringLiteral( R"""(PROJCS["xxx",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[1,2,3,4,5,6,7],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37.2],PARAMETER["central_meridian",145.1],PARAMETER["false_easting",2510000],PARAMETER["false_northing",2520000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH]])""" ) );
#else
QCOMPARE( myCrs15.authid(), QStringLiteral( "USER:100003" ) );
QCOMPARE( myCrs15.toProj4(), QStringLiteral( "+proj=lcc +lat_1=-36 +lat_2=-38 +lat_0=-37.2 +lon_0=145.1 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs" ) );
QCOMPARE( myCrs15.toProj(), QStringLiteral( "+proj=lcc +lat_1=-36 +lat_2=-38 +lat_0=-37.2 +lon_0=145.1 +x_0=2510000 +y_0=2520000 +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +units=m +no_defs" ) );
QCOMPARE( myCrs15.toWkt(), QStringLiteral( R"""(PROJCS["unnamed",GEOGCS["GRS 1980(IUGG, 1980)",DATUM["unknown",SPHEROID["GRS80",6378137,298.257222101],TOWGS84[1,2,3,4,5,6,7]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37.2],PARAMETER["central_meridian",145.1],PARAMETER["false_easting",2510000],PARAMETER["false_northing",2520000],UNIT["Meter",1]])""" ) );
#endif
@ -1007,10 +1007,10 @@ void TestQgsCoordinateReferenceSystem::readWriteXml()
QVERIFY( myCrs17.readXml( node ) );
QCOMPARE( myCrs17.authid(), QStringLiteral( "EPSG:3111" ) );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( myCrs17.toProj4(), QStringLiteral( "+proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QCOMPARE( myCrs17.toProj(), QStringLiteral( "+proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QCOMPARE( myCrs17.toWkt(), QStringLiteral( R"""(PROJCS["GDA94 / Vicgrid",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["latitude_of_origin",-37],PARAMETER["central_meridian",145],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["false_easting",2500000],PARAMETER["false_northing",2500000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","3111"]])""" ) );
#else
QCOMPARE( myCrs17.toProj4(), QStringLiteral( "+proj=lcc +lat_1=-36 +lat_2=-38 +lat_0=-37 +lon_0=145 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QCOMPARE( myCrs17.toProj(), QStringLiteral( "+proj=lcc +lat_1=-36 +lat_2=-38 +lat_0=-37 +lon_0=145 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QCOMPARE( myCrs17.toWkt(), QStringLiteral( R"""(PROJCS["GDA94 / Vicgrid",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37],PARAMETER["central_meridian",145],PARAMETER["false_easting",2500000],PARAMETER["false_northing",2500000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","3111"]])""" ) );
#endif
@ -1028,10 +1028,10 @@ void TestQgsCoordinateReferenceSystem::readWriteXml()
QVERIFY( myCrs19.readXml( node ) );
QCOMPARE( myCrs19.authid(), QStringLiteral( "EPSG:3111" ) );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( myCrs19.toProj4(), QStringLiteral( "+proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QCOMPARE( myCrs19.toProj(), QStringLiteral( "+proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QCOMPARE( myCrs19.toWkt(), QStringLiteral( R"""(PROJCS["GDA94 / Vicgrid",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["latitude_of_origin",-37],PARAMETER["central_meridian",145],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["false_easting",2500000],PARAMETER["false_northing",2500000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","3111"]])""" ) );
#else
QCOMPARE( myCrs19.toProj4(), QStringLiteral( "+proj=lcc +lat_1=-36 +lat_2=-38 +lat_0=-37 +lon_0=145 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QCOMPARE( myCrs19.toProj(), QStringLiteral( "+proj=lcc +lat_1=-36 +lat_2=-38 +lat_0=-37 +lon_0=145 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" ) );
QCOMPARE( myCrs19.toWkt(), QStringLiteral( R"""(PROJCS["GDA94 / Vicgrid",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4283"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",-36],PARAMETER["standard_parallel_2",-38],PARAMETER["latitude_of_origin",-37],PARAMETER["central_meridian",145],PARAMETER["false_easting",2500000],PARAMETER["false_northing",2500000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","3111"]])""" ) );
#endif
}
@ -1095,14 +1095,14 @@ void TestQgsCoordinateReferenceSystem::toWkt()
qDebug() << "stripped: " << myStrippedWkt;
QVERIFY( myWkt == myStrippedWkt );
}
void TestQgsCoordinateReferenceSystem::toProj4()
void TestQgsCoordinateReferenceSystem::toProj()
{
QgsCoordinateReferenceSystem myCrs;
myCrs.createFromSrid( GEOSRID );
debugPrint( myCrs );
//first proj string produced by gdal 1.8-1.9
//second by gdal 1.7
QCOMPARE( myCrs.toProj4(), geoProj4() );
QCOMPARE( myCrs.toProj(), geoProj4() );
}
void TestQgsCoordinateReferenceSystem::isGeographic()
{
@ -1136,7 +1136,7 @@ void TestQgsCoordinateReferenceSystem::setValidationHint()
{
QgsCoordinateReferenceSystem myCrs;
myCrs.setValidationHint( QStringLiteral( "<head>" ) );
QVERIFY( myCrs.validationHint() == "<head>" );
QVERIFY( myCrs.validationHint() == QLatin1String( "<head>" ) );
debugPrint( myCrs );
}
@ -1160,12 +1160,12 @@ void TestQgsCoordinateReferenceSystem::debugPrint(
QgsCoordinateReferenceSystem &crs )
{
QgsDebugMsg( QStringLiteral( "***SpatialRefSystem***" ) );
QgsDebugMsg( "* Valid : " + ( crs.isValid() ? QString( "true" ) :
QString( "false" ) ) );
QgsDebugMsg( "* Valid : " + ( crs.isValid() ? QStringLiteral( "true" ) :
QStringLiteral( "false" ) ) );
QgsDebugMsg( "* SrsId : " + QString::number( crs.srsid() ) );
QgsDebugMsg( "* EPSG ID : " + crs.authid() );
QgsDebugMsg( "* PGIS ID : " + QString::number( crs.postgisSrid() ) );
QgsDebugMsg( "* Proj4 : " + crs.toProj4() );
QgsDebugMsg( "* Proj4 : " + crs.toProj() );
QgsDebugMsg( "* WKT : " + crs.toWkt() );
QgsDebugMsg( "* Desc. : " + crs.description() );
if ( crs.mapUnits() == QgsUnitTypes::DistanceMeters )
@ -1182,10 +1182,10 @@ void TestQgsCoordinateReferenceSystem::debugPrint(
}
}
void TestQgsCoordinateReferenceSystem::createFromProj4Invalid()
void TestQgsCoordinateReferenceSystem::createFromProjInvalid()
{
QgsCoordinateReferenceSystem myCrs;
QVERIFY( !myCrs.createFromProj4( "+proj=longlat +no_defs" ) );
QVERIFY( !myCrs.createFromProj( QStringLiteral( "+proj=longlat +no_defs" ) ) );
}
void TestQgsCoordinateReferenceSystem::validSrsIds()
@ -1227,35 +1227,35 @@ void TestQgsCoordinateReferenceSystem::bounds()
QgsCoordinateReferenceSystem invalid;
QVERIFY( invalid.bounds().isNull() );
QgsCoordinateReferenceSystem crs3111( "EPSG:3111" );
QgsCoordinateReferenceSystem crs3111( QStringLiteral( "EPSG:3111" ) );
QgsRectangle bounds = crs3111.bounds();
QGSCOMPARENEAR( bounds.xMinimum(), 140.960000, 0.0001 );
QGSCOMPARENEAR( bounds.xMaximum(), 150.040000, 0.0001 );
QGSCOMPARENEAR( bounds.yMinimum(), -39.200000, 0.0001 );
QGSCOMPARENEAR( bounds.yMaximum(), -33.980000, 0.0001 );
QgsCoordinateReferenceSystem crs28356( "EPSG:28356" );
QgsCoordinateReferenceSystem crs28356( QStringLiteral( "EPSG:28356" ) );
bounds = crs28356.bounds();
QGSCOMPARENEAR( bounds.xMinimum(), 150.000000, 0.0001 );
QGSCOMPARENEAR( bounds.xMaximum(), 156.000000, 0.0001 );
QGSCOMPARENEAR( bounds.yMinimum(), -58.960000, 0.0001 );
QGSCOMPARENEAR( bounds.yMaximum(), -13.870000, 0.0001 );
QgsCoordinateReferenceSystem crs3857( "EPSG:3857" );
QgsCoordinateReferenceSystem crs3857( QStringLiteral( "EPSG:3857" ) );
bounds = crs3857.bounds();
QGSCOMPARENEAR( bounds.xMinimum(), -180.000000, 0.0001 );
QGSCOMPARENEAR( bounds.xMaximum(), 180.000000, 0.0001 );
QGSCOMPARENEAR( bounds.yMinimum(), -85.060000, 0.0001 );
QGSCOMPARENEAR( bounds.yMaximum(), 85.060000, 0.0001 );
QgsCoordinateReferenceSystem crs4326( "EPSG:4326" );
QgsCoordinateReferenceSystem crs4326( QStringLiteral( "EPSG:4326" ) );
bounds = crs4326.bounds();
QGSCOMPARENEAR( bounds.xMinimum(), -180.000000, 0.0001 );
QGSCOMPARENEAR( bounds.xMaximum(), 180.000000, 0.0001 );
QGSCOMPARENEAR( bounds.yMinimum(), -90.00000, 0.0001 );
QGSCOMPARENEAR( bounds.yMaximum(), 90.00000, 0.0001 );
QgsCoordinateReferenceSystem crs2163( "EPSG:2163" );
QgsCoordinateReferenceSystem crs2163( QStringLiteral( "EPSG:2163" ) );
bounds = crs2163.bounds();
QGSCOMPARENEAR( bounds.xMinimum(), 167.65000, 0.0001 );
QGSCOMPARENEAR( bounds.xMaximum(), -65.69000, 0.0001 );
@ -1266,9 +1266,9 @@ void TestQgsCoordinateReferenceSystem::bounds()
void TestQgsCoordinateReferenceSystem::saveAsUserCrs()
{
QString madeUpProjection = QStringLiteral( "+proj=aea +lat_1=20 +lat_2=-23 +lat_0=4 +lon_0=29 +x_0=10 +y_0=3 +datum=WGS84 +units=m +no_defs" );
QgsCoordinateReferenceSystem userCrs = QgsCoordinateReferenceSystem::fromProj4( madeUpProjection );
QgsCoordinateReferenceSystem userCrs = QgsCoordinateReferenceSystem::fromProj( madeUpProjection );
QVERIFY( userCrs.isValid() );
QCOMPARE( userCrs.toProj4(), madeUpProjection );
QCOMPARE( userCrs.toProj(), madeUpProjection );
QCOMPARE( userCrs.srsid(), 0L ); // not saved to database yet
long newId = userCrs.saveAsUserCrs( QStringLiteral( "babies first projection" ) );
@ -1278,9 +1278,9 @@ void TestQgsCoordinateReferenceSystem::saveAsUserCrs()
QCOMPARE( userCrs.description(), QStringLiteral( "babies first projection" ) );
// new CRS with same definition, check that it's matched to user crs
QgsCoordinateReferenceSystem userCrs2 = QgsCoordinateReferenceSystem::fromProj4( madeUpProjection );
QgsCoordinateReferenceSystem userCrs2 = QgsCoordinateReferenceSystem::fromProj( madeUpProjection );
QVERIFY( userCrs2.isValid() );
QCOMPARE( userCrs2.toProj4(), madeUpProjection );
QCOMPARE( userCrs2.toProj(), madeUpProjection );
QCOMPARE( userCrs2.srsid(), userCrs.srsid() );
QCOMPARE( userCrs2.authid(), QStringLiteral( "USER:100000" ) );
QCOMPARE( userCrs2.description(), QStringLiteral( "babies first projection" ) );
@ -1289,8 +1289,8 @@ void TestQgsCoordinateReferenceSystem::saveAsUserCrs()
QgsCoordinateReferenceSystem userCrs3;
userCrs3.createFromString( QStringLiteral( "USER:100000" ) );
QVERIFY( userCrs3.isValid() );
QCOMPARE( userCrs3.authid(), QString( "USER:100000" ) );
QCOMPARE( userCrs3.toProj4(), madeUpProjection );
QCOMPARE( userCrs3.authid(), QStringLiteral( "USER:100000" ) );
QCOMPARE( userCrs3.toProj(), madeUpProjection );
QCOMPARE( userCrs3.description(), QStringLiteral( "babies first projection" ) );
}
@ -1301,7 +1301,7 @@ void TestQgsCoordinateReferenceSystem::projectWithCustomCrs()
QSignalSpy spyCrsChanged( &p, &QgsProject::crsChanged );
QVERIFY( p.read( TEST_DATA_DIR + QStringLiteral( "/projects/custom_crs.qgs" ) ) );
QVERIFY( p.crs().isValid() );
QCOMPARE( p.crs().toProj4(), QStringLiteral( "+proj=ortho +lat_0=42.1 +lon_0=12.8 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs" ) );
QCOMPARE( p.crs().toProj(), QStringLiteral( "+proj=ortho +lat_0=42.1 +lon_0=12.8 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs" ) );
QCOMPARE( spyCrsChanged.count(), 1 );
}
@ -1355,11 +1355,11 @@ void TestQgsCoordinateReferenceSystem::noProj()
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:2218" ) );
QVERIFY( crs.isValid() );
QCOMPARE( crs.toWkt(), QStringLiteral( "PROJCS[\"Scoresbysund 1952 / Greenland zone 5 east\",GEOGCS[\"Scoresbysund 1952\",DATUM[\"Scoresbysund_1952\",SPHEROID[\"International 1924\",6378388,297,AUTHORITY[\"EPSG\",\"7022\"]],AUTHORITY[\"EPSG\",\"6195\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4195\"]],PROJECTION[\"Lambert_Conic_Conformal_(West_Orientated)\"],PARAMETER[\"Latitude of natural origin\",70.5],PARAMETER[\"Longitude of natural origin\",-24],PARAMETER[\"Scale factor at natural origin\",1],PARAMETER[\"False easting\",0],PARAMETER[\"False northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"2218\"]]" ) );
crs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( "ESRI:54091" );
crs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( QStringLiteral( "ESRI:54091" ) );
QCOMPARE( crs.authid(), QStringLiteral( "ESRI:54091" ) );
QVERIFY( crs.isValid() );
QCOMPARE( crs.toWkt(), QStringLiteral( "PROJCS[\"WGS_1984_Peirce_quincuncial_North_Pole_diamond\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Peirce_Quincuncial\"],PARAMETER[\"False_Easting\",0],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",0],PARAMETER[\"Scale_Factor\",1],PARAMETER[\"Latitude_Of_Origin\",90],PARAMETER[\"Option\",1],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH],AUTHORITY[\"ESRI\",\"54091\"]]" ) );
crs = QgsCoordinateReferenceSystem( "EPSG:22300" );
crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:22300" ) );
QCOMPARE( crs.authid(), QStringLiteral( "EPSG:22300" ) );
QVERIFY( crs.isValid() );
QCOMPARE( crs.toWkt(), QStringLiteral( "PROJCS[\"Carthage (Paris) / Tunisia Mining Grid\",GEOGCS[\"Carthage (Paris)\",DATUM[\"Carthage_Paris\",SPHEROID[\"Clarke 1880 (IGN)\",6378249.2,293.466021293627,AUTHORITY[\"EPSG\",\"7011\"]],AUTHORITY[\"EPSG\",\"6816\"]],PRIMEM[\"Paris\",2.33722916999999,AUTHORITY[\"EPSG\",\"8903\"]],UNIT[\"grad\",0.0157079632679489,AUTHORITY[\"EPSG\",\"9105\"]],AUTHORITY[\"EPSG\",\"4816\"]],PROJECTION[\"Tunisia_Mapping_Grid\"],PARAMETER[\"latitude_of_origin\",36.5964],PARAMETER[\"central_meridian\",7.83445],PARAMETER[\"false_easting\",270],PARAMETER[\"false_northing\",360],UNIT[\"kilometre\",1000,AUTHORITY[\"EPSG\",\"9036\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH],AUTHORITY[\"EPSG\",\"22300\"]]" ) ); //#spellok
@ -1370,9 +1370,9 @@ void TestQgsCoordinateReferenceSystem::noProj()
void TestQgsCoordinateReferenceSystem::customProjString()
{
#if PROJ_VERSION_MAJOR>=6
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromProj4( QStringLiteral( "+proj=sterea +lat_0=47.4860018439082 +lon_0=19.0491441390302 +k=1 +x_0=500000 +y_0=500000 +ellps=bessel +towgs84=595.75,121.09,515.50,8.2270,-1.5193,5.5971,-2.6729 +units=m +vunits=m +no_defs" ) );
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromProj( QStringLiteral( "+proj=sterea +lat_0=47.4860018439082 +lon_0=19.0491441390302 +k=1 +x_0=500000 +y_0=500000 +ellps=bessel +towgs84=595.75,121.09,515.50,8.2270,-1.5193,5.5971,-2.6729 +units=m +vunits=m +no_defs" ) );
QVERIFY( crs.isValid() );
QCOMPARE( crs.toProj4(), QStringLiteral( "+proj=sterea +lat_0=47.4860018439082 +lon_0=19.0491441390302 +k=1 +x_0=500000 +y_0=500000 +ellps=bessel +towgs84=595.75,121.09,515.50,8.2270,-1.5193,5.5971,-2.6729 +units=m +vunits=m +no_defs" ) );
QCOMPARE( crs.toProj(), QStringLiteral( "+proj=sterea +lat_0=47.4860018439082 +lon_0=19.0491441390302 +k=1 +x_0=500000 +y_0=500000 +ellps=bessel +towgs84=595.75,121.09,515.50,8.2270,-1.5193,5.5971,-2.6729 +units=m +vunits=m +no_defs" ) );
QCOMPARE( crs.toWkt(), QStringLiteral( R"""(COMPD_CS["unknown",PROJCS["unknown",GEOGCS["unknown",DATUM["Unknown_based_on_Bessel_1841_ellipsoid",SPHEROID["Bessel 1841",6377397.155,299.1528128],TOWGS84[595.75,121.09,515.5,8.227,-1.5193,5.5971,-2.6729]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]]],PROJECTION["Oblique_Stereographic"],PARAMETER["latitude_of_origin",47.4860018439082],PARAMETER["central_meridian",19.0491441390302],PARAMETER["scale_factor",1],PARAMETER["false_easting",500000],PARAMETER["false_northing",500000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH]],VERT_CS["unknown",VERT_DATUM["unknown",2005],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Gravity-related height",UP]]])""" ) );
#endif
}

View File

@ -613,7 +613,7 @@ void TestQgsCoordinateTransform::testCustomProjTransform()
#if PROJ_VERSION_MAJOR >= 6
// test custom proj string
// refs https://github.com/qgis/QGIS/issues/32928
QgsCoordinateReferenceSystem ss( QgsCoordinateReferenceSystem::fromProj4( QStringLiteral( "+proj=sterea +lat_0=47.4860018439082 +lon_0=19.0491441390302 +k=1 +x_0=500000 +y_0=500000 +ellps=bessel +towgs84=595.75,121.09,515.50,8.2270,-1.5193,5.5971,-2.6729 +units=m +vunits=m +no_defs" ) ) );
QgsCoordinateReferenceSystem ss( QgsCoordinateReferenceSystem::fromProj( QStringLiteral( "+proj=sterea +lat_0=47.4860018439082 +lon_0=19.0491441390302 +k=1 +x_0=500000 +y_0=500000 +ellps=bessel +towgs84=595.75,121.09,515.50,8.2270,-1.5193,5.5971,-2.6729 +units=m +vunits=m +no_defs" ) ) );
QgsCoordinateReferenceSystem dd( QStringLiteral( "EPSG:23700" ) );
QgsCoordinateTransform ct( ss, dd, QgsCoordinateTransformContext() );
QVERIFY( ct.isValid() );

View File

@ -44,9 +44,9 @@ class TestQgsDistanceArea(unittest.TestCase):
self.assertFalse(da.ellipsoidCrs().isValid())
da.setEllipsoid("GRS80")
# depends on proj version
self.assertIn(da.ellipsoidCrs().toProj4(), ('+proj=longlat +ellps=GRS80 +no_defs', '+proj=longlat +a=6378137 +rf=298.25722210100002 +no_defs'))
self.assertIn(da.ellipsoidCrs().toProj(), ('+proj=longlat +ellps=GRS80 +no_defs', '+proj=longlat +a=6378137 +rf=298.25722210100002 +no_defs'))
da.setEllipsoid("WGS84")
self.assertIn(da.ellipsoidCrs().toProj4(), ('+proj=longlat +ellps=WGS84 +no_defs', '+proj=longlat +a=6378137 +rf=298.25722356300003 +no_defs'))
self.assertIn(da.ellipsoidCrs().toProj(), ('+proj=longlat +ellps=WGS84 +no_defs', '+proj=longlat +a=6378137 +rf=298.25722356300003 +no_defs'))
def testMeasureLine(self):
# +-+
@ -79,7 +79,7 @@ class TestQgsDistanceArea(unittest.TestCase):
da_wsg84.setEllipsoid(da_wsg84.sourceCrs().ellipsoidAcronym())
self.assertEqual(da_wsg84.sourceCrs().authid(), 'EPSG:4326')
print(("setting [{}] srid [{}] description [{}] isGeographic[{}]".format(u'Wsg84', da_wsg84.sourceCrs().authid(), da_wsg84.sourceCrs().description(), da_wsg84.sourceCrs().isGeographic())))
# print(("-- projectionAcronym[{}] ellipsoidAcronym[{}] toWkt[{}] mapUnits[{}] toProj4[{}]".format(da_wsg84.sourceCrs().projectionAcronym(),da_wsg84.sourceCrs().ellipsoidAcronym(), da_wsg84.sourceCrs().toWkt(),da_wsg84.sourceCrs().mapUnits(),da_wsg84.sourceCrs().toProj4())))
# print(("-- projectionAcronym[{}] ellipsoidAcronym[{}] toWkt[{}] mapUnits[{}] toProj4[{}]".format(da_wsg84.sourceCrs().projectionAcronym(),da_wsg84.sourceCrs().ellipsoidAcronym(), da_wsg84.sourceCrs().toWkt(),da_wsg84.sourceCrs().mapUnits(),da_wsg84.sourceCrs().toProj())))
print(("Testing Position change for[{}] years[{}]".format(u'Ampelanlage - Potsdamer Platz, Verkehrsinsel', u'1924 and 1998')))
# 1924-10-24 SRID=3068;POINT(23099.49 20296.69)

View File

@ -37,7 +37,7 @@ class TestQgsEllipsoidUtils(unittest.TestCase):
if QgsProjUtils.projVersionMajor() < 6:
self.assertEqual(params.crs.authid(), 'EPSG:4030')
else:
self.assertEqual(params.crs.toProj4(), '+proj=longlat +a=6378137 +rf=298.25722356300003 +no_defs')
self.assertEqual(params.crs.toProj(), '+proj=longlat +a=6378137 +rf=298.25722356300003 +no_defs')
for i in range(2):
params = QgsEllipsoidUtils.ellipsoidParameters("Ganymede2000")
@ -49,7 +49,7 @@ class TestQgsEllipsoidUtils(unittest.TestCase):
if QgsProjUtils.projVersionMajor() < 6:
self.assertEqual(params.crs.authid(), '')
else:
self.assertEqual(params.crs.toProj4(), '+proj=longlat +a=2632345 +no_defs')
self.assertEqual(params.crs.toProj(), '+proj=longlat +a=2632345 +no_defs')
if QgsProjUtils.projVersionMajor() >= 6:
params = QgsEllipsoidUtils.ellipsoidParameters("ESRI:107916")
@ -58,7 +58,7 @@ class TestQgsEllipsoidUtils(unittest.TestCase):
self.assertEqual(params.semiMinor, 2632345.0)
self.assertEqual(params.inverseFlattening, 0)
self.assertFalse(params.useCustomParameters)
self.assertEqual(params.crs.toProj4(), '+proj=longlat +a=2632345 +no_defs')
self.assertEqual(params.crs.toProj(), '+proj=longlat +a=2632345 +no_defs')
params = QgsEllipsoidUtils.ellipsoidParameters("EPSG:7001")
self.assertTrue(params.valid)
@ -66,7 +66,7 @@ class TestQgsEllipsoidUtils(unittest.TestCase):
self.assertEqual(params.semiMinor, 6356256.909237285)
self.assertEqual(params.inverseFlattening, 299.3249646)
self.assertFalse(params.useCustomParameters)
self.assertEqual(params.crs.toProj4(),
self.assertEqual(params.crs.toProj(),
'+proj=longlat +a=6377563.3959999997 +rf=299.32496459999999 +no_defs')
params = QgsEllipsoidUtils.ellipsoidParameters("EPSG:7008")
@ -75,7 +75,7 @@ class TestQgsEllipsoidUtils(unittest.TestCase):
self.assertEqual(params.semiMinor, 6356583.8)
self.assertEqual(params.inverseFlattening, 294.9786982138982)
self.assertFalse(params.useCustomParameters)
self.assertEqual(params.crs.toProj4(),
self.assertEqual(params.crs.toProj(),
'+proj=longlat +a=6378206.4000000004 +b=6356583.7999999998 +no_defs')
# using parameters

View File

@ -507,7 +507,7 @@ class TestQgsSymbol(unittest.TestCase):
painter = QPainter()
ms = QgsMapSettings()
crs = QgsCoordinateReferenceSystem.fromProj4('+proj=ortho +lat_0=36.5 +lon_0=-118.8 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs')
crs = QgsCoordinateReferenceSystem.fromProj('+proj=ortho +lat_0=36.5 +lon_0=-118.8 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs')
self.assertTrue(crs.isValid())
ms.setDestinationCrs(crs)
ms.setExtent(QgsRectangle(1374999.8, 3912610.7, 4724462.5, 6505499.6))