25 QList< QgsDatumTransform::TransformPair > transformations;
30 if ( srcGeoId.isEmpty() || destGeoId.isEmpty() )
32 return transformations;
35 QStringList srcSplit = srcGeoId.split(
':' );
36 QStringList destSplit = destGeoId.split(
':' );
38 if ( srcSplit.size() < 2 || destSplit.size() < 2 )
40 return transformations;
43 int srcAuthCode = srcSplit.at( 1 ).toInt();
44 int destAuthCode = destSplit.at( 1 ).toInt();
46 if ( srcAuthCode == destAuthCode )
48 return transformations;
51 QList<int> directTransforms;
52 searchDatumTransform( QStringLiteral(
"SELECT coord_op_code FROM tbl_datum_transform WHERE source_crs_code=%1 AND target_crs_code=%2 ORDER BY deprecated ASC,preferred DESC" ).arg( srcAuthCode ).arg( destAuthCode ),
54 QList<int> reverseDirectTransforms;
55 searchDatumTransform( QStringLiteral(
"SELECT coord_op_code FROM tbl_datum_transform WHERE source_crs_code = %1 AND target_crs_code=%2 ORDER BY deprecated ASC,preferred DESC" ).arg( destAuthCode ).arg( srcAuthCode ),
56 reverseDirectTransforms );
57 QList<int> srcToWgs84;
58 searchDatumTransform( QStringLiteral(
"SELECT coord_op_code FROM tbl_datum_transform WHERE (source_crs_code=%1 AND target_crs_code=%2) OR (source_crs_code=%2 AND target_crs_code=%1) ORDER BY deprecated ASC,preferred DESC" ).arg( srcAuthCode ).arg( 4326 ),
60 QList<int> destToWgs84;
61 searchDatumTransform( QStringLiteral(
"SELECT coord_op_code FROM tbl_datum_transform WHERE (source_crs_code=%1 AND target_crs_code=%2) OR (source_crs_code=%2 AND target_crs_code=%1) ORDER BY deprecated ASC,preferred DESC" ).arg( destAuthCode ).arg( 4326 ),
65 for (
int transform : qgis::as_const( directTransforms ) )
71 for (
int transform : qgis::as_const( reverseDirectTransforms ) )
76 for (
int srcTransform : qgis::as_const( srcToWgs84 ) )
78 for (
int destTransform : qgis::as_const( destToWgs84 ) )
84 return transformations;
87 void QgsDatumTransform::searchDatumTransform(
const QString &sql, QList< int > &transforms )
91 if ( openResult != SQLITE_OK )
98 statement = database.
prepare( sql, prepareRes );
99 if ( prepareRes != SQLITE_OK )
105 while ( statement.
step() == SQLITE_ROW )
108 transforms.push_back( cOpCode.toInt() );
114 QString transformString;
118 if ( openResult != SQLITE_OK )
120 return transformString;
124 QString sql = QStringLiteral(
"SELECT coord_op_method_code,p1,p2,p3,p4,p5,p6,p7 FROM tbl_datum_transform WHERE coord_op_code=%1" ).arg( datumTransform );
126 statement = database.
prepare( sql, prepareRes );
127 if ( prepareRes != SQLITE_OK )
129 return transformString;
132 if ( statement.
step() == SQLITE_ROW )
136 if ( methodCode == 9615 )
138 transformString =
"+nadgrids=" + statement.
columnAsText( 1 );
140 else if ( methodCode == 9603 || methodCode == 9606 || methodCode == 9607 )
142 transformString += QLatin1String(
"+towgs84=" );
150 if ( methodCode == 9603 )
152 transformString += QStringLiteral(
"%1,%2,%3" ).arg( QString::number( p1 ), QString::number( p2 ), QString::number( p3 ) );
156 transformString += QStringLiteral(
"%1,%2,%3,%4,%5,%6,%7" ).arg( QString::number( p1 ), QString::number( p2 ), QString::number( p3 ), QString::number( p4 ), QString::number( p5 ), QString::number( p6 ), QString::number( p7 ) );
161 return transformString;
168 if ( openResult != SQLITE_OK )
174 QString sql = QStringLiteral(
"SELECT coord_op_method_code,p1,p2,p3,p4,p5,p6,p7,coord_op_code FROM tbl_datum_transform" );
176 statement = database.
prepare( sql, prepareRes );
177 if ( prepareRes != SQLITE_OK )
182 while ( statement.
step() == SQLITE_ROW )
184 QString transformString;
187 if ( methodCode == 9615 )
189 transformString =
"+nadgrids=" + statement.
columnAsText( 1 );
191 else if ( methodCode == 9603 || methodCode == 9606 || methodCode == 9607 )
193 transformString += QLatin1String(
"+towgs84=" );
201 if ( methodCode == 9603 )
203 transformString += QStringLiteral(
"%1,%2,%3" ).arg( QString::number( p1 ), QString::number( p2 ), QString::number( p3 ) );
207 transformString += QStringLiteral(
"%1,%2,%3,%4,%5,%6,%7" ).arg( QString::number( p1 ), QString::number( p2 ), QString::number( p3 ), QString::number( p4 ), QString::number( p5 ), QString::number( p6 ), QString::number( p7 ) );
211 if ( transformString.compare(
string, Qt::CaseInsensitive ) == 0 )
226 if ( openResult != SQLITE_OK )
232 QString sql = QStringLiteral(
"SELECT epsg_nr,source_crs_code,target_crs_code,remarks,scope,preferred,deprecated FROM tbl_datum_transform WHERE coord_op_code=%1" ).arg( datumTransform );
234 statement = database.
prepare( sql, prepareRes );
235 if ( prepareRes != SQLITE_OK )
240 int srcCrsId, destCrsId;
241 if ( statement.
step() != SQLITE_ROW )
QString geographicCrsAuthId() const
Returns auth id of related geographic CRS.
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
int step()
Steps to the next record in the statement, returning the sqlite3 result code.
QString description() const
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
QString columnAsText(int column) const
Returns the column value from the current statement row as a string.
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
int open_v2(const QString &path, int flags, const char *zVfs)
Opens the database at the specified file path.
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
This class represents a coordinate reference system (CRS).
static QString srsDatabaseFilePath()
Returns the path to the srs.db file.
double columnAsDouble(int column) const
Get column value from the current statement row as a double.
qlonglong columnAsInt64(int column) const
Get column value from the current statement row as a long long integer (64 bits). ...
QString authid() const
Returns the authority identifier for the CRS.