Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To read csv #25

Open
kazuhito84455 opened this issue Feb 21, 2019 · 7 comments
Open

To read csv #25

kazuhito84455 opened this issue Feb 21, 2019 · 7 comments
Labels
upstream Upstream QGIS issue

Comments

@kazuhito84455
Copy link

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.

@nyalldawson
Copy link
Contributor

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

@nyalldawson nyalldawson added the upstream Upstream QGIS issue label Feb 22, 2019
@kazuhito84455
Copy link
Author

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

@nyalldawson
Copy link
Contributor

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.

@kazuhito84455
Copy link
Author

Wow, fantastic! Thanks so much.

@Habitat-Projects
Copy link

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!

@gavg712
Copy link
Contributor

gavg712 commented Sep 30, 2021

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)

@yodaanneaux
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream Upstream QGIS issue
Projects
None yet
Development

No branches or pull requests

4 participants