Skip to content
Permalink
Browse files

when intializing from WKT favourize EPSG instead of PROJ.4

  • Loading branch information
jef-n committed Nov 7, 2011
1 parent 4b12e5c commit acae4d6b43459b48c8d03ac86d4d1c0d30634262
@@ -314,6 +314,15 @@ bool QgsCoordinateReferenceSystem::createFromWkt( QString theWkt )
return mIsValidFlag;
}

if ( OSRAutoIdentifyEPSG( mCRS ) == OGRERR_NONE )
{
QString authid = QString( "%1:%2" )
.arg( OSRGetAuthorityName( mCRS, NULL ) )
.arg( OSRGetAuthorityCode( mCRS, NULL ) );
QgsDebugMsg( "authid recognized as " + authid );
return createFromOgcWmsCrs( authid );
}

// always morph from esri as it doesn't hurt anything
// FW: Hey, that's not right! It can screw stuff up! Disable
//myOgrSpatialRef.morphFromESRI();
@@ -2020,44 +2020,6 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
return true;
}

bool QgsOgrProvider::crsFromWkt( QgsCoordinateReferenceSystem &srs, const char *wkt )
{
void *hCRS = OSRNewSpatialReference( NULL );

if ( OSRImportFromWkt( hCRS, ( char ** ) &wkt ) == OGRERR_NONE )
{
if ( OSRAutoIdentifyEPSG( hCRS ) == OGRERR_NONE )
{
QString authid = QString( "%1:%2" )
.arg( OSRGetAuthorityName( hCRS, NULL ) )
.arg( OSRGetAuthorityCode( hCRS, NULL ) );
QgsDebugMsg( "authid recognized as " + authid );
srs.createFromOgcWmsCrs( authid );
}
else
{
// get the proj4 text
char *pszProj4;
OSRExportToProj4( hCRS, &pszProj4 );
QgsDebugMsg( pszProj4 );
OGRFree( pszProj4 );

char *pszWkt = NULL;
OSRExportToWkt( hCRS, &pszWkt );
QString myWktString = QString( pszWkt );
OGRFree( pszWkt );

// create CRS from Wkt
srs.createFromWkt( myWktString );
}
}

OSRRelease( hCRS );

return srs.isValid();
}


QgsCoordinateReferenceSystem QgsOgrProvider::crs()
{
QgsDebugMsg( "entering." );
@@ -2078,7 +2040,7 @@ QgsCoordinateReferenceSystem QgsOgrProvider::crs()
QString myWktString = prjStream.readLine();
prjFile.close();

if ( crsFromWkt( srs, myWktString.toUtf8().constData() ) )
if ( srs.createFromWkt( myWktString.toUtf8().constData() ) )
return srs;
}
}
@@ -2095,7 +2057,8 @@ QgsCoordinateReferenceSystem QgsOgrProvider::crs()

char *pszWkt = NULL;
OSRExportToWkt( mySpatialRefSys, &pszWkt );
crsFromWkt( srs, pszWkt );

srs.createFromWkt( pszWkt );
OGRFree( pszWkt );
}
else
@@ -296,7 +296,6 @@ class QgsOgrProvider : public QgsVectorDataProvider
static bool convertField( QgsField &field, const QTextCodec &encoding );

private:
bool crsFromWkt( QgsCoordinateReferenceSystem &srs, const char *wkt );
unsigned char *getGeometryPointer( OGRFeatureH fet );
QgsFieldMap mAttributeFields;
OGRDataSourceH ogrDataSource;

0 comments on commit acae4d6

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