Search code examples
rgithubzipshapefile

Cannot open GitHub shapefile in tempdir()


I'd like to open a shapefile in *zip format by GitHub download without success in windows 10. In my example:

library(rgdal)

# get AOI
download.file(
  "https://github.com/Leprechault/trash/blob/main/stands_example.zip",
  zip_path <- tempfile(fileext = ".zip")
)
unzip(zip_path, exdir = tempdir())

Warning message:
In unzip(zip_path, exdir = tempdir()) :
  error 1 extracting from zip file

setwd(tempdir())
stands_extent <- readOGR(file.path(tempdir(), "stands_target")) # Border
Error in ogrListLayers(dsn = dsn) : Cannot open data source

dir()
[1] "file9e88423c5c2b.zip"                             "rs-graphics-5776e6df-be67-40c4-a4f7-e311eb11d978"

Please, any help with this problem?


Solution

  • library(rgdal)
    
    # get AOI
    download.file(
      "https://github.com/Leprechault/trash/raw/main/stands_example.zip",
      zip_path <- tempfile(fileext = ".zip")
    )
    unzip(zip_path, exdir = tempdir())
    setwd(tempdir())
    stands_extent <- readOGR(".", "stands_target") 
    OGR data source with driver: ESRI Shapefile 
    Source: "C:\Users\fores\AppData\Local\Temp\RtmpGSHaOM", layer: "stands_target"
    with 7 features
    It has 2 fields