User,
There are a few things you can do. The best is to install rgdal
and change the mapserver format parameter on your call to a geographic format, like GeoTIFF ('Gtiff
). The parameter options are here. This will preserve the georeferencing. Once rgdal
is installed, you can read the file very easily:
url <- "http://demo.mapserver.org/cgi-bin/wms?version=1.1.1&service=WMS&request=GetMap&VERSION=1.1.1&LAYERS=continents&WIDTH=500&HEIGHT=500&BBOX=0,45,15,60&SRS=EPSG:4326&FORMAT=Gtiff"
download.file(url, destfile="my.tiff")
map <- brick("my.tiff")
map2 <- raster(map, layer=2)
map
class : RasterBrick
dimensions : 500, 500, 250000, 3 (nrow, ncol, ncell, nlayers)
resolution : 0.03, 0.03 (x, y)
extent : 0, 15, 45, 60 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : ~/my.tiff
names : my.1, my.2, my.3
min values : 0, 0, 0
max values : 255, 255, 255
map2
class : RasterLayer
band : 2
dimensions : 500, 500, 250000 (nrow, ncol, ncell)
resolution : 0.03, 0.03 (x, y)
extent : 0, 15, 45, 60 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : ~/my.tiff
names : my.2
values : 0, 255 (min, max)
If you want to use the png format, it will be easier if you use the png
package:
library(png)
library(RCurl)
url <-"http://demo.mapserver.org/cgi-bin/wms?version=1.1.1&service=WMS&request=GetMap&VERSION=1.1.1&LAYERS=continents&WIDTH=500&HEIGHT=500&BBOX=0,45,15,60&SRS=EPSG:4326&FORMAT=image/png"
map_png <- getBinaryURL(url)
xx <- readPNG(map_png)
map <- raster(xx[,,2]) # The png is read as an array, and your data is in the second layer.