Skip to content

Commit

Permalink
[BUGFIX][Processing] RScript: Insert None value as NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Jun 6, 2016
1 parent 601af0e commit 3a2f3df
Showing 1 changed file with 47 additions and 29 deletions.
76 changes: 47 additions & 29 deletions python/plugins/processing/algs/r/RAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(',')
Expand All @@ -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')
Expand Down

0 comments on commit 3a2f3df

Please sign in to comment.