Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in ogrInfo: Cannot open layer #16

Closed
cpsievert opened this issue Mar 25, 2016 · 22 comments
Closed

Error in ogrInfo: Cannot open layer #16

cpsievert opened this issue Mar 25, 2016 · 22 comments

Comments

@cpsievert
Copy link

> library(tigris)

Attaching package:tigrisThe following object is masked frompackage:graphics:

    plot

> me <- counties("Maine", cb = TRUE)
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  : 
  Cannot open layer
In addition: Warning message:
In unzip(file_loc, exdir = cache_dir, overwrite = TRUE) :
  error 1 in extracting from zip file
> session_info()
Session info -------------------------------------------------------------------
 setting  value                       
 version  R version 3.2.4 (2016-03-10)
 system   x86_64, darwin13.4.0        
 ui       X11                         
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       Australia/Melbourne         
 date     2016-03-25                  

Packages -----------------------------------------------------------------------
 package     * version date       source        
 devtools    * 1.10.0  2016-01-23 CRAN (R 3.2.3)
 digest        0.6.9   2016-01-08 CRAN (R 3.2.3)
 foreign       0.8-66  2015-08-19 CRAN (R 3.2.4)
 fortunes      1.5-2   2013-12-14 CRAN (R 3.2.0)
 htmltools     0.3     2015-12-29 CRAN (R 3.2.3)
 htmlwidgets   0.6     2016-02-25 CRAN (R 3.2.3)
 httr          1.1.0   2016-01-28 CRAN (R 3.2.3)
 inline        0.3.14  2015-04-13 CRAN (R 3.2.0)
 lattice       0.20-33 2015-07-14 CRAN (R 3.2.4)
 magrittr      1.5     2014-11-22 CRAN (R 3.2.0)
 maptools      0.8-39  2016-01-30 CRAN (R 3.2.3)
 memoise       1.0.0   2016-01-29 CRAN (R 3.2.3)
 R6            2.1.2   2016-01-26 CRAN (R 3.2.3)
 rappdirs      0.3     2014-09-02 CRAN (R 3.2.0)
 rgdal         1.1-3   2015-12-21 CRAN (R 3.2.4)
 rgeos         0.3-17  2016-02-13 CRAN (R 3.2.4)
 sp            1.2-2   2016-02-05 CRAN (R 3.2.4)
 stringi       1.0-1   2015-10-22 CRAN (R 3.2.0)
 stringr       1.0.0   2015-04-30 CRAN (R 3.2.0)
 tigris      * 0.2.2   2016-02-15 CRAN (R 3.2.3)
 uuid          0.1-2   2015-07-28 CRAN (R 3.2.0)
@hrbrmstr
Copy link
Contributor

I'll try it on one of my 3.2.4 systems in a bit. Still on the work Mac and I'm stuck at 3.2.3 on that till one of our pipelines is done. It's working fine on this setup tho:

Session info ------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.2.3 (2015-12-10)
 system   x86_64, darwin15.2.0        
 ui       RStudio (0.99.893)          
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/New_York            
 date     2016-03-24                  

Packages ----------------------------------------------------------------------------------------------
 package  * version date       source        
 devtools * 1.10.0  2016-01-23 CRAN (R 3.2.3)
 digest     0.6.9   2016-01-08 CRAN (R 3.2.3)
 foreign    0.8-66  2015-08-19 CRAN (R 3.2.3)
 httr       1.1.0   2016-01-28 CRAN (R 3.2.3)
 lattice    0.20-33 2015-07-14 CRAN (R 3.2.3)
 magrittr   1.5     2014-11-22 CRAN (R 3.2.3)
 maptools   0.8-37  2015-09-29 CRAN (R 3.2.3)
 memoise    0.2.1   2014-04-22 CRAN (R 3.2.3)
 R6         2.1.2   2016-01-26 CRAN (R 3.2.3)
 rappdirs   0.3     2014-09-02 CRAN (R 3.2.3)
 rgdal      1.1-3   2015-12-21 CRAN (R 3.2.3)
 rgeos      0.3-15  2015-11-04 CRAN (R 3.2.3)
 sp         1.2-1   2015-10-18 CRAN (R 3.2.3)
 stringi    1.0-1   2015-10-22 CRAN (R 3.2.3)
 stringr    1.0.0   2015-04-30 CRAN (R 3.2.3)
 tigris   * 0.2.2   2016-02-15 CRAN (R 3.2.3)
 uuid       0.1-2   2015-07-28 CRAN (R 3.2.3)

image

@hrbrmstr
Copy link
Contributor

and, wow are things bad in my state

image

@walkerke
Copy link
Owner

Hmm... this is the second time this has been brought up (see #14) but the previous issue was on a different operating system. There seemed to be an issue with the cache directory that rappdirs was pointing to - I couldn't reproduce the error.

@cpsievert
Copy link
Author

Hmm, it seems to be a problem for tempdir() as well

> library(rappdirs)
> user_cache_dir()
[1] "/Users/cpsievert/Library/Caches"
> list.files("/Users/cpsievert/Library/Caches/tigris")
 [1] "cb_2014_us_county_500k.zip"          "cb_2014_us_ua10_500k.cpg"           
 [3] "cb_2014_us_ua10_500k.dbf"            "cb_2014_us_ua10_500k.prj"           
 [5] "cb_2014_us_ua10_500k.shp"            "cb_2014_us_ua10_500k.shp.ea.iso.xml"
 [7] "cb_2014_us_ua10_500k.shp.iso.xml"    "cb_2014_us_ua10_500k.shp.xml"       
 [9] "cb_2014_us_ua10_500k.shx"            "cb_2014_us_ua10_500k.zip"           
> options(tigris_use_cache = FALSE)
> library(tigris)
> me <- counties("Maine", cb = TRUE)
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  : 
  Cannot open layer
In addition: Warning message:
In unzip(file_loc, exdir = cache_dir, overwrite = TRUE) :
  error 1 in extracting from zip file

@walkerke
Copy link
Owner

It appears as though tigris::urban_areas(cb = TRUE) worked, however?

In regards to tempdir(): try setting the option not to use the cache after the library call. For example:

library(tigris)
options(tigris_use_cache = FALSE)

me <- counties('Maine', cb = TRUE)

Let me know if that still isn't working.

@cpsievert
Copy link
Author

It appears as though tigris::urban_areas(cb = TRUE) worked, however?

Yep.

try setting the option not to use the cache after the library call

That worked, thanks!

@walkerke
Copy link
Owner

Good to hear. I want to figure this out though as in both your and @ZellW's cases the folders are not unzipping as they should. @hrbrmstr any ideas why this might be happening?

@walkerke
Copy link
Owner

@cpsievert I believe I've fixed this issue in e2a0044. On occasion, Census downloads won't work (internet hiccup, the Census website is down, etc.). When this happens, tigris puts a folder in the cache directory anyway that will impede any future attempts to get the file.

Now, adding the argument refresh = TRUE will re-download the shapefile and load it correctly. I've tested myself and it is working; would you mind installing the development version from GitHub and then running me <- counties('Maine', cb = TRUE, year = 2014, refresh = TRUE) and seeing if that works? The year argument is necessary because the new version of tigris now defaults to 2015 shapefiles.

@cpsievert
Copy link
Author

Works great, thanks!

@walkerke
Copy link
Owner

Great! Sending the update to CRAN shortly.

@Erich-St
Copy link

Hi!

I'm having similar troubles as those folks before me. I tried the solutions suggested in previous comments, but to no avail. Does anybody know where the problem is?

Best regards,
Erich

sessionInfo()
R version 3.2.5 (2016-04-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] tigris_0.3.3

loaded via a namespace (and not attached):
[1] httr_1.2.1 magrittr_1.5 R6_2.1.2 rgdal_1.1-10 tools_3.2.5 foreign_0.8-66 sp_1.2-3
[8] curl_1.1 rappdirs_0.3.1 uuid_0.1-2 stringi_1.1.1 grid_3.2.5 maptools_0.8-39 stringr_1.0.0
[15] rgeos_0.3-19 lattice_0.20-33

library(tigris)

Attaching package: ‘tigris’

The following object is masked from ‘package:graphics’:

plot

us_states_20m <- states(cb = TRUE, resolution = "20m", year=2010, refresh = TRUE)
Downloading: 140 kB
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, :
Cannot open layer
In addition: Warning message:
In unzip(file_loc, exdir = cache_dir, overwrite = TRUE) :
error 1 in extracting from zip file

@walkerke
Copy link
Owner

Have a look at this open issue: #23. tigris currently supports Census boundaries from 2011 to the present; for 2010 boundaries, I recommend the UScensus2010 package.

I'm leaving the issue open as I'll probably get to it at some point, but it isn't a top priority for me. I would welcome a pull request, however.

@Erich-St
Copy link

Erich-St commented Jan 25, 2017 via email

@walkerke
Copy link
Owner

There isn't an R package for boundaries that go back that far - however you can get historical boundaries from NHGIS: https://www.nhgis.org/

@Erich-St
Copy link

Erich-St commented Jan 26, 2017 via email

@Ahmed-qureshi
Copy link

hi i am having this issue with tigris using it rails() method i used
options(tigris_use_cache = FALSE)
but still it gives

Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, :
Cannot open data source
In addition: Warning message:
In unzip(file_loc, exdir = tmp) : error 1 in extracting from zip file

code
library(tigris)

options(tigris_use_cache = FALSE)
rls <- rails()

plot(rls)

@jaybgholap
Copy link

@Ahmed-qureshi
I encountered the same error recently. It got fixed when I downgraded tigris to version 0.5.
I got an error while using tigris 0.7.

@irinasm
Copy link

irinasm commented Feb 21, 2019

I am having the same problem. adding "options(tigris_use_cache = FALSE)" did not help.
My code is this:

library(tigris)
options(tigris_use_cache = FALSE) 
geoc <- counties(cb=TRUE)

the error is this:

Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  : 
  Cannot open data source
In addition: Warning message:
In unzip(file_loc, exdir = tmp) : error 1 in extracting from zip file

@HeHuangDortmund
Copy link

I am using MAC OS.
I solved this problem by changing the OS language to english.

@alexWhitworth
Copy link

alexWhitworth commented Mar 24, 2020

@walkerke @cpsievert

counties works for me, but tracts does not.

> devtools::install_github("walkerke/tigris)
> library(tigris)
> me <- counties('Maine', cb = TRUE) 
|===========| 100%
Using FIPS code '23' for state 'Maine'
> la_geo <- tracts(state = "CA", county = "Los Angeles", cb = TRUE)
Using FIPS code '06' for state 'CA'
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  : 
  Cannot open data source
In addition: Warning message:
In unzip(file_loc, exdir = tmp) : error 1 in extracting from zip file
> options(tigris_use_cache = FALSE)
> la_geo <- tracts(state = "CA", county = "Los Angeles", cb = TRUE)
Using FIPS code '06' for state 'CA'
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  : 
  Cannot open data source
In addition: Warning message:
In unzip(file_loc, exdir = tmp) : error 1 in extracting from zip file

> rappdirs::user_cache_dir()
[1] "/Users/alexwhitworth/Library/Caches"
> list.files("/Users/alexwhitworth/Library/Caches/tigris")
character(0)

Session Info

> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tigris_0.9.3 sp_1.4-1    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4         rstudioapi_0.11    magrittr_1.5       units_0.6-6        maptools_0.9-9    
 [6] rappdirs_0.3.1     uuid_0.1-4         tidyselect_1.0.0   lattice_0.20-38    R6_2.4.1          
[11] rlang_0.4.5        stringr_1.4.0      httr_1.4.1         dplyr_0.8.5        tools_3.6.3       
[16] rgdal_1.4-8        grid_3.6.3         KernSmooth_2.23-16 e1071_1.7-3        DBI_1.1.0         
[21] class_7.3-15       yaml_2.2.1         assertthat_0.2.1   tibble_2.1.3       crayon_1.3.4      
[26] sf_0.8-1           purrr_0.3.3        curl_4.3           glue_1.3.2         stringi_1.4.6     
[31] compiler_3.6.3     pillar_1.4.3       classInt_0.4-2     foreign_0.8-76     pkgconfig_2.0.3   

Edit: hmmm..... It just worked, 5 minutes later. The census database must have just been down

@laurenmarietta
Copy link

I'll pile on to say I've been having this issue for the county_subdivisions function (not for other geographies) for a few weeks now. I've tried implementing all the fixes here, to no avail. Using tigris version 0.8.2 on Mac OS Big Sur.

Here's my code:

library(tigris)
options(tigris_use_cache = FALSE)
county_subdivisions("MA", cb=T, refresh=T)

And the error:
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, : Cannot open layer

@walkerke
Copy link
Owner

Hi @laurenmarietta - the version of tigris you are running is two years old, which may mean that you also have some other outdated packages. I'd recommend updating tigris to the latest version and also updating the sf package; my hunch is that this will solve the problem (I'm running your code without error).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants