Skip to content
Permalink
Browse files

[BUGFIX][Processing] RScript: Insert None value as NULL

  • Loading branch information
rldhont committed Jun 6, 2016
1 parent 601af0e commit 3a2f3df9d5353e863550a3e09652b102cadbfa8a
Showing with 47 additions and 29 deletions.
  1. +47 −29 python/plugins/processing/algs/r/RAlgorithm.py
@@ -360,37 +360,46 @@ def getImportCommands(self):

for param in self.parameters:
if isinstance(param, ParameterRaster):
value = param.value
value = value.replace('\\', '/')
if self.passFileNames:
commands.append(param.name + ' = "' + value + '"')
elif self.useRasterPackage:
commands.append(param.name + ' = ' + 'brick("' + value
+ '")')
if param.value is None:
commands.append(param.name + '= NULL')
else:
commands.append(param.name + ' = ' + 'readGDAL("' + value
+ '")')
value = param.value
value = value.replace('\\', '/')
if self.passFileNames:
commands.append(param.name + ' = "' + value + '"')
elif self.useRasterPackage:
commands.append(param.name + ' = ' + 'brick("' + value
+ '")')
else:
commands.append(param.name + ' = ' + 'readGDAL("' + value
+ '")')
elif isinstance(param, ParameterVector):
value = param.getSafeExportedLayer()
value = value.replace('\\', '/')
filename = os.path.basename(value)
filename = filename[:-4]
folder = os.path.dirname(value)
if self.passFileNames:
commands.append(param.name + ' = "' + value + '"')
if param.value is None:
commands.append(param.name + '= NULL')
else:
commands.append(param.name + ' = readOGR("' + folder
+ '",layer="' + filename + '")')
value = param.getSafeExportedLayer()
value = value.replace('\\', '/')
filename = os.path.basename(value)
filename = filename[:-4]
folder = os.path.dirname(value)
if self.passFileNames:
commands.append(param.name + ' = "' + value + '"')
else:
commands.append(param.name + ' = readOGR("' + folder
+ '",layer="' + filename + '")')
elif isinstance(param, ParameterTable):
value = param.value
if not value.lower().endswith('csv'):
raise GeoAlgorithmExecutionException(
'Unsupported input file format.\n' + value)
if self.passFileNames:
commands.append(param.name + ' = "' + value + '"')
if param.value is None:
commands.append(param.name + '= NULL')
else:
commands.append(param.name + ' <- read.csv("' + value
+ '", head=TRUE, sep=",")')
value = param.value
if not value.lower().endswith('csv'):
raise GeoAlgorithmExecutionException(
'Unsupported input file format.\n' + value)
if self.passFileNames:
commands.append(param.name + ' = "' + value + '"')
else:
commands.append(param.name + ' <- read.csv("' + value
+ '", head=TRUE, sep=",")')
elif isinstance(param, ParameterExtent):
if param.value:
tokens = unicode(param.value).split(',')
@@ -400,12 +409,21 @@ def getImportCommands(self):
else:
commands.append(param.name + ' = NULL')
elif isinstance(param, ParameterCrs):
commands.append(param.name + ' = "' + param.value + '"')
if param.value is None:
commands.append(param.name + '= NULL')
else:
commands.append(param.name + ' = "' + param.value + '"')
elif isinstance(param, (ParameterTableField, ParameterString,
ParameterFile)):
commands.append(param.name + '="' + param.value + '"')
if param.value is None:
commands.append(param.name + '= NULL')
else:
commands.append(param.name + '="' + param.value + '"')
elif isinstance(param, (ParameterNumber, ParameterSelection)):
commands.append(param.name + '=' + unicode(param.value))
if param.value is None:
commands.append(param.name + '= NULL')
else:
commands.append(param.name + '=' + unicode(param.value))
elif isinstance(param, ParameterBoolean):
if param.value:
commands.append(param.name + '=TRUE')

0 comments on commit 3a2f3df

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