Skip to content

Commit

Permalink
[processing] take in account file extension when loading Processing
Browse files Browse the repository at this point in the history
results (fix #16486)
  • Loading branch information
alexbruy committed May 12, 2017
1 parent aa0ce1c commit 3d3b6ec
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions python/plugins/processing/tools/dataobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,9 @@ def load(fileName, name=None, crs=None, style=None):
settings.setValue('/Projections/defaultBehaviour', '')
if name is None:
name = os.path.split(fileName)[1]
qgslayer = QgsVectorLayer(fileName, name, 'ogr')
if qgslayer.isValid():
if crs is not None and qgslayer.crs() is None:
qgslayer.setCrs(crs, False)
if style is None:
if qgslayer.geometryType() == QGis.Point:
style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_POINT_STYLE)
elif qgslayer.geometryType() == QGis.Line:
style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_LINE_STYLE)
else:
style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_POLYGON_STYLE)
qgslayer.loadNamedStyle(style)
QgsMapLayerRegistry.instance().addMapLayers([qgslayer])
else:

suffix = os.path.splitext(fileName)[1][1:]
if suffix in getSupportedOutputRasterLayerExtensions():
qgslayer = QgsRasterLayer(fileName, name)
if qgslayer.isValid():
if crs is not None and qgslayer.crs() is None:
Expand All @@ -197,6 +186,21 @@ def load(fileName, name=None, crs=None, style=None):
settings.setValue('/Projections/defaultBehaviour', prjSetting)
raise RuntimeError('Could not load layer: ' + unicode(fileName)
+ '\nCheck the processing framework log to look for errors')
else:
qgslayer = QgsVectorLayer(fileName, name, 'ogr')
if qgslayer.isValid():
if crs is not None and qgslayer.crs() is None:
qgslayer.setCrs(crs, False)
if style is None:
if qgslayer.geometryType() == QGis.Point:
style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_POINT_STYLE)
elif qgslayer.geometryType() == QGis.Line:
style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_LINE_STYLE)
else:
style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_POLYGON_STYLE)
qgslayer.loadNamedStyle(style)
QgsMapLayerRegistry.instance().addMapLayers([qgslayer])

if prjSetting:
settings.setValue('/Projections/defaultBehaviour', prjSetting)

Expand Down

0 comments on commit 3d3b6ec

Please sign in to comment.