Skip to content

Commit

Permalink
Overwrite the .prj files that GDAL creates for us when saving as SHAP…
Browse files Browse the repository at this point in the history
…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 committed Aug 14, 2009
1 parent a51b0a0 commit 4ab570e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -30,6 +30,7 @@
#include <QSettings>
#include <QFileInfo>
#include <QTextCodec>
#include <QTextStream>

#include <cassert>
#include <cstdlib> // size_t
Expand Down Expand Up @@ -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() );
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 4ab570e

Please sign in to comment.