Skip to content
Permalink
Browse files

Merge pull request #9043 from alexbruy/misc-backports

3.4 backports
  • Loading branch information
alexbruy committed Jan 31, 2019
2 parents ef97dba + a1d75a4 commit d3bfa158951d5949f6b7135a4e08d08209227426
@@ -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,15 @@ 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'),
False
)
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 +543,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 +915,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 +931,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 ''
' lco="{}"'.format(lco) if lco else '',
' -c' if exportnocat else ''
)
)

@@ -406,6 +406,7 @@ tests:
GRASS_SNAP_TOLERANCE_PARAMETER: -1.0
GRASS_VECTOR_DSCO: ''
GRASS_VECTOR_LCO: ''
GRASS_VECTOR_EXPORT_NOCAT: true
input:
name: pointsz.gml|layername=pointsz
type: vector
@@ -23,7 +23,7 @@
#include "qgsvectorlayer.h"

QgsProcessingAlgRunnerTask::QgsProcessingAlgRunnerTask( const QgsProcessingAlgorithm *algorithm, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
: QgsTask( tr( "Executing “%1”" ).arg( algorithm->displayName() ), QgsTask::CanCancel )
: QgsTask( tr( "Executing “%1”" ).arg( algorithm->displayName() ), algorithm->flags() & QgsProcessingAlgorithm::FlagCanCancel ? QgsTask::CanCancel : QgsTask::Flag() )
, mParameters( parameters )
, mContext( context )
, mFeedback( feedback )

0 comments on commit d3bfa15

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