[QGIS Commit] r11381 - trunk/qgis/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Aug 14 13:59:41 EDT 2009


Author: homann
Date: 2009-08-14 13:59:41 -0400 (Fri, 14 Aug 2009)
New Revision: 11381

Modified:
   trunk/qgis/src/core/qgsvectorfilewriter.cpp
Log:
Overwrite the .prj files that GDAL creates for us when saving as SHAPE-file with the WKT from the CRS directly. Might break ESRI-sensitive programs. Partly fixes #1875.

Modified: trunk/qgis/src/core/qgsvectorfilewriter.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorfilewriter.cpp	2009-08-14 17:57:03 UTC (rev 11380)
+++ trunk/qgis/src/core/qgsvectorfilewriter.cpp	2009-08-14 17:59:41 UTC (rev 11381)
@@ -30,6 +30,7 @@
 #include <QSettings>
 #include <QFileInfo>
 #include <QTextCodec>
+#include <QTextStream>
 
 #include <cassert>
 #include <cstdlib> // size_t
@@ -89,6 +90,7 @@
   if ( srs )
   {
     QString srsWkt = srs->toWkt();
+    QgsDebugMsg( "WKT to save as is " + srsWkt );
     ogrRef = OSRNewSpatialReference( srsWkt.toLocal8Bit().data() );
   }
 
@@ -379,6 +381,27 @@
   {
     delete ct;
   }
+
+  // Ohh, a great Hack-fest starts!
+  // Overwrite the .prj file created by QGsVectorFileWrite().
+  // This might break progrmas that relies on ESRI style .prf-files.
+  // The 'CT-params' (e.g. +towgs84) does not get stripped in this way
+  QRegExp regExp( ".shp$" );
+  QString prjName = shapefileName;
+  prjName.replace( regExp, QString( "" ));
+  prjName.append( QString( ".prj" ) );
+  QFile prjFile( prjName );
+
+  if( !prjFile.open( QIODevice::WriteOnly ) )
+  {
+    QgsDebugMsg( "Couldn't open file " + prjName );
+    return NoError; // For now
+  }
+
+  QTextStream prjStream( & prjFile );
+  prjStream << destCRS->toWkt() << endl;
+  prjFile.close();
+
   return NoError;
 }
 



More information about the QGIS-commit mailing list