Skip to content

Commit 4ab570e

Browse files
author
homann
committed
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.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11381 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a51b0a0 commit 4ab570e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/core/qgsvectorfilewriter.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <QSettings>
3131
#include <QFileInfo>
3232
#include <QTextCodec>
33+
#include <QTextStream>
3334

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

@@ -379,6 +381,27 @@ QgsVectorFileWriter::writeAsShapefile( QgsVectorLayer* layer,
379381
{
380382
delete ct;
381383
}
384+
385+
// Ohh, a great Hack-fest starts!
386+
// Overwrite the .prj file created by QGsVectorFileWrite().
387+
// This might break progrmas that relies on ESRI style .prf-files.
388+
// The 'CT-params' (e.g. +towgs84) does not get stripped in this way
389+
QRegExp regExp( ".shp$" );
390+
QString prjName = shapefileName;
391+
prjName.replace( regExp, QString( "" ));
392+
prjName.append( QString( ".prj" ) );
393+
QFile prjFile( prjName );
394+
395+
if( !prjFile.open( QIODevice::WriteOnly ) )
396+
{
397+
QgsDebugMsg( "Couldn't open file " + prjName );
398+
return NoError; // For now
399+
}
400+
401+
QTextStream prjStream( & prjFile );
402+
prjStream << destCRS->toWkt() << endl;
403+
prjFile.close();
404+
382405
return NoError;
383406
}
384407

0 commit comments

Comments
 (0)