23 #if PROJ_VERSION_MAJOR>=6 30 QList< QgsDatumTransform::TransformDetails > res;
31 #if PROJ_VERSION_MAJOR<6 33 Q_UNUSED( destination )
35 if ( !source.projObject() || !destination.projObject() )
40 PJ_OPERATION_FACTORY_CONTEXT *operationContext = proj_create_operation_factory_context( pjContext,
nullptr );
43 proj_operation_factory_context_set_grid_availability_use( pjContext, operationContext, PROJ_GRID_AVAILABILITY_IGNORED );
46 proj_operation_factory_context_set_spatial_criterion( pjContext, operationContext, PROJ_SPATIAL_CRITERION_PARTIAL_INTERSECTION );
48 if ( PJ_OBJ_LIST *ops = proj_create_operations( pjContext, source.projObject(), destination.projObject(), operationContext ) )
50 int count = proj_list_get_count( ops );
51 for (
int i = 0; i < count; ++i )
53 QgsProjUtils::proj_pj_unique_ptr op( proj_list_get( pjContext, ops, i ) );
57 res.push_back( transformDetailsFromPj( op.get() ) );
59 proj_list_destroy( ops );
61 proj_operation_factory_context_destroy( operationContext );
68 QList< QgsDatumTransform::TransformPair > transformations;
73 if ( srcGeoId.isEmpty() || destGeoId.isEmpty() )
75 return transformations;
78 QStringList srcSplit = srcGeoId.split(
':' );
79 QStringList destSplit = destGeoId.split(
':' );
81 if ( srcSplit.size() < 2 || destSplit.size() < 2 )
83 return transformations;
86 int srcAuthCode = srcSplit.at( 1 ).toInt();
87 int destAuthCode = destSplit.at( 1 ).toInt();
89 if ( srcAuthCode == destAuthCode )
91 return transformations;
94 QList<int> directTransforms;
95 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 ),
97 QList<int> reverseDirectTransforms;
98 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 ),
99 reverseDirectTransforms );
100 QList<int> srcToWgs84;
101 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 ),
103 QList<int> destToWgs84;
104 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 ),
108 for (
int transform : qgis::as_const( directTransforms ) )
114 for (
int transform : qgis::as_const( reverseDirectTransforms ) )
119 for (
int srcTransform : qgis::as_const( srcToWgs84 ) )
121 for (
int destTransform : qgis::as_const( destToWgs84 ) )
127 return transformations;
130 void QgsDatumTransform::searchDatumTransform(
const QString &sql, QList< int > &transforms )
134 if ( openResult != SQLITE_OK )
141 statement = database.
prepare( sql, prepareRes );
142 if ( prepareRes != SQLITE_OK )
148 while ( statement.
step() == SQLITE_ROW )
151 transforms.push_back( cOpCode.toInt() );
157 QString transformString;
161 if ( openResult != SQLITE_OK )
163 return transformString;
167 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 );
169 statement = database.
prepare( sql, prepareRes );
170 if ( prepareRes != SQLITE_OK )
172 return transformString;
175 if ( statement.
step() == SQLITE_ROW )
179 if ( methodCode == 9615 )
181 transformString =
"+nadgrids=" + statement.
columnAsText( 1 );
183 else if ( methodCode == 9603 || methodCode == 9606 || methodCode == 9607 )
185 transformString += QLatin1String(
"+towgs84=" );
193 if ( methodCode == 9603 )
195 transformString += QStringLiteral(
"%1,%2,%3" ).arg( QString::number( p1 ), QString::number( p2 ), QString::number( p3 ) );
199 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 ) );
204 return transformString;
211 if ( openResult != SQLITE_OK )
217 QString sql = QStringLiteral(
"SELECT coord_op_method_code,p1,p2,p3,p4,p5,p6,p7,coord_op_code FROM tbl_datum_transform" );
219 statement = database.
prepare( sql, prepareRes );
220 if ( prepareRes != SQLITE_OK )
225 while ( statement.
step() == SQLITE_ROW )
227 QString transformString;
230 if ( methodCode == 9615 )
232 transformString =
"+nadgrids=" + statement.
columnAsText( 1 );
234 else if ( methodCode == 9603 || methodCode == 9606 || methodCode == 9607 )
236 transformString += QLatin1String(
"+towgs84=" );
244 if ( methodCode == 9603 )
246 transformString += QStringLiteral(
"%1,%2,%3" ).arg( QString::number( p1 ), QString::number( p2 ), QString::number( p3 ) );
250 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 ) );
254 if ( transformString.compare(
string, Qt::CaseInsensitive ) == 0 )
269 if ( openResult != SQLITE_OK )
275 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 );
277 statement = database.
prepare( sql, prepareRes );
278 if ( prepareRes != SQLITE_OK )
283 int srcCrsId, destCrsId;
284 if ( statement.
step() != SQLITE_ROW )
308 #if PROJ_VERSION_MAJOR >= 6 316 QgsProjUtils::proj_pj_unique_ptr normalized( proj_normalize_for_visualization( pjContext, op ) );
318 details.
proj = QString( proj_as_proj_string( pjContext, normalized.get(), PJ_PROJ_5, nullptr ) );
320 if ( details.
proj.isEmpty() )
321 details.
proj = QString( proj_as_proj_string( pjContext, op, PJ_PROJ_5,
nullptr ) );
322 details.
name = QString( proj_get_name( op ) );
323 details.
accuracy = proj_coordoperation_get_accuracy( pjContext, op );
324 details.
isAvailable = proj_coordoperation_is_instantiable( pjContext, op );
326 for (
int j = 0; j < proj_coordoperation_get_grid_used_count( pjContext, op ); ++j )
328 const char *shortName =
nullptr;
329 const char *fullName =
nullptr;
330 const char *packageName =
nullptr;
331 const char *url =
nullptr;
332 int directDownload = 0;
335 proj_coordoperation_get_grid_used( pjContext, op, j, &shortName, &fullName, &packageName, &url, &directDownload, &openLicense, &isAvailable );
337 gridDetails.
shortName = QString( shortName );
338 gridDetails.
fullName = QString( fullName );
340 gridDetails.
url = QString( url );
345 details.
grids.append( gridDetails );
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.
static PJ_CONTEXT * get()
Returns a thread local instance of a proj context, safe for use in the current thread.
double columnAsDouble(int column) const
Gets column value from the current statement row as a double.
qlonglong columnAsInt64(int column) const
Gets column value from the current statement row as a long long integer (64 bits).
QString authid() const
Returns the authority identifier for the CRS.