How to keep x/y coordinates while creating a raster from a data frame in r with terra package?

40 views Asked by At

Resulted raster

I have a dataframe with x and y coordinates, containing predicted values. I created an empty raster with the right ext, res and crs and I want to assign the predicted values. I used the function setValues from the terra package, however the function does not consider the x and y from the dataframe and read the data in another manner. It results with a raster that contains only the horizontal (x) info --> look at the picture. Is there an alternative function in the terra package where it is possible to add the x/y coordinates?

1

There are 1 answers

0
Robert Hijmans On

What you are looking for is probably rast(x, type="xyz"), but it is hard to say since there is no example. Also, you can probably avoid this whole situation by using terra::predict.