Skip to content
Permalink
Browse files
Remove more proj4 api usage
  • Loading branch information
nyalldawson committed Apr 15, 2019
1 parent d3f6a5f commit 018f3bc19bbffb3958aba8e3f13208b9589d78da
Showing with 19 additions and 4 deletions.
  1. +19 −4 src/core/qgscoordinatereferencesystem.cpp
@@ -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>
@@ -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
@@ -1144,6 +1157,8 @@ void QgsCoordinateReferenceSystem::setProj4String( const QString &proj4String )
pj_free( proj );
}
pj_ctx_free( pContext );
#endif

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

1 comment on commit 018f3bc

@PeterPetrik

This comment has been minimized.

Copy link
Contributor

@PeterPetrik PeterPetrik commented on 018f3bc Apr 25, 2019

this commit broken build with proj6

Please sign in to comment.