0

Someone who has experience with R in Qgis can help me with this problem. I have a script that works perfectly in R making downloads SRTM DEM and cuts to the desired polygon. But I can't implement it in qgis.

library(sf)
library(raster)
library(elevatr)
library(viridis)
library(tidyverse)
library(sp)
library(rgdal)
setwd("D:/teste_MDT/1")
pol_mask <- readOGR(dsn = "D:/teste_MDT/1", layer = "2")
#crs(pol_mask) <- "+proj=longlat +datum=WGS84"
plot(pol_mask)
dem <- get_elev_raster(pol_mask, z = 11, override_size_check = TRUE)
plot(dem)
writeRaster(dem, filename= "dem.tif")
crop_dem <- mask(x= crop(dem, pol_mask), pol_mask, filename = "crop.tif")
plot(crop_dem)

enter image description here

1
  • Please always provide error messages as formatted text rather than pictures.
    – PolyGeo
    Commented Jun 16, 2021 at 3:03

1 Answer 1

0

It looks like you might be running an old version of elevatr that doesn't work with sf objects.

QGIS' R scripts get passed vector data as sf objects, but the error looks like it is trying to run sp functions (spTransform is mentioned) on an sf object.

Try updating elevatr, or converting the vector layer to an sp object with something like:

pol_mask_sp = as(pol_mask,"Spatial")

and working with that.

2
  • I implemented the following changes but I keep getting the same message. DATABASE.LAYOUT.VERSION.MINOR metadata. Comes from another installation of PROJ. Error in h (simpleError (msg, call)): error evaluating 'CRSobj' argument in method selection for 'spTransform' function: 'NA' Calls: get_elev_raster -> estimate_raster_size -> <Anonymous> -> <Anonymous> Execution interrupted
    – Ramon
    Commented Jun 16, 2021 at 23:40
  • 1
    I would suspect there is a mismatch in package versions used by R standalone and those executed from QGIS rprocessing plugin. Make sure the R Processing Options: User library folder points out to your local R library rather QGIS profile folder. Commented Jan 7 at 23:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.