ggmap stamen watercolor png error

自作多情 提交于 2019-12-03 06:48:12

As a temporary fix you can do the change yourself. Type

get_stamenmap 

at the R terminal. This will dump out the code for loading the maps. You will need to edit this code and replace the function in the namespace.

Copy the code to a text editor and make if a function again by changing the first line:

get_stamenmap <- function (bbox = 

Then you need to switch over to loading jpegs. Search on png and change the text to jpg. I had two instances which looked like the text you need in the file extension, they were on line 64 and 71 for me.

64: urls <- paste(urls, ".jpg", sep = "")
71: destfile <- paste(filename, "jpg", sep = ".")

On line 75 there is the function readPNG, which you need to change to readJPEG.

tile <- readJPEG(destfile)

You will also need to ensure to load the jpeg package, i.e. library(jpeg) since ggmap does not otherwise realise this is now needed. I also needed library(plyr) but I did not figure out why - I did this because I got a later error message about ldply() which I found in that package.

Now paste this "all new" function back into the terminal. Afterwards, you need to overwrite the function embedded in the package, which is different from the local copy you just pasted into the terminal, so you need to type this:

assignInNamespace("get_stamenmap",get_stamenmap,ns="ggmap")

Now you should be ready to use qmap again. This procedure worked for me and was simpler than recompiling the package with the same changes or downloading the latest source which has these fixes and compiling.

I have had the same issue. Note that if you run

get_map(location='Auckland', source="stamen", maptype="watercolor", zoom=13)

you will get the URL(s) for the tiles you're trying to load in R. When I visit one of the URLs given, it redirects to a .jpg, instead of a .png. Hence the error is accurate - the tiles being served are not in PNG format - they're JPGs.

Looks like this is a bug in ggmap introduced by a change in Stamen's API. It appears that version 2.4 will address this; see the GitHub commit here: https://github.com/dkahle/ggmap/commit/c7c48947360351f2e86ba13d0457aa3894b51d46.

An alternative until the 2.4 is published in the library is to load the functions available in the repository and replace the ones already present on the ggmap package (as Michael answered). I just loaded the content of get_stamenmap.R and filedrawer.R (needed for url_lookup()) as was good to go with watercolor maps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!