Skip to content
Permalink
Browse files

do not always use the -c flag to export vectors from GRASS

(cherry picked from commit 5f99955)
  • Loading branch information
gioman authored and alexbruy committed Nov 5, 2018
1 parent dddb32e commit ed0623d9c6c9ee7075c4e5f0b1abc8b48ca764b2
Showing with 18 additions and 5 deletions.
  1. +18 −5 python/plugins/processing/algs/grass7/Grass7Algorithm.py
@@ -90,6 +90,7 @@ class Grass7Algorithm(QgsProcessingAlgorithm):
GRASS_RASTER_FORMAT_META = 'GRASS_RASTER_FORMAT_META'
GRASS_VECTOR_DSCO = 'GRASS_VECTOR_DSCO'
GRASS_VECTOR_LCO = 'GRASS_VECTOR_LCO'
GRASS_VECTOR_EXPORT_NOCAT = 'GRASS_VECTOR_EXPORT_NOCAT'

OUTPUT_TYPES = ['auto', 'point', 'line', 'area']
QGIS_OUTPUT_TYPES = {QgsProcessing.TypeVectorAnyGeometry: 'auto',
@@ -319,6 +320,14 @@ def defineCharacteristicsFromFile(self):
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.params.append(param)

# Add a -c flag for export
param = QgsProcessingParameterBoolean(
self.GRASS_VECTOR_EXPORT_NOCAT,
self.tr('Also export features without category (not labeled). Otherwise only features with category are exported')
)
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.params.append(param)

def getDefaultCellSize(self):
"""
Determine a default cell size from all the raster layers.
@@ -533,7 +542,8 @@ def processCommand(self, parameters, context, feedback, delOutputs=False):
self.GRASS_RASTER_FORMAT_OPT,
self.GRASS_RASTER_FORMAT_META,
self.GRASS_VECTOR_DSCO,
self.GRASS_VECTOR_LCO]:
self.GRASS_VECTOR_LCO,
self.GRASS_VECTOR_EXPORT_NOCAT]:
continue

# Raster and vector layers
@@ -904,10 +914,11 @@ def exportVectorLayerFromParameter(self, name, parameters, context, layer=None,
outFormat = QgsVectorFileWriter.driverForExtension(os.path.splitext(fileName)[1]).replace(' ', '_')
dsco = self.parameterAsString(parameters, self.GRASS_VECTOR_DSCO, context)
lco = self.parameterAsString(parameters, self.GRASS_VECTOR_LCO, context)
self.exportVectorLayer(grassName, fileName, layer, nocats, dataType, outFormat, dsco, lco)
exportnocat = self.parameterAsBool(parameters, self.GRASS_VECTOR_EXPORT_NOCAT, context)
self.exportVectorLayer(grassName, fileName, layer, nocats, dataType, outFormat, dsco, lco, exportnocat)

def exportVectorLayer(self, grassName, fileName, layer=None, nocats=False, dataType='auto',
outFormat=None, dsco=None, lco=None):
outFormat=None, dsco=None, lco=None, exportnocat=False):
"""
Creates a dedicated command to export a vector from
temporary GRASS DB into a file via OGR.
@@ -919,19 +930,21 @@ def exportVectorLayer(self, grassName, fileName, layer=None, nocats=False, dataT
:param outFormat: file format for export.
:param dsco: datasource creation options for format.
:param lco: layer creation options for format.
:param exportnocat: do not export features without categories.
"""
if outFormat is None:
outFormat = QgsVectorFileWriter.driverForExtension(os.path.splitext(fileName)[1]).replace(' ', '_')

for cmd in [self.commands, self.outputCommands]:
cmd.append(
'v.out.ogr{0} type="{1}" input="{2}" output="{3}" format="{4}" {5}{6}{7} --overwrite'.format(
'' if nocats else ' -c',
'v.out.ogr{0} type="{1}" input="{2}" output="{3}" format="{4}" {5}{6}{7}{8} --overwrite'.format(
'' if nocats else '',
dataType, grassName, fileName,
outFormat,
'layer={}'.format(layer) if layer else '',
' dsco="{}"'.format(dsco) if dsco else '',
' lco="{}"'.format(lco) if lco else ''
, ' -c' if exportnocat else ''
)
)

0 comments on commit ed0623d

Please sign in to comment.
You can’t perform that action at this time.