Skip to content

Commit

Permalink
Refactor to extract useful method
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 3, 2019
1 parent eeeda4b commit d754a09
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 34 deletions.
1 change: 1 addition & 0 deletions python/core/auto_generated/qgsdatumtransform.sip.in
Expand Up @@ -160,6 +160,7 @@ If ``datumTransformId`` was not a valid transform ID, a TransformInfo with Trans
.. deprecated:: Not used for builds based on Proj >= 6.0
%End


};

/************************************************************************
Expand Down
81 changes: 47 additions & 34 deletions src/core/qgsdatumtransform.cpp
Expand Up @@ -45,44 +45,19 @@ QList<QgsDatumTransform::TransformDetails> QgsDatumTransform::operations( const
// See https://lists.osgeo.org/pipermail/proj/2019-May/008604.html
proj_operation_factory_context_set_spatial_criterion( pjContext, operationContext, PROJ_SPATIAL_CRITERION_PARTIAL_INTERSECTION );

PJ_OBJ_LIST *ops = proj_create_operations( pjContext, source.projObject(), destination.projObject(), operationContext );
int count = proj_list_get_count( ops );
for ( int i = 0; i < count; ++i )
if ( PJ_OBJ_LIST *ops = proj_create_operations( pjContext, source.projObject(), destination.projObject(), operationContext ) )
{
QgsProjUtils::proj_pj_unique_ptr op( proj_list_get( pjContext, ops, i ) );
if ( !op )
continue;

TransformDetails details;
details.proj = QString( proj_as_proj_string( pjContext, op.get(), PJ_PROJ_5, nullptr ) );
details.name = QString( proj_get_name( op.get() ) );
details.accuracy = proj_coordoperation_get_accuracy( pjContext, op.get() );
details.isAvailable = proj_coordoperation_is_instantiable( pjContext, op.get() );

for ( int j = 0; j < proj_coordoperation_get_grid_used_count( pjContext, op.get() ); ++j )
int count = proj_list_get_count( ops );
for ( int i = 0; i < count; ++i )
{
const char *shortName = nullptr;
const char *fullName = nullptr;
const char *packageName = nullptr;
const char *url = nullptr;
int directDownload = 0;
int openLicense = 0;
int isAvailable = 0;
proj_coordoperation_get_grid_used( pjContext, op.get(), j, &shortName, &fullName, &packageName, &url, &directDownload, &openLicense, &isAvailable );
GridDetails gridDetails;
gridDetails.shortName = QString( shortName );
gridDetails.fullName = QString( fullName );
gridDetails.packageName = QString( packageName );
gridDetails.url = QString( url );
gridDetails.directDownload = directDownload;
gridDetails.openLicense = openLicense;
gridDetails.isAvailable = isAvailable;

details.grids.append( gridDetails );
QgsProjUtils::proj_pj_unique_ptr op( proj_list_get( pjContext, ops, i ) );
if ( !op )
continue;

res.push_back( transformDetailsFromPj( op.get() ) );
}
res.push_back( details );
proj_list_destroy( ops );
}
proj_list_destroy( ops );
proj_operation_factory_context_destroy( operationContext );
#endif
return res;
Expand Down Expand Up @@ -329,3 +304,41 @@ QgsDatumTransform::TransformInfo QgsDatumTransform::datumTransformInfo( int datu

return info;
}

#if PROJ_VERSION_MAJOR >= 6
QgsDatumTransform::TransformDetails QgsDatumTransform::transformDetailsFromPj( PJ *op )
{
PJ_CONTEXT *pjContext = QgsProjContext::get();
TransformDetails details;
if ( !op )
return details;

details.proj = QString( proj_as_proj_string( pjContext, op, PJ_PROJ_5, nullptr ) );
details.name = QString( proj_get_name( op ) );
details.accuracy = proj_coordoperation_get_accuracy( pjContext, op );
details.isAvailable = proj_coordoperation_is_instantiable( pjContext, op );

for ( int j = 0; j < proj_coordoperation_get_grid_used_count( pjContext, op ); ++j )
{
const char *shortName = nullptr;
const char *fullName = nullptr;
const char *packageName = nullptr;
const char *url = nullptr;
int directDownload = 0;
int openLicense = 0;
int isAvailable = 0;
proj_coordoperation_get_grid_used( pjContext, op, j, &shortName, &fullName, &packageName, &url, &directDownload, &openLicense, &isAvailable );
GridDetails gridDetails;
gridDetails.shortName = QString( shortName );
gridDetails.fullName = QString( fullName );
gridDetails.packageName = QString( packageName );
gridDetails.url = QString( url );
gridDetails.directDownload = directDownload;
gridDetails.openLicense = openLicense;
gridDetails.isAvailable = isAvailable;

details.grids.append( gridDetails );
}
return details;
}
#endif
19 changes: 19 additions & 0 deletions src/core/qgsdatumtransform.h
Expand Up @@ -24,6 +24,12 @@

class QgsCoordinateReferenceSystem;

#if PROJ_VERSION_MAJOR>=6
#ifndef SIP_RUN
struct PJconsts;
typedef struct PJconsts PJ;
#endif
#endif

/**
* Contains methods and classes relating the datum transformations.
Expand Down Expand Up @@ -227,6 +233,19 @@ class CORE_EXPORT QgsDatumTransform
*/
Q_DECL_DEPRECATED static QgsDatumTransform::TransformInfo datumTransformInfo( int datumTransformId ) SIP_DEPRECATED;

#ifndef SIP_RUN
#if PROJ_VERSION_MAJOR >= 6

/**
* Returns the transform details for a Proj coordinate operation \a op.
*
* \since QGIS 3.8
* \note Requires Proj 6.0 or later
*/
static QgsDatumTransform::TransformDetails transformDetailsFromPj( PJ *op );
#endif
#endif

private:

static void searchDatumTransform( const QString &sql, QList< int > &transforms );
Expand Down

0 comments on commit d754a09

Please sign in to comment.