qgis-processing-r
qgis-processing-r copied to clipboard
To read csv
I would like to read a csv layer (which I have drag and dropped onto QGIS window) by a rsx. Below is a sample code which takes csv file (fields: X, Y, Z) and rasterize it :
##Raster Analysis=group
##CSV= table
##X= Field CSV
##Y= Field CSV
##Z= Field CSV
##EPSG=number 4326
##Output=output raster
library(raster)
DATA <- data.frame(X= CSV[[X]], Y= CSV[[Y]], Z= CSV[[Z]])
r <- rasterFromXYZ(DATA)
crs(r) <- paste0("+init=epsg:", EPSG)
Output <- r
When I run the code, it returns an Execution error message: This script has a syntax error. Problem with line: CSV= table
.
I thought table
worked in previous QGIS. What is the currently valid keyword to read csv? Thank you.
Hm - this is an API limitation in core QGIS, it'll need to be addressed upstream
I see. Thanks for investigating this and suggestion. Will try to find core QGIS upstream and post a question.
I was intending to leave this open and will address the core API limitations for QGIS 3.8 (and backport). It'll just take some time.
Wow, fantastic! Thanks so much.
Has there been an update on this issue ? I am also getting the same error when I try to run : ##Table=table
This is the error generated :
R: This script has a syntax error. Problem with line: Table=table
Thanks!
An alternative way to do is directly read the CSV file within the script. The colnames from table can be specified by a string separated by a known caracter, i.e comma (,)
##Conversions=group
##Csv file to raster=name
##CSV_file=file
##coord_names=string x,y,z
##CRS=crs
##rasterFromCSV=output raster
data <- read.csv(CSV_file)
coord_names <- unlist(strsplit(coord_names, ","))
rasterFromCSV <- rasterFromXYZ(data[,coord_names], crs = CRS)
Has there been an update on this issue ? I am also getting the same error when I try to run : ##Table=table
This is the error generated :
R: This script has a syntax error. Problem with line: Table=table
Thanks!
This issue is still here. Tried on Qgis 3.28.3 running on Windows 10 Pro with a fresh install of R.