Skip to content

Commit 0c3cb55

Browse files
pmav99nyalldawson
authored andcommitted
Introduce GRASS_USE_REXTERNAL setting
GRASS GIS, in addition to importing data in its native formats via `r.in.gdal`/`v.in.ogr` (and likewise `r.import`/v.import`), also supports `r.external`/`v.external` which only link the data into the GRASS DB. Nevertheless, both `r.external` and `v.external` occasionally have problems, especially on windows. E.g.: - https://trac.osgeo.org/grass/ticket/3927 GRASS 7 Processing Plugin already has a setting that controls whether `v.external` is used (disabled by default). With this commit the complementary setting for `r.external` gets added too. Usage of `r.external` is disabled by default. This is changing the existing behavior, which was to use r`r.external`. The downsides of this change should be the somewhat lower import speed + higher disk usage. Nevertheless this way we have the same default value as `v.external` + we circumvent the `r.import/v.import` shortcomings.
1 parent a83154c commit 0c3cb55

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

python/plugins/processing/algs/grass7/Grass7Algorithm.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,29 +700,31 @@ def processOutputs(self, parameters, context, feedback):
700700
elif isinstance(out, QgsProcessingParameterFolderDestination):
701701
self.exportRasterLayersIntoDirectory(outName, parameters, context)
702702

703-
def loadRasterLayerFromParameter(self, name, parameters, context, external=True, band=1):
703+
def loadRasterLayerFromParameter(self, name, parameters, context, external=None, band=1):
704704
"""
705705
Creates a dedicated command to load a raster into
706706
the temporary GRASS DB.
707707
:param name: name of the parameter.
708708
:param parameters: algorithm parameters dict.
709709
:param context: algorithm context.
710-
:param external: True if using r.external.
710+
:param external: use r.external if True, r.in.gdal otherwise.
711711
:param band: imports only specified band. None for all bands.
712712
"""
713713
layer = self.parameterAsRasterLayer(parameters, name, context)
714714
self.loadRasterLayer(name, layer, external, band)
715715

716-
def loadRasterLayer(self, name, layer, external=True, band=1, destName=None):
716+
def loadRasterLayer(self, name, layer, external=None, band=1, destName=None):
717717
"""
718718
Creates a dedicated command to load a raster into
719719
the temporary GRASS DB.
720720
:param name: name of the parameter.
721721
:param layer: QgsMapLayer for the raster layer.
722-
:param external: True if using r.external.
722+
:param external: use r.external if True, r.in.gdal if False.
723723
:param band: imports only specified band. None for all bands.
724724
:param destName: force the destination name of the raster.
725725
"""
726+
if external is None:
727+
external = ProcessingConfig.getSetting(Grass7Utils.GRASS_USE_REXTERNAL)
726728
self.inputLayers.append(layer)
727729
self.setSessionProjectionFromLayer(layer)
728730
if not destName:

python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,16 @@ def load(self):
7070
Grass7Utils.GRASS_HELP_PATH,
7171
self.tr('Location of GRASS docs'),
7272
Grass7Utils.grassHelpPath()))
73-
# Add a setting for using v.external instead of v.in.ogr
74-
# But set it to False by default because some algorithms
75-
# can't be used with external data (need a solid v.in.ogr).
73+
# Add settings for using r.external/v.external instead of r.in.gdal/v.in.ogr
74+
# but set them to False by default because the {r,v}.external implementations
75+
# have some bugs on windows + there are algorithms that can't be used with
76+
# external data (need a solid r.in.gdal/v.in.ogr).
77+
# For more info have a look at e.g. https://trac.osgeo.org/grass/ticket/3927
78+
ProcessingConfig.addSetting(Setting(
79+
self.name(),
80+
Grass7Utils.GRASS_USE_REXTERNAL,
81+
self.tr('For raster layers, use r.external (faster) instead of r.in.gdal'),
82+
False))
7683
ProcessingConfig.addSetting(Setting(
7784
self.name(),
7885
Grass7Utils.GRASS_USE_VEXTERNAL,
@@ -90,6 +97,7 @@ def unload(self):
9097
ProcessingConfig.removeSetting(Grass7Utils.GRASS_LOG_COMMANDS)
9198
ProcessingConfig.removeSetting(Grass7Utils.GRASS_LOG_CONSOLE)
9299
ProcessingConfig.removeSetting(Grass7Utils.GRASS_HELP_PATH)
100+
ProcessingConfig.removeSetting(Grass7Utils.GRASS_USE_REXTERNAL)
93101
ProcessingConfig.removeSetting(Grass7Utils.GRASS_USE_VEXTERNAL)
94102

95103
def isActive(self):

python/plugins/processing/algs/grass7/Grass7Utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Grass7Utils:
5050
GRASS_LOG_COMMANDS = 'GRASS7_LOG_COMMANDS'
5151
GRASS_LOG_CONSOLE = 'GRASS7_LOG_CONSOLE'
5252
GRASS_HELP_PATH = 'GRASS_HELP_PATH'
53+
GRASS_USE_REXTERNAL = 'GRASS_USE_REXTERNAL'
5354
GRASS_USE_VEXTERNAL = 'GRASS_USE_VEXTERNAL'
5455

5556
# TODO Review all default options formats
@@ -401,6 +402,9 @@ def executeGrass(commands, feedback, outputCommands=None):
401402
elif 'Segmentation fault' in line:
402403
feedback.reportError(line.strip())
403404
feedback.reportError('\n' + Grass7Utils.tr('GRASS command crashed :( Try a different set of input parameters and consult the GRASS algorithm manual for more information.') + '\n')
405+
if ProcessingConfig.getSetting(Grass7Utils.GRASS_USE_REXTERNAL):
406+
feedback.reportError(Grass7Utils.tr(
407+
'Suggest disabling the experimental "use r.external" option from the Processing GRASS Provider options.') + '\n')
404408
if ProcessingConfig.getSetting(Grass7Utils.GRASS_USE_VEXTERNAL):
405409
feedback.reportError(Grass7Utils.tr(
406410
'Suggest disabling the experimental "use v.external" option from the Processing GRASS Provider options.') + '\n')

0 commit comments

Comments
 (0)