Ggmap stamen watercolor png error

I would really like the help / ideas about the problem that I am encountering with ggmap and watercolor exposure.

I get the same error message every time I try to create a watercolor map of the stamens:

"Error in readPNG(destfile) : file is not in PNG format" 

Here are some examples of simple code that returns this error:

 qmap("new-york", zoom=13, source="stamen", maptype="watercolor") 

or

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

I am using the r version: [Default] [64-bit] C: \ Program Files \ R \ R-3.0.2 under windows 8

I understand that a few people posted this issue, but only a few, and I did not see any explanation / suggestions. I am in a dead end and disappointment, and I really hope that someone with more experience than me has encountered (and solved) this problem. Thanks in advance or any help you can provide

+8
png ggmap stamen-maps
source share
3 answers

As a temporary fix, you can do it yourself. Type of

 get_stamenmap 

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

Copy the code into a text editor and do it if the function changes the first line again:

 get_stamenmap <- function (bbox = 

Then you need to go to download jpeg. Search in png and change the text to jpg. I had two instances that looked like the text you need in the file extension, they were on lines 64 and 71 for me.

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

Line 75 has a readPNG function that needs to be changed to readJPEG.

 tile <- readJPEG(destfile) 

You will also need to ensure that the jpeg package is downloaded, that is, the library (jpeg), since ggmap does not otherwise understand that this is necessary now. I also need a library (plyr), but I did not understand why - I did this because I received a later error message ldply (), which I found in this package.

Now insert this "all new" function back into the terminal. After that, you need to overwrite the function built into the package, which is different from the local copy that you just pasted into the terminal, so you need to type this:

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

You should now be ready to use qmap again. This procedure worked for me and was easier than recompiling the package with the same changes or downloading the latest source that has these fixes and compilation.

+14
source share

I had the same problem. Please note that if you run

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

you will get the URL (s) for the fragments that you are trying to load in R. When I visit one of the indicated URLs, it redirects to .jpg, not .png. Therefore, the error is correct - the tiles that are served are not in PNG format - this is JPG.

This seems to be a bug in ggmap introduced by the Stamen API change. Version 2.4 seems to consider this; see here GitHub: https://github.com/dkahle/ggmap/commit/c7c48947360351f2e86ba13d0457aa3894b51d46 .

+2
source share

An alternative before publishing 2.4 in the library is to load the functions available in the repository and replace those already present in the ggmap package (as Michael replied). I just downloaded the contents of get_stamenmap.R and filedrawer.R (necessary for url_lookup ()), since it was nice to go with watercolor maps.

+1
source share

All Articles