Skip to content

Commit

Permalink
when intializing from WKT favourize EPSG instead of PROJ.4
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Nov 7, 2011
1 parent 4b12e5c commit acae4d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 41 deletions.
9 changes: 9 additions & 0 deletions src/core/qgscoordinatereferencesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
43 changes: 3 additions & 40 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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." );
Expand All @@ -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;
}
}
Expand All @@ -2095,7 +2057,8 @@ QgsCoordinateReferenceSystem QgsOgrProvider::crs()

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

srs.createFromWkt( pszWkt );
OGRFree( pszWkt );
}
else
Expand Down
1 change: 0 additions & 1 deletion src/providers/ogr/qgsogrprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit acae4d6

Please sign in to comment.