Вопрос

I am trying to use the OpenStreetMap package in R, however when I try to use the examples I found on the internet, I always get the same result - blank plot with points and labels plotted. The map image is not being plotted, just the points and text. I am a beginner R developer and can't think why this could be happening, does anyone have any ideas?

I tried opening the website to see if maps load on my computer at all, and the website works correctly.

http://www.openstreetmap.org/

Simple example I'm trying to run. I also tried a different example with text and points which are plotted.

map=openmap(c(43.611522,1.428533), c(43.598903,1.461059),type="osm")
plot(map)

Additional information after editing - result of names(map). map$bbox and str(map$tiles[[1]])

> map=openmap(c(43.611522,1.428533), c(43.598903,1.461059),type="osm")
> plot(map)
> names(map)
[1] "tiles" "bbox" 
> map$bbox
$p1
[1]  159023.6 5405519.8

$p2
[1]  162644.3 5403579.9

> str(map$tiles[[1]])
List of 5
 $ colorData : chr [1:1220080] "#BEACAC" "#BEACAC" "#BEACAC" "#BEACAC" ...
 $ bbox      :List of 2
  ..$ p1: num [1:2] 159024 5405520
  ..$ p2: num [1:2] 162644 5403580
 $ projection:Formal class 'CRS' [package "sp"] with 1 slots
  .. ..@ projargs: chr "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0     +k=1.0 +units=m +nadgrids=@null +no_defs"
 $ xres      : int 808
 $ yres      : int 1510
 - attr(*, "class")= chr "os
Это было полезно?

Решение

Try with plot(map, raster=FALSE)

This will be slower than if raster=TRUE was actually working.

The OpenStreetMap package uses the raster package to plot things. Some graphics devices have special code for drawing rasters like images and tiles, and the system should automatically figure out if it can use it. Sometimes though, the package passes raster=TRUE to the plotting function to override, and if it does this then if your system doesn't have the raster capability then you get empty rasters.

I've reported things like this to the raster maintainer and changes have been made, so unless you are already upgraded to the latest versions I'd suggest doing so.

Другие советы

Turned out that the problem was caused by working via a Remote Desktop Connection. To enable raster graphics, you need to do the following:

  1. On the server launch Remote Desktop Session Host Configuration.
  2. Under Connections, right click on RDP-Tcp and select Properties.
  3. On the Client Settings tab either uncheck LimitMaximum Color Depth or set it to 32 bits per pixel.
  4. Click OK and log out of the remote session.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top