BLUF: you need more than just the .shp
file. Unzip more (all) of the files and you'll get differing results.
For each below, I'm using unzip
on the command line to unzip only the files in the step. In between, I remove files not being tested. I do not believe there is a way in R to unz(..)
in order to get to all files.
Just 94e2701.shp
: error
.shp
and .prj
: error
.shp
and .dbf
file: error
.shp
and .shx
: partial success, does not fill CRS
data <- sf::st_read("94e2701.shp")
# Reading layer `94e2701' from data source `C:\Users\r2\AppData\Local\Temp\Rtmpqoj4GE\94e2701.shp' using driver `ESRI Shapefile'
# Simple feature collection with 2 features and 0 fields
# Geometry type: POLYGON
# Dimension: XY
# Bounding box: xmin: -100.4 ymin: 28.27 xmax: -91.4 ymax: 39.77
# CRS: NA
.shp
, .shx
, and .dbf
: same as 4, no CRS
.shp
, .shx
, .dbf
, and .prj
: success
data <- sf::st_read("94e2701.shp")
# Reading layer `94e2701' from data source `C:\Users\r2\AppData\Local\Temp\Rtmpqoj4GE\94e2701.shp' using driver `ESRI Shapefile'
# Simple feature collection with 2 features and 7 fields
# Geometry type: POLYGON
# Dimension: XY
# Bounding box: xmin: -100.4 ymin: 28.27 xmax: -91.4 ymax: 39.77
# Geodetic CRS: GCS_Sphere_EMEP
Incidentally, the thing that made me check this is one paragraph in ?sf::st_read
:
Note that stray files in data source directories (such as *.dbf
) may lead to spurious errors that accompanying '*.shp' are missing.
This made me wonder if the presence of other files in the directory were causing your problem.
I do not believe there is a way in R to unz(..)
in order to get to all files. If you don't want to unzip them into your current directory (just "look" at the files and discard later), then you can create a temp directory, unzip into that, and open the file from there.
dir.create(td <- tempfile())
unzip(tmp, exdir = td)
data <- sf::st_read(file.path(td, f_name))
# Reading layer `94e2701' from data source `C:\Users\r2\AppData\Local\Temp\Rtmpqoj4GE\file185581a1d4d01\94e2701.shp' using driver `ESRI Shapefile'
# Simple feature collection with 2 features and 7 fields
# Geometry type: POLYGON
# Dimension: XY
# Bounding box: xmin: -100.4 ymin: 28.27 xmax: -91.4 ymax: 39.77
# Geodetic CRS: GCS_Sphere_EMEP