Skip to content
Permalink
Browse files

Overwrite the .prj files that GDAL creates for us when saving as SHAP…

…E-file with the WKT from the CRS directly. Might break ESRI-sensitive programs. Partly fixes #1875.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11381 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann
homann committed Aug 14, 2009
1 parent a51b0a0 commit 4ab570e04ce53abc9689772bf20135ae67e67372
Showing with 23 additions and 0 deletions.
  1. +23 −0 src/core/qgsvectorfilewriter.cpp
@@ -30,6 +30,7 @@
#include <QSettings>
#include <QFileInfo>
#include <QTextCodec>
#include <QTextStream>

#include <cassert>
#include <cstdlib> // size_t
@@ -89,6 +90,7 @@ QgsVectorFileWriter::QgsVectorFileWriter( const QString& shapefileName,
if ( srs )
{
QString srsWkt = srs->toWkt();
QgsDebugMsg( "WKT to save as is " + srsWkt );
ogrRef = OSRNewSpatialReference( srsWkt.toLocal8Bit().data() );
}

@@ -379,6 +381,27 @@ QgsVectorFileWriter::writeAsShapefile( QgsVectorLayer* layer,
{
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;
}

0 comments on commit 4ab570e

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