Skip to content
Permalink
Browse files

use GDAL_FIX_ESRI_WKT=GEOGCS instead of TOWGS84 and maintain user-def…

…ined value
  • Loading branch information
etiennesky authored and jef-n committed May 28, 2012
1 parent ae753b8 commit dfe4a9334aa135814d1eae81fd3a964727be3c16
@@ -137,6 +137,14 @@ bool QgsCoordinateReferenceSystem::createFromUserInput( const QString theDefinit
char *wkt = NULL;
OGRSpatialReferenceH crs = OSRNewSpatialReference( NULL );

// make sure towgs84 parameter is loaded if using an ESRI definition and gdal >= 1.9
#if GDAL_VERSION_NUM >= 1900
if ( theDefinition.startsWith( "ESRI::" ) )
{
setupESRIWktFix();
}
#endif

if ( OSRSetFromUserInput( crs, theDefinition.toLocal8Bit().constData() ) == OGRERR_NONE )
{
if ( OSRExportToWkt( crs, &wkt ) == OGRERR_NONE )
@@ -146,10 +154,31 @@ bool QgsCoordinateReferenceSystem::createFromUserInput( const QString theDefinit
}
OSRDestroySpatialReference( crs );
}
QgsDebugMsg( "theDefinition: " + theDefinition + " theWkt = " + theWkt );
//QgsDebugMsg( "theDefinition: " + theDefinition + " theWkt = " + theWkt );
return createFromWkt( theWkt );
}

void QgsCoordinateReferenceSystem::setupESRIWktFix( )
{
// make sure towgs84 parameter is loaded if gdal >= 1.9
// this requires setting GDAL_FIX_ESRI_WKT=GEOGCS (see qgis bug #5598 and gdal bug #4673)
#if GDAL_VERSION_NUM >= 1900
const char* configOld = CPLGetConfigOption( "GDAL_FIX_ESRI_WKT", "" );
const char* configNew = "GEOGCS";
// only set if it was not set, to let user change the value if needed
if ( strcmp( configOld, "" ) == 0 )
{
CPLSetConfigOption( "GDAL_FIX_ESRI_WKT", configNew );
if ( strcmp( configNew, CPLGetConfigOption( "GDAL_FIX_ESRI_WKT", "" ) ) != 0 )
QgsLogger::warning( QString( "GDAL_FIX_ESRI_WKT could not be set to %1 : %2"
).arg( configNew ).arg( CPLGetConfigOption( "GDAL_FIX_ESRI_WKT", "" ) ) ) ;
QgsDebugMsg( QString( "set GDAL_FIX_ESRI_WKT : %1" ).arg( configNew ) );
}
else
QgsDebugMsg( QString( "GDAL_FIX_ESRI_WKT was already set : %1" ).arg( configNew ) );
#endif
}

bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs( QString theCrs )
{
QRegExp re( "(user|custom|qgis):(\\d+)", Qt::CaseInsensitive );
@@ -186,6 +186,17 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
*/
bool createFromUserInput( const QString theDefinition );

/*! Make sure that ESRI WKT import is done properly.
* This is required for proper shapefile CRS import when using gdal>= 1.9.
* @note This function is called by createFromUserInput() and QgsOgrProvider::crs(), there is usually
* no need to call it from elsewhere.
* @note This function sets CPL config option GDAL_FIX_ESRI_WKT to a proper value,
* unless it has been set by the user through the commandline or an environment variable.
* For more details refer to OGRSpatialReference::morphFromESRI() .
* @note added in 1.8
*/
static void setupESRIWktFix();

/*! Find out whether this CRS is correctly initialised and usable */
bool isValid() const;

@@ -2157,7 +2157,8 @@ QgsCoordinateReferenceSystem QgsOgrProvider::crs()
}
}

CPLSetConfigOption( "GDAL_FIX_ESRI_WKT", "TOWGS84" ); // add towgs84 parameter
// add towgs84 parameter
QgsCoordinateReferenceSystem::setupESRIWktFix();

OGRSpatialReferenceH mySpatialRefSys = OGR_L_GetSpatialRef( ogrLayer );
if ( mySpatialRefSys )

0 comments on commit dfe4a93

Please sign in to comment.
You can’t perform that action at this time.