From fc5f70c6f5da67003ac0a47aada44aeff2e3ada2 Mon Sep 17 00:00:00 2001 From: "arnaud.morvan@camptocamp.com" Date: Thu, 28 Apr 2016 14:04:46 +0200 Subject: [PATCH] Processing - Support tables with no geometry in OutputVector --- .../plugins/processing/core/GeoAlgorithm.py | 2 +- python/plugins/processing/core/outputs.py | 29 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/python/plugins/processing/core/GeoAlgorithm.py b/python/plugins/processing/core/GeoAlgorithm.py index 825e17bea70..4670421d515 100644 --- a/python/plugins/processing/core/GeoAlgorithm.py +++ b/python/plugins/processing/core/GeoAlgorithm.py @@ -354,7 +354,7 @@ class GeoAlgorithm: out.value = out.value + '.' + exts[0] else: ext = out.value[idx + 1:] - if ext not in exts: + if ext not in exts + ['dbf']: out.value = out.value + '.' + exts[0] def resolveTemporaryOutputs(self): diff --git a/python/plugins/processing/core/outputs.py b/python/plugins/processing/core/outputs.py index a1165aceb47..78d274f504e 100644 --- a/python/plugins/processing/core/outputs.py +++ b/python/plugins/processing/core/outputs.py @@ -250,15 +250,34 @@ class OutputVector(Output): encoding = None compatible = None - def getFileFilter(self, alg): + def __init__(self, name='', description='', hidden=False, base_input=None): + Output.__init__(self, name, description, hidden) + self.base_input = base_input + self.base_layer = None + + def hasGeometry(self): + if self.base_layer is None: + return True + return dataobjects.canUseVectorLayer(self.base_layer, [-1]) + + def getSupportedOutputVectorLayerExtensions(self): exts = dataobjects.getSupportedOutputVectorLayerExtensions() + if not self.hasGeometry(): + exts = ['dbf'] + [ext for ext in exts if ext in VectorWriter.nogeometry_extensions] + return exts + + def getFileFilter(self, alg): + exts = self.getSupportedOutputVectorLayerExtensions() for i in range(len(exts)): exts[i] = self.tr('%s files (*.%s)', 'OutputVector') % (exts[i].upper(), exts[i].lower()) return ';;'.join(exts) def getDefaultFileExtension(self, alg): - supported = alg.provider.getSupportedOutputVectorLayerExtensions() - default = ProcessingConfig.getSetting(ProcessingConfig.DEFAULT_OUTPUT_VECTOR_LAYER_EXT) + supported = self.getSupportedOutputVectorLayerExtensions() + if self.hasGeometry(): + default = ProcessingConfig.getSetting(ProcessingConfig.DEFAULT_OUTPUT_VECTOR_LAYER_EXT) + else: + default = 'dbf' ext = default if default in supported else supported[0] return ext @@ -271,9 +290,8 @@ class OutputVector(Output): temporary file with a supported file format, to be used to generate the output result. """ - ext = self.value[self.value.rfind('.') + 1:] - if ext in alg.provider.getSupportedOutputVectorLayerExtensions(): + if ext in self.getSupportedOutputVectorLayerExtensions(): return self.value else: if self.compatible is None: @@ -307,4 +325,5 @@ class OutputVector(Output): w = VectorWriter(self.value, self.encoding, fields, geomType, crs, options) self.layer = w.layer + self.value = w.destination return w