qgis-processing-r icon indicating copy to clipboard operation
qgis-processing-r copied to clipboard

To read csv

Open kazuhito84455 opened this issue 6 years ago • 7 comments

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.

kazuhito84455 avatar Feb 21 '19 16:02 kazuhito84455

Hm - this is an API limitation in core QGIS, it'll need to be addressed upstream

nyalldawson avatar Feb 22 '19 00:02 nyalldawson

I see. Thanks for investigating this and suggestion. Will try to find core QGIS upstream and post a question.

kazuhito84455 avatar Feb 22 '19 21:02 kazuhito84455

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.

nyalldawson avatar Feb 22 '19 21:02 nyalldawson

Wow, fantastic! Thanks so much.

kazuhito84455 avatar Feb 22 '19 21:02 kazuhito84455

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!

Habitat-Projects avatar Apr 23 '20 20:04 Habitat-Projects

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)

gavg712 avatar Sep 30 '21 23:09 gavg712

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.

yodaanneaux avatar Feb 22 '23 15:02 yodaanneaux