Skip to content

Commit cee63c8

Browse files
committedOct 18, 2015
vector file writer: defer destroying spatial reference (fixes #10515)
1 parent 6426be3 commit cee63c8

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed
 

‎src/core/qgsvectorfilewriter.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
6969
)
7070
: mDS( NULL )
7171
, mLayer( NULL )
72+
, mOgrRef( NULL )
7273
, mGeom( NULL )
7374
, mError( NoError )
7475
, mCodec( 0 )
@@ -260,12 +261,11 @@ QgsVectorFileWriter::QgsVectorFileWriter(
260261
}
261262

262263
// consider spatial reference system of the layer
263-
OGRSpatialReferenceH ogrRef = NULL;
264264
if ( srs )
265265
{
266266
QString srsWkt = srs->toWkt();
267267
QgsDebugMsg( "WKT to save as is " + srsWkt );
268-
ogrRef = OSRNewSpatialReference( srsWkt.toLocal8Bit().data() );
268+
mOgrRef = OSRNewSpatialReference( srsWkt.toLocal8Bit().data() );
269269
}
270270

271271
// datasource created, now create the output layer
@@ -285,7 +285,7 @@ QgsVectorFileWriter::QgsVectorFileWriter(
285285
// disable encoding conversion of OGR Shapefile layer
286286
CPLSetConfigOption( "SHAPE_ENCODING", "" );
287287

288-
mLayer = OGR_DS_CreateLayer( mDS, TO8F( layerName ), ogrRef, wkbType, options );
288+
mLayer = OGR_DS_CreateLayer( mDS, TO8F( layerName ), mOgrRef, wkbType, options );
289289

290290
if ( options )
291291
{
@@ -318,8 +318,6 @@ QgsVectorFileWriter::QgsVectorFileWriter(
318318
QgsDebugMsg( "Couldn't open file " + layerName + ".qpj" );
319319
}
320320
}
321-
322-
OSRDestroySpatialReference( ogrRef );
323321
}
324322

325323
if ( mLayer == NULL )
@@ -1829,6 +1827,11 @@ QgsVectorFileWriter::~QgsVectorFileWriter()
18291827
{
18301828
OGR_DS_Destroy( mDS );
18311829
}
1830+
1831+
if ( mOgrRef )
1832+
{
1833+
OSRDestroySpatialReference( mOgrRef );
1834+
}
18321835
}
18331836

18341837
QgsVectorFileWriter::WriterError

‎src/core/qgsvectorfilewriter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ class CORE_EXPORT QgsVectorFileWriter
275275

276276
OGRDataSourceH mDS;
277277
OGRLayerH mLayer;
278+
OGRSpatialReferenceH mOgrRef;
278279
OGRGeometryH mGeom;
279280

280281
QgsFields mFields;

0 commit comments

Comments
 (0)
Please sign in to comment.