Search code examples
rdropboxraster

Importing .asc files from Dropbox using R


I have a bunch of .asc raster files that I need to access through Dropbox share links. For some reason I am unable to read the files into R. I have tried the raster(), read.csv(), and read.table() functions, but all return errors. R claims the files don't exist, while the Dropbox share links do in fact contain the .asc files. Any suggestions where I'm going wrong?

Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  : 
  Cannot create a RasterLayer object from this file. (file does not exist)

My code

library(raster)

# define projection
RD_Proj4 = '+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +towgs84=565.2369,50.0087,465.658,-0.406857330322398,0.350732676542563,-1.8703473836068,4.0812 +no_defs'

# The share link for the Dropbox .asc files
pm10 <- "https://www.dropbox.com/s/vkvbabwcwdk2r3q/conc_pm10_2019.asc?dl=0"
no2 <- "https://www.dropbox.com/s/foq2yufvi3694gt/conc_no2_2019.asc?dl=0"

# Trying to fetch the files from Dropbox
rasterData <- raster(pm10, crs = RD_Proj4)

Solution

  • @MrFlick pointed out what the right URL is, and with that you can do

    library(raster)
    RD_Proj4 = '+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +towgs84=565.2369,50.0087,465.658,-0.406857330322398,0.350732676542563,-1.8703473836068,4.0812 +no_defs'
    
    pm10 <- "https://www.dropbox.com/s/vkvbabwcwdk2r3q/conc_pm10_2019.asc?dl=1"
    r <- raster(pm10, crs=RD_Proj4)
    r 
    
    #class      : RasterLayer 
    #dimensions : 320, 280, 89600  (nrow, ncol, ncell)
    #resolution : 1000, 1000  (x, y)
    #extent     : 0, 280000, 3e+05, 620000  (xmin, xmax, ymin, ymax)
    #crs        : +proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.2369,50.0087,465.658,-0.406857330322398,0.350732676542563,-1.8703473836068,4.0812 +units=m +no_defs 
    #source     : https://www.dropbox.com/s/vkvbabwcwdk2r3q/conc_pm10_2019.asc?dl=1 
    #names      : conc_pm10_2019.asc.dl.1