Bug report #21856

QGIS crashed while using QgsVectorFileWriter

Added by Bill Mitchell over 1 year ago. Updated over 1 year ago.

Status:Closed
Priority:High
Assignee:Alessandro Pasotti
Category:Vectors
Affected QGIS version:3.7(master) Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:Yes Resolution:fixed/implemented
Crashes QGIS or corrupts data:No Copied to github as #:29671

Description

QGIS consistently crashes when I run the following script in the Python console.

from qgis.core import (
    QgsVectorLayer,
    QgsField, QgsFields, 

    # QgsFeatureSource,
    # QgsFeatureSink,
    # QgsProject,
    QgsWkbTypes,
    QgsVectorFileWriter,
)

baseDir = "/Users/mitchell/Dropbox/python/import_gpx" 
gpxFile = f"{baseDir}/../gps/Waypoints_01-MAR-18.gpx" 

sourceLayer = QgsVectorLayer(gpxFile, "testFile", "GPX")

error, errormsg = QgsVectorFileWriter.writeAsVectorFormat(
    layer=sourceLayer,
    fileName="test.gpkg",
    fileEncoding="utf-8",
    destCRS=QgsCoordinateReferenceSystem('EPSG:4326'),
    driverName="GPKG",
    )
if error:
    print(f"{error} --- {errormsg}")
 

I have attached the crash report.

crash-report.text Magnifier (123 KB) Bill Mitchell, 2019-04-15 10:03 PM

Associated revisions

Revision e8a7d0e9
Added by Alessandro Pasotti over 1 year ago

Guard vector file writer against invalid layers

instead of crashing.

Fixes #21856

Funded by: QCooperative.net

Revision 0415c619
Added by Alessandro Pasotti over 1 year ago

Guard vector file writer against invalid layers

instead of crashing.

Fixes #21856

Funded by: QCooperative.net

Revision 911c3182
Added by Alessandro Pasotti over 1 year ago

Guard vector file writer against invalid layers

instead of crashing.

Fixes #21856

Funded by: QCooperative.net

Revision adb646fc
Added by Alessandro Pasotti over 1 year ago

Guard vector file writer against invalid layers

instead of crashing.

Fixes #21856

Funded by: QCooperative.net

Revision d3a93c5a
Added by Alessandro Pasotti over 1 year ago

Guard vector file writer against invalid layers

instead of crashing.

Fixes #21856

Funded by: QCooperative.net

History

#1 Updated by Giovanni Manghi over 1 year ago

  • Priority changed from Normal to High

#2 Updated by Alessandro Pasotti over 1 year ago

  • Operating System deleted (mac osx mohave (10.14.4))
  • Affected QGIS version changed from 3.6.1 to 3.7(master)
  • Assignee set to Alessandro Pasotti
  • Status changed from Open to In Progress
  • Category changed from Python bindings / sipify to Vectors
  • Crashes QGIS or corrupts data changed from Yes to No

This is wrong and will produce an invalid layer (there is not "GPX" provider, use "ogr" instead):

sourceLayer = QgsVectorLayer(gpxFile, "testFile", "GPX")

btw, a crash is not nice.

#3 Updated by Alessandro Pasotti over 1 year ago

  • Resolution set to fixed/implemented
  • Pull Request or Patch supplied changed from No to Yes

#4 Updated by Alessandro Pasotti over 1 year ago

  • Status changed from In Progress to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF