library('mapmisc')
## Loading required package: sp
## Loading required package: raster
## map images will be cached in /tmp/RtmpPX4Ncb/mapmiscCache
if(!exists('mapmiscCachePath'))
mapmiscCachePath = system.file('extdata', package='mapmisc')
if(!exists('mapmiscCacheReadOnly'))
mapmiscCacheReadOnly = TRUE
options(
mapmiscCachePath = mapmiscCachePath,
mapmiscCacheReadOnly = mapmiscCacheReadOnly,
mapmiscVerbose=TRUE)
getOption("mapmiscCachePath")
## [1] "/home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache"
getOption("mapmiscCacheReadOnly")
## [1] FALSE
myraster = raster(matrix(0,10,10),xmn=8,xmx=18,ymn=0,ymx=10,
crs=CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
)
values(myraster) = seq(0,1,len=ncell(myraster))
myPoints = SpatialPoints(myraster,
proj4string=CRS(proj4string(myraster)))[
seq(1,ncell(myraster),len=5)]
plot(myraster)
points(myPoints)
only do the following if rgdal is available
if(require('rgdal', quietly=TRUE)) {
# utm zone 32
utmproj = CRS("+init=epsg:3064")
myrasterUTM = projectRaster(myraster, crs=utmproj)
myPointsUTM = spTransform(myPoints, utmproj)
plot(myrasterUTM)
points(myPointsUTM)
myPointsMercator = spTransform(myPoints,
crsMerc)
myplot = function(first,second=first) {
par(mar=c(0,0,0,0))
plot(first)
plot(mytiles, add=TRUE)
plot(second,add=TRUE,col='blue')
# points(mycities,col='red')
# text(mycities, labels=mycities$name, col='red',pos=4)
scaleBar(first)
}
thezoom=6
# only do the following if running unix (because nsl is available)
# and if the OpenStreetMap.org web site can be accessed
# raster, result will be in project of the raster (long-lat)
mytiles = openmap(x=extend(myraster,1),
zoom=thezoom)
# mycities = GNcities(extend(myraster,1),max=5)
myplot(myraster, myPoints)
# slash at the end
mytiles = openmap(extend(myraster,1),zoom=thezoom,
path="http://tile.openstreetmap.org/")
# mycities = GNcities(extend(myraster,1),max=5)
myplot(myraster, myPoints)
# no http at beginning
mytiles = openmap(extend(myraster,1),path="tile.openstreetmap.org")
# mycities = GNcities(extend(myraster,1),max=5)
myplot(myraster, myPoints)
# extent, tiles will be long-lat
mytiles = openmap(extent(myraster),zoom=thezoom)
# cities will be long=lat
# mycities = GNcities(extent(myraster),max=5,lang="fr")
# myplot(mycities,myPoints)
# give the bbox, long lat
mytiles = openmap(bbox(myraster),zoom=thezoom)
# mycities = GNcities(bbox(myraster),max=5)
# myplot(mycities,myPoints)
# give points, result is CRS of points (long-lat)
mytiles = openmap(myPoints,zoom=thezoom)
# mycities = GNcities(myPoints,max=5,lang="es")
myplot(myPoints)
# UTM raster
mytiles = openmap(myrasterUTM,zoom=thezoom)
# mycities = GNcities(myrasterUTM,max=5)
myplot(myrasterUTM, myPointsUTM)
# supply a crs
mytiles = openmap(x=extent(myrasterUTM),zoom=thezoom,
crs=proj4string(myrasterUTM))
# mycities = GNcities(myrasterUTM,max=5)
myplot(myrasterUTM, myPointsUTM)
# utm points
mytiles = openmap(myPointsUTM,zoom=thezoom)
# mycities = GNcities(myPointsUTM,max=5)
myplot(myPointsUTM)
# specify different output crs
mytiles = openmap(myPointsUTM, crs=CRS("+init=epsg:4326"))
# mycities = GNcities(myPoints,max=5)
myplot(myPoints)
# one point only
mytiles = openmap(coordinates(myPoints)[1,], zoom=4)
myplot(myPoints)
} # end have rgdal
## rgdal: version: 1.2-15, (SVN revision 691)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 2.2.1, released 2017/06/23
## Path to GDAL shared files: /usr/share/gdal/2.2
## GDAL binary built with GEOS: TRUE
## Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
## Path to PROJ.4 shared files: (autodetected)
## Linking to sp version: 1.2-5
## zoom is 6 , 9 tiles
## http://tile.openstreetmap.org/
## http://tile.openstreetmap.org/
## downloading http://tile.openstreetmap.org/6/33/30.png
## downloading http://tile.openstreetmap.org/6/33/31.png
## downloading http://tile.openstreetmap.org/6/33/32.png
## downloading http://tile.openstreetmap.org/6/34/30.png
## downloading http://tile.openstreetmap.org/6/34/31.png
## downloading http://tile.openstreetmap.org/6/34/32.png
## downloading http://tile.openstreetmap.org/6/35/30.png
## downloading http://tile.openstreetmap.org/6/35/31.png
## downloading http://tile.openstreetmap.org/6/35/32.png
## reprojecting 589824 cells...done
## copying colortable for http...tile.openstreetmap.org.
## zoom is 6 , 9 tiles
## http://tile.openstreetmap.org/
## http://tile.openstreetmap.org/
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/32.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/32.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/32.png cached
## reprojecting 589824 cells...done
## copying colortable for http...tile.openstreetmap.org.
## zoom is 6 , 9 tiles
## tile.openstreetmap.org
## http://tile.openstreetmap.org/
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/32.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/32.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/32.png cached
## reprojecting 589824 cells...done
## copying colortable for tile.openstreetmap.org
## zoom is 6 , 6 tiles
## http://tile.openstreetmap.org/
## http://tile.openstreetmap.org/
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/31.png cached
## copying colortable for http...tile.openstreetmap.org.
## zoom is 6 , 6 tiles
## http://tile.openstreetmap.org/
## http://tile.openstreetmap.org/
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/31.png cached
## copying colortable for http...tile.openstreetmap.org.
## zoom is 6 , 6 tiles
## http://tile.openstreetmap.org/
## http://tile.openstreetmap.org/
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/31.png cached
## reprojecting 393216 cells...done
## copying colortable for http...tile.openstreetmap.org.
## zoom is 6 , 9 tiles
## http://tile.openstreetmap.org/
## http://tile.openstreetmap.org/
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/32.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/32.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/32.png cached
## reprojecting 589824 cells...done
## copying colortable for http...tile.openstreetmap.org.
## zoom is 6 , 9 tiles
## http://tile.openstreetmap.org/
## http://tile.openstreetmap.org/
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/32.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/32.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/32.png cached
## reprojecting 589824 cells...done
## copying colortable for http...tile.openstreetmap.org.
## zoom is 6 , 6 tiles
## http://tile.openstreetmap.org/
## http://tile.openstreetmap.org/
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/31.png cached
## reprojecting 393216 cells...done
## copying colortable for http...tile.openstreetmap.org.
## zoom is 6 , 6 tiles
## http://tile.openstreetmap.org/
## http://tile.openstreetmap.org/
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/33/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/34/31.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/30.png cached
## tile /home/patrick/workspaceOxygen/diseasemapping/www/mapmiscCache/org/6/35/31.png cached
## reprojecting 393216 cells...done
## copying colortable for http...tile.openstreetmap.org.
## zoom is 4 , 1 tiles
## http://tile.openstreetmap.org/
## http://tile.openstreetmap.org/
## downloading http://tile.openstreetmap.org/4/8/7.png
## copying colortable for http...tile.openstreetmap.org.
ams city hall
cityHall = SpatialPoints(cbind( 4.891111, 52.373056), proj4string=crsLL)
# cityHall = spTransform(cityHall,CRS("+init=epsg:28992"))
if(require('rgdal', quietly=TRUE)) {
cityHall = spTransform(cityHall,CRS("+init=epsg:32631"))
mytiles = openmap(cityHall, buffer=50)
map.new(mytiles)
plot(mytiles, add=TRUE)
points(cityHall, pch=3, col='blue',cex=4)
scaleBar(mytiles, 'topleft')
} # end have rgdal
## zoom is 18 , 4 tiles
## http://tile.openstreetmap.org/
## http://tile.openstreetmap.org/
## downloading http://tile.openstreetmap.org/18/134633/86146.png
## downloading http://tile.openstreetmap.org/18/134633/86147.png
## downloading http://tile.openstreetmap.org/18/134634/86146.png
## downloading http://tile.openstreetmap.org/18/134634/86147.png
## reprojecting 262144 cells...done
## copying colortable for http...tile.openstreetmap.org.