Skip to content

Commit

Permalink
Remove more proj4 api usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 15, 2019
1 parent d3f6a5f commit 018f3bc
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -37,10 +37,12 @@
#include "qgssettings.h"

#include <sqlite3.h>
#ifndef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
#endif
#if PROJ_VERSION_MAJOR>=6
#include "qgsprojutils.h"
#include <proj.h>
#else
#include <proj_api.h>
#endif

//gdal and ogr includes (needed for == operator)
#include <ogr_srs_api.h>
Expand Down Expand Up @@ -1127,7 +1129,18 @@ void QgsCoordinateReferenceSystem::setProj4String( const QString &proj4String )

OSRDestroySpatialReference( d->mCRS );
d->mCRS = OSRNewSpatialReference( nullptr );
d->mIsValid = OSRImportFromProj4( d->mCRS, proj4String.trimmed().toLatin1().constData() ) == OGRERR_NONE;
const QString trimmed = proj4String.trimmed();
d->mIsValid = OSRImportFromProj4( d->mCRS, trimmed.toLatin1().constData() ) == OGRERR_NONE;
#if PROJ_VERSION_MAJOR>=6
PJ_CONTEXT *ctx = QgsProjContext::get();
QgsProjUtils::proj_pj_unique_ptr proj( proj_create( ctx, trimmed.toLatin1().constData() ) );
if ( !proj )
{
const int errNo = proj_context_errno( ctx );
QgsDebugMsg( QStringLiteral( "proj string rejected: %1" ).arg( proj_errno_string( errNo ) ) );
d->mIsValid = false;
}
#else
// OSRImportFromProj4() may accept strings that are not valid proj.4 strings,
// e.g if they lack a +ellps parameter, it will automatically add +ellps=WGS84, but as
// we use the original mProj4 with QgsCoordinateTransform, it will fail to initialize
Expand All @@ -1144,6 +1157,8 @@ void QgsCoordinateReferenceSystem::setProj4String( const QString &proj4String )
pj_free( proj );
}
pj_ctx_free( pContext );
#endif

d->mWkt.clear();
setMapUnits();
}
Expand Down

1 comment on commit 018f3bc

@PeterPetrik
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this commit broken build with proj6

Please sign in to comment.