[QGIS Commit] r15527 - trunk/qgis/src/providers/ogr
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu Mar 17 07:46:25 EDT 2011
Author: jef
Date: 2011-03-17 04:46:25 -0700 (Thu, 17 Mar 2011)
New Revision: 15527
Modified:
trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
trunk/qgis/src/providers/ogr/qgsogrprovider.h
Log:
heck, fix #3620
Modified: trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
===================================================================
--- trunk/qgis/src/providers/ogr/qgsogrprovider.cpp 2011-03-17 08:58:10 UTC (rev 15526)
+++ trunk/qgis/src/providers/ogr/qgsogrprovider.cpp 2011-03-17 11:46:25 UTC (rev 15527)
@@ -1807,6 +1807,44 @@
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." );
@@ -1827,30 +1865,15 @@
QString myWktString = prjStream.readLine();
prjFile.close();
- // create CRS from Wkt
- srs.createFromWkt( myWktString );
-
- if ( srs.isValid() )
+ if ( crsFromWkt( srs, myWktString.toUtf8().constData() ) )
return srs;
}
}
}
OGRSpatialReferenceH mySpatialRefSys = OGR_L_GetSpatialRef( ogrLayer );
- if ( mySpatialRefSys == NULL )
+ if ( mySpatialRefSys )
{
- QgsDebugMsg( "no spatial reference found" );
- }
- else if ( OSRAutoIdentifyEPSG( mySpatialRefSys ) == OGRERR_NONE )
- {
- QString authid = QString( "%1:%2" )
- .arg( OSRGetAuthorityName( mySpatialRefSys, NULL ) )
- .arg( OSRGetAuthorityCode( mySpatialRefSys, NULL ) );
- QgsDebugMsg( "authid recognized as " + authid );
- srs.createFromOgcWmsCrs( authid );
- }
- else
- {
// get the proj4 text
char *pszProj4;
OSRExportToProj4( mySpatialRefSys, &pszProj4 );
@@ -1859,12 +1882,13 @@
char *pszWkt = NULL;
OSRExportToWkt( mySpatialRefSys, &pszWkt );
- QString myWktString = QString( pszWkt );
+ crsFromWkt( srs, pszWkt );
OGRFree( pszWkt );
-
- // create CRS from Wkt
- srs.createFromWkt( myWktString );
}
+ else
+ {
+ QgsDebugMsg( "no spatial reference found" );
+ }
return srs;
}
Modified: trunk/qgis/src/providers/ogr/qgsogrprovider.h
===================================================================
--- trunk/qgis/src/providers/ogr/qgsogrprovider.h 2011-03-17 08:58:10 UTC (rev 15526)
+++ trunk/qgis/src/providers/ogr/qgsogrprovider.h 2011-03-17 11:46:25 UTC (rev 15527)
@@ -255,6 +255,7 @@
void setRelevantFields( bool fetchGeometry, const QgsAttributeList& fetchAttributes );
private:
+ bool crsFromWkt( QgsCoordinateReferenceSystem &srs, const char *wkt );
unsigned char *getGeometryPointer( OGRFeatureH fet );
QgsFieldMap mAttributeFields;
OGRDataSourceH ogrDataSource;
More information about the QGIS-commit
mailing list