I know this is a very specific question about a specific package but I can't seem to be able to deal with it on my own so I'm seeking help. I'd like to use the {leaidr} package (GitHub - ivelasq/leaidr: An R Package for U.S. School District Shapefiles) to download shapefiles for US school districts and have followed the instructions written by Isabella here (%>% dreams - An even easier-to-use R package for school district shapefiles) but I can't seem to get it to work. Specifically, when I download the shapefile for a particular state using the lea_get function as she did, I got the following output
trying URL 'https://github.com/datalorax/us-district-shapefiles/raw/master/individ-districts/47.dbf'
Content type 'application/octet-stream' length 210592 bytes (205 KB)
downloaded 205 KB
trying URL 'https://github.com/datalorax/us-district-shapefiles/raw/master/individ-districts/47.prj'
Content type 'text/plain; charset=utf-8' length 147 bytes
downloaded 147 bytes
trying URL 'https://github.com/datalorax/us-district-shapefiles/raw/master/individ-districts/47.shp'
Content type 'application/octet-stream' length 7345380 bytes (7.0 MB)
downloaded 7.0 MB
trying URL 'https://github.com/datalorax/us-district-shapefiles/raw/master/individ-districts/47.shx'
Content type 'application/octet-stream' length 1364 bytes
downloaded 1364 bytes
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, :
Cannot open layer
In addition: Warning messages:
1: OGR support is provided by the sf and terra packages among others
2: OGR support is provided by the sf and terra packages among others
Essentially there is a "cannot open layer error" toward the end that I can't deal with. Any help would be greatly appreciated. Thank you!
Works for me:
library(leaidr)
tn <- lea_get("tn")
# Warning: OGR support is provided by the sf and terra packages among others
# Warning: OGR support is provided by the sf and terra packages among others
# Warning: OGR support is provided by the sf and terra packages among others
# Warning: OGR support is provided by the sf and terra packages among others
# Warning: OGR support is provided by the sf and terra packages among others
# Warning: OGR support is provided by the sf and terra packages among others
# OGR data source with driver: ESRI Shapefile
# Source: "/tmp/RtmpAxM7Cb/47", layer: "47"
# with 158 features
# It has 18 fields
str(tn)
# Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
# ..@ data :'data.frame': 158 obs. of 18 variables:
# .. ..$ STATEFP : chr [1:158] "47" "47" "47" "47" ...
# .. ..$ ELSDLEA : chr [1:158] NA NA NA NA ...
[...]
# ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
# .. .. ..@ projargs: chr "+proj=longlat +ellps=GRS80 +no_defs"
# .. .. ..$ comment: chr "GEOGCRS[\"GRS 1980(IUGG, 1980)\",\n DATUM[\"D_unknown\",\n ELLIPSOID[\"GRS80\",6378137,298.257222101,"| __truncated__
# ..$ comment: chr "TRUE"
Created on 2023-05-15 with reprex v2.0.2
Try to get the files again. If doesn't work, download them directly from github (GitHub - datalorax/us-district-shapefiles: Individual district shapefiles from leaidir package) -- either clone them or download zip archive, unpack and read using sf::read_sf() function like:
sf::read_sf("/tmp/RtmpPBW4E8/47/47.shp")
# Simple feature collection with 158 features and 18 fields
# Geometry type: MULTIPOLYGON
# Dimension: XY
# Bounding box: xmin: -90.3103 ymin: 34.98292 xmax: -81.6469 ymax: 36.67826
# Geodetic CRS: GRS 1980(IUGG, 1980)
# # A tibble: 158 × 19
# STATEFP ELSDLEA SCSDLEA UNSDLEA GEOID NAME LSAD LOGRADE HIGRADE MTFCC SDTYP
# <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
# 1 47 <NA> 47073 <NA> 4747… Hawk… 00 09 12 G5410 A
# 2 47 <NA> 47123 <NA> 4747… Monr… 00 09 12 G5410 A
# 3 47 <NA> 47002 <NA> 4747… Arli… 00 09 12 G5410 A
# 4 47 <NA> 47187 <NA> 4747… Will… 00 09 12 G5410 A
# 5 47 <NA> 47189 <NA> 4747… Wils… 00 09 12 G5410 A
# 6 47 <NA> 47031 <NA> 4747… Coff… 00 09 12 G5410 A
# 7 47 <NA> 47029 <NA> 4747… Cock… 00 09 12 G5410 A
# 8 47 <NA> 47077 <NA> 4747… Hend… 00 09 12 G5410 A
# 9 47 <NA> 47143 <NA> 4747… Rhea… 00 09 12 G5410 A
# 10 47 <NA> 47149 <NA> 4747… Ruth… 00 07 12 G5410 A
# # ℹ 148 more rows
# # ℹ 8 more variables: FUNCSTAT <chr>, ALAND <dbl>, AWATER <dbl>,
# # INTPTLAT <chr>, INTPTLON <chr>, GEO_YEAR <chr>, SCHOOLYEAR <chr>,
# # geometry <MULTIPOLYGON [°]>
Please note /tmp/Rxxx/47.shp is just a temporary path in my environment, yours would be different.
Regards,
Grzegorz
Thanks so much
So this works great, and I was able to get the data and do things to them. I do still want to be able to learn how to do things automatically remotely without downloading the shapefiles first though. Do you know what might have happened when I tried the original approach? In the instructions written by the author of the package, she said one must have a GITHUB_PAT before you can run lea_get, which I do. Essentially what I did is the following:
- I created a PAT
- I used the
{gitcreds} package to set my PAT in my environment
- Then I ran
lea_get but still got the same "cannot open layer" error message as before.
Any thoughts?