[QGIS Commit] r12274 - in trunk/qgis/src: core providers/ogr
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Nov 28 11:11:04 EST 2009
Author: jef
Date: 2009-11-28 11:11:04 -0500 (Sat, 28 Nov 2009)
New Revision: 12274
Modified:
trunk/qgis/src/core/qgsvectorfilewriter.cpp
trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
Log:
shapefile projection fix: save the real projection in .qpj next to the .prj file (fixes #2123 and #2154)
Modified: trunk/qgis/src/core/qgsvectorfilewriter.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorfilewriter.cpp 2009-11-28 16:02:15 UTC (rev 12273)
+++ trunk/qgis/src/core/qgsvectorfilewriter.cpp 2009-11-28 16:11:04 UTC (rev 12274)
@@ -95,15 +95,15 @@
}
// datasource created, now create the output layer
- QString layerName = shapefileName.left( shapefileName.lastIndexOf( ".shp", Qt::CaseInsensitive ) );
+ QString layerName = shapefileName.left( shapefileName.indexOf( ".shp", Qt::CaseInsensitive ) );
OGRwkbGeometryType wkbType = static_cast<OGRwkbGeometryType>( geometryType );
mLayer = OGR_DS_CreateLayer( mDS, QFile::encodeName( layerName ).data(), ogrRef, wkbType, NULL );
if ( srs )
{
- if ( shapefileName != layerName )
+ if ( driverName == "ESRI Shapefile" )
{
- QFile prjFile( layerName + ".prj" );
+ QFile prjFile( layerName + ".qpj" );
if ( prjFile.open( QIODevice::WriteOnly ) )
{
QTextStream prjStream( &prjFile );
@@ -112,7 +112,7 @@
}
else
{
- QgsDebugMsg( "Couldn't open file " + layerName + ".prj" );
+ QgsDebugMsg( "Couldn't open file " + layerName + ".qpj" );
}
}
@@ -420,10 +420,10 @@
// TODO: should be case-insensitive
//
QString myFileBase = theFileName.replace( ".shp", "" );
- bool ok = TRUE;
+ bool ok = true;
- const char* suffixes[] = { ".shp", ".shx", ".dbf", ".prj", ".qix" };
- for ( std::size_t i = 0; i < sizeof( suffixes ) / sizeof( char* ); i++ )
+ const char *suffixes[] = { ".shp", ".shx", ".dbf", ".prj", ".qix", ".qpj" };
+ for ( std::size_t i = 0; i < sizeof( suffixes ) / sizeof( *suffixes ); i++ )
{
QString file = myFileBase + suffixes[i];
QFileInfo myInfo( file );
@@ -432,7 +432,7 @@
if ( !QFile::remove( file ) )
{
QgsDebugMsg( "Removing file failed : " + file );
- ok = FALSE;
+ ok = false;
}
}
}
Modified: trunk/qgis/src/providers/ogr/qgsogrprovider.cpp
===================================================================
--- trunk/qgis/src/providers/ogr/qgsogrprovider.cpp 2009-11-28 16:02:15 UTC (rev 12273)
+++ trunk/qgis/src/providers/ogr/qgsogrprovider.cpp 2009-11-28 16:11:04 UTC (rev 12274)
@@ -1026,6 +1026,7 @@
ability |= ChangeGeometries;
}
+#if 0
if ( OGR_L_TestCapability( ogrLayer, "FastSpatialFilter" ) )
// TRUE if this layer implements spatial filtering efficiently.
// Layers that effectively read all features, and test them with the
@@ -1059,25 +1060,20 @@
{
// No use required for this QGIS release.
}
+#endif
- if ( 1 )
+ // OGR doesn't handle shapefiles without attributes, ie. missing DBFs well, fixes #803
+ if ( ogrDriverName == "ESRI Shapefile" )
{
- // Ideally this should test for Shapefile type and GDAL >= 1.2.6
- // In reality, createSpatialIndex() looks after itself.
+#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1260
+ // test for Shapefile type and GDAL >= 1.2.6
ability |= CreateSpatialIndex;
- }
-
+#endif
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1600
- // adding attributes was added in GDAL 1.6
- if ( ogrDriverName.startsWith( "ESRI" ) )
- {
+ // adding attributes was added in GDAL 1.6
ability |= AddAttributes;
- }
#endif
- // OGR doesn't handle shapefiles without attributes, ie. missing DBFs well, fixes #803
- if ( ogrDriverName.startsWith( "ESRI" ) )
- {
if ( mAttributeFields.size() == 0 )
{
QgsDebugMsg( "OGR doesn't handle shapefile without attributes well, ie. missing DBFs" );
@@ -1586,10 +1582,12 @@
OGR_DS_Destroy( dataSource );
- if ( uri.endsWith( ".shp", Qt::CaseInsensitive ) )
+ QString driverName = OGR_Dr_GetName( driver );
+
+ if ( driverName == "ESRI Shapefile" )
{
- QString layerName = uri.left( uri.length() - 4 );
- QFile prjFile( layerName + ".prj" );
+ QString layerName = uri.left( uri.indexOf( ".shp", Qt::CaseInsensitive ) );
+ QFile prjFile( layerName + ".qpj" );
if ( prjFile.open( QIODevice::WriteOnly ) )
{
QTextStream prjStream( &prjFile );
@@ -1598,7 +1596,7 @@
}
else
{
- QgsDebugMsg( "Couldn't open file " + layerName + ".prj" );
+ QgsDebugMsg( "Couldn't open file " + layerName + ".qpj" );
}
}
@@ -1618,6 +1616,29 @@
QgsCoordinateReferenceSystem srs;
+ if ( ogrDriver )
+ {
+ QString driverName = OGR_Dr_GetName( ogrDriver );
+
+ if ( driverName == "ESRI Shapefile" )
+ {
+ QString layerName = mFilePath.left( mFilePath.indexOf( ".shp", Qt::CaseInsensitive ) );
+ QFile prjFile( layerName + ".qpj" );
+ if ( prjFile.open( QIODevice::ReadOnly ) )
+ {
+ QTextStream prjStream( &prjFile );
+ QString myWktString = prjStream.readLine();
+ prjFile.close();
+
+ // create CRS from Wkt
+ srs.createFromWkt( myWktString );
+
+ if ( srs.isValid() )
+ return srs;
+ }
+ }
+ }
+
OGRSpatialReferenceH mySpatialRefSys = OGR_L_GetSpatialRef( ogrLayer );
if ( mySpatialRefSys == NULL )
{
@@ -1626,10 +1647,10 @@
else
{
// get the proj4 text
- char * ppszProj4;
+ char *ppszProj4;
OSRExportToProj4( mySpatialRefSys, &ppszProj4 );
QgsDebugMsg( ppszProj4 );
- char *pszWkt = NULL;
+ char *pszWkt = NULL;
OSRExportToWkt( mySpatialRefSys, &pszWkt );
QString myWktString = QString( pszWkt );
OGRFree( pszWkt );
More information about the QGIS-commit
mailing list