Proj < 6 updates

This commit is contained in:
Nyall Dawson 2019-12-17 15:50:33 +10:00
parent 59a2cf1424
commit e64a6acd38

View File

@ -45,6 +45,9 @@
#include <proj_api.h> #include <proj_api.h>
#endif #endif
#include "qgsogrutils.h"
#include <ogr_srs_api.h>
QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget *parent, Qt::WindowFlags fl ) QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget *parent, Qt::WindowFlags fl )
: QDialog( parent, fl ) : QDialog( parent, fl )
{ {
@ -615,22 +618,50 @@ void QgsCustomProjectionDialog::validateCurrent()
proj_context_destroy( context ); proj_context_destroy( context );
context = nullptr; context = nullptr;
#else #else
projCtx pContext = pj_ctx_alloc(); switch ( static_cast< Format >( mFormatComboBox->currentData().toInt() ) )
projPJ proj = pj_init_plus_ctx( pContext, projDef.toLocal8Bit().data() ); {
case Format::Wkt:
{
QByteArray ba = projDef.toLatin1();
const char *pWkt = ba.data();
OGRSpatialReferenceH crs = OSRNewSpatialReference( nullptr );
if ( proj ) OGRErr myInputResult = OSRImportFromWkt( crs, const_cast< char ** >( & pWkt ) );
{ if ( myInputResult == OGRERR_NONE )
QMessageBox::information( this, tr( "Custom Coordinate Reference System" ), {
tr( "This proj projection definition is valid." ) ); QMessageBox::information( this, tr( "Custom Coordinate Reference System" ),
} tr( "This WKT projection definition is valid." ) );
else }
{ else
QMessageBox::warning( this, tr( "Custom Coordinate Reference System" ), {
tr( "This proj projection definition is not valid" ) ); QMessageBox::warning( this, tr( "Custom Coordinate Reference System" ),
tr( "This WKT projection definition is not valid." ) );
}
OSRDestroySpatialReference( crs );
break;
}
case Format::Proj:
{
projCtx pContext = pj_ctx_alloc();
projPJ proj = pj_init_plus_ctx( pContext, projDef.toLocal8Bit().data() );
if ( proj )
{
QMessageBox::information( this, tr( "Custom Coordinate Reference System" ),
tr( "This proj projection definition is valid." ) );
}
else
{
QMessageBox::warning( this, tr( "Custom Coordinate Reference System" ),
tr( "This proj projection definition is not valid" ) );
}
pj_free( proj );
pj_ctx_free( pContext );
break;
}
} }
pj_free( proj );
pj_ctx_free( pContext );
#endif #endif
} }
@ -668,6 +699,14 @@ void QgsCustomProjectionDialog::pbnCalculate_clicked()
QString projDef = teParameters->toPlainText(); QString projDef = teParameters->toPlainText();
QgsDebugMsgLevel( QStringLiteral( "Proj: %1" ).arg( projDef ), 3 ); QgsDebugMsgLevel( QStringLiteral( "Proj: %1" ).arg( projDef ), 3 );
#else #else
if ( static_cast< Format >( mFormatComboBox->currentData().toInt() ) == Format::Wkt )
{
// it's not trivial to implement, and we've gotta draw the line somewhere...
QMessageBox::warning( this, tr( "Custom Coordinate Reference System" ),
tr( "Testing WKT based CRS definitions requires Proj version 6 or later." ) );
return;
}
projCtx pContext = pj_ctx_alloc(); projCtx pContext = pj_ctx_alloc();
projPJ proj = pj_init_plus_ctx( pContext, teParameters->toPlainText().toLocal8Bit().data() ); projPJ proj = pj_init_plus_ctx( pContext, teParameters->toPlainText().toLocal8Bit().data() );
QgsDebugMsgLevel( QStringLiteral( "Proj: %1" ).arg( teParameters->toPlainText() ), 3 ); QgsDebugMsgLevel( QStringLiteral( "Proj: %1" ).arg( teParameters->toPlainText() ), 3 );