Skip to content

Commit

Permalink
Follow up 012ee83: delete .qpj file when overwriting pre-existing sha…
Browse files Browse the repository at this point in the history
…pefile dataset
  • Loading branch information
github-actions[bot] authored and nirvn committed Feb 4, 2020
1 parent b4142c3 commit 445de78
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/core/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -3635,6 +3635,7 @@ bool QgsOgrProviderUtils::createEmptyDataSource( const QString &uri,
{
QString layerName = uri.left( index );
QFile prjFile( layerName + ".qpj" );
#if PROJ_VERSION_MAJOR<6
if ( prjFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QTextStream prjStream( &prjFile );
Expand All @@ -3645,6 +3646,10 @@ bool QgsOgrProviderUtils::createEmptyDataSource( const QString &uri,
{
QgsMessageLog::logMessage( QObject::tr( "Couldn't create file %1.qpj" ).arg( layerName ), QObject::tr( "OGR" ) );
}
#else
if ( prjFile.exists() )
prjFile.remove();
#endif
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -503,13 +503,13 @@ void QgsVectorFileWriter::init( QString vectorFileName,
CPLSetConfigOption( "SHAPE_ENCODING", nullptr );
}

#if PROJ_VERSION_MAJOR<6
if ( srs.isValid() )
{
if ( mOgrDriverName == QLatin1String( "ESRI Shapefile" ) )
{
QString layerName = vectorFileName.left( vectorFileName.indexOf( QLatin1String( ".shp" ), Qt::CaseInsensitive ) );
QFile prjFile( layerName + ".qpj" );
#if PROJ_VERSION_MAJOR<6
if ( prjFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QTextStream prjStream( &prjFile );
Expand All @@ -520,9 +520,12 @@ void QgsVectorFileWriter::init( QString vectorFileName,
{
QgsDebugMsg( "Couldn't open file " + layerName + ".qpj" );
}
#else
if ( prjFile.exists() )
prjFile.remove();
#endif
}
}
#endif

if ( !mLayer )
{
Expand Down

0 comments on commit 445de78

Please sign in to comment.