ropensci / rnaturalearth

An R package to hold and facilitate interaction with natural earth map data :earth_africa:
http://ropensci.github.io/rnaturalearth/
Other
214 stars 24 forks source link

lakes file path directory not correct #61

Closed spencer-tassone closed 1 year ago

spencer-tassone commented 1 year ago

I am trying to open the 110 m geometry of lakes for the whole world and am getting an HTTP Error 404 Not Found message due to what I think is an incorrect file path.

When I run this command:

library(dplyr)
library(rnaturalearth)

lakes <- rnaturalearth::ne_download(scale = 110,
                                    type = 'lakes',
                                    category = 'physical') %>%
  sf::st_as_sf(lakes110, crs = 4269)

I get this error

trying URL 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip'
Error in utils::download.file(file.path(address), zip_file <- tempfile()) : 
  cannot open URL 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip'
In addition: Warning message:
In utils::download.file(file.path(address), zip_file <- tempfile()) :
  cannot open URL 'https://www.naturalearthdata.com/http/www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip': HTTP status was '404 Not Found'

When I go to the naturalearthdata.com website and search lakes I can see the download link for the 110 m lakes, which has the following filepath:

https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip

Which is a slightly different file path from what the command above is trying

Incorrect file paths that the command above is trying

1. http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip
2. https://www.naturalearthdata.com/http/www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip

The first incorrect file path is missing an s in the first http The second incorrect file path is missing a / in the second http/

z3tt commented 1 year ago

This is not an issue for lakes only but (likely) all data to be downloaded via ne_download(). At least I see the same error for multiple data sets including countries, airports and more:

cannot open URL 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip': HTTP status was '404 Not Found'

cannot open URL 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_airports.zip': HTTP status was '404 Not Found'

Dr-Joe-Roberts commented 1 year ago

I had the same issue this morning. Is there a workaround at all? I plan to use this package for teaching geospatial data visualisation next week [09/01/23].

larry77 commented 1 year ago

I confirm the same bug on my platform (I was about to open an issue, but then saw it already existed). It seems something trivial to fix, but at the same time, is there any workaround once the zip folder has been downloaded locally? I am really stuck now.

PMassicotte commented 1 year ago

Looks like they just switched to https:

http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/ne_10m_land.zip

https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/ne_10m_land.zip

PMassicotte commented 1 year ago

You can install the version from ropensci/rnaturalearth. It will work.

spencer-tassone commented 1 year ago

You can install the version from ropensci/rnaturalearth. It will work.

I cannot confirm the code from my original comment is working again. I am still getting the same error message as described in the original comment.

PMassicotte commented 1 year ago

I can confirm that your code works on my side:

rnaturalearth::ne_download(scale = 110, type = 'lakes', category = 'physical', returnclass = "sf") 
trying URL 'https://naturalearth.s3.amazonaws.com/110m_physical/ne_110m_lakes.zip'
Content type 'application/zip' length 23622 bytes (23 KB)
==================================================
downloaded 23 KB

OGR data source with driver: ESRI Shapefile 
Source: "/tmp/Rtmp3j7riO", layer: "ne_110m_lakes"
with 24 features
It has 37 fields
Integer64 fields read as strings:  scalerank ne_id 
Simple feature collection with 24 features and 37 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -124.9536 ymin: -16.53641 xmax: 109.9298 ymax: 66.9693
Geodetic CRS:  WGS 84
spencer-tassone commented 1 year ago

When I try

rnaturalearth::ne_download(scale = 110, type = 'lakes', category = 'physical', returnclass = "sf") 

I get the same error message as described in the first post

trying URL 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip'
Error in utils::download.file(file.path(address), zip_file <- tempfile()) : 
  cannot open URL 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip'
In addition: Warning message:
In utils::download.file(file.path(address), zip_file <- tempfile()) :
  cannot open URL 'https://www.naturalearthdata.com/http/www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip': HTTP status was '404 Not Found'
spencer-tassone commented 1 year ago

I can confirm that your code works on my side:

rnaturalearth::ne_download(scale = 110, type = 'lakes', category = 'physical', returnclass = "sf") 
trying URL 'https://naturalearth.s3.amazonaws.com/110m_physical/ne_110m_lakes.zip'
Content type 'application/zip' length 23622 bytes (23 KB)
==================================================
downloaded 23 KB

OGR data source with driver: ESRI Shapefile 
Source: "/tmp/Rtmp3j7riO", layer: "ne_110m_lakes"
with 24 features
It has 37 fields
Integer64 fields read as strings:  scalerank ne_id 
Simple feature collection with 24 features and 37 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -124.9536 ymin: -16.53641 xmax: 109.9298 ymax: 66.9693
Geodetic CRS:  WGS 84

It is unclear to me why/how your machine defaults to an amazon web services (aws) site when downloading the data, while mine tries the naturalearthdata.com website. Are you using any different packages?

PMassicotte commented 1 year ago

Check my earlier message about installation. If you have installed as I said, you will have to restart R.

spencer-tassone commented 1 year ago

You can install the version from ropensci/rnaturalearth. It will work.

It is unclear what you mean by "the version". I have tried re-installing rnaturalearth but that has not fixed the issue.

install.packages("rnaturalearth")
library(rnaturalearth)
rnaturalearth::ne_download(scale = 110, type = 'lakes', category = 'physical', returnclass = "sf") 
trying URL 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip'
Error in utils::download.file(file.path(address), zip_file <- tempfile()) : 
  cannot open URL 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip'
In addition: Warning message:
In utils::download.file(file.path(address), zip_file <- tempfile()) :
  cannot open URL 'https://www.naturalearthdata.com/http/www.naturalearthdata.com/download/110m/physical/ne_110m_lakes.zip': HTTP status was '404 Not Found'
Nowosad commented 1 year ago

@spencer-tassone, you need to install the developement version:

remotes::install_github("ropensci/rnaturalearth")
haleyoleynik commented 1 year ago

@spencer-tassone it just worked for me and I took these steps:

  1. Uninstall rnaturalearth
  2. Restart R
  3. devtools::install_github("ropensci/rnaturalearth")
  4. require("rnaturalearth")
  5. run rnaturalearth::ne_download(scale = 110, type = 'lakes', category = 'physical', returnclass = "sf") and make sure you have rnaturalearth:: - it didn't work for me without this
spencer-tassone commented 1 year ago

Great it just worked for me too, thanks all!

spencer-tassone commented 1 year ago

@spencer-tassone it just worked for me and I took these steps:

1. Uninstall rnaturalearth

2. Restart R

3. `devtools::install_github("ropensci/rnaturalearth")`

4. `require("rnaturalearth")`

5. run `rnaturalearth::ne_download(scale = 110, type = 'lakes', category = 'physical', returnclass = "sf")` and make sure you have `rnaturalhearth::` - it didn't work for me without this

This was very clear and helpful advice, thank you! Also there is a small typo in number 5; in the second rnaturalearth there is an extra h.

z3tt commented 1 year ago

Hi @haleyoleynik, the namespace (the double colon) shouldn't be necessary once you have loaded the package. It is good practice to use library() for that and not require() but none of them should require an explicit reference to the package, strange. For me, it works without the namespace so make sure you're package is truly loaded.