R version 4.4.0 alpha (2024-04-01 r86264 ucrt) Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > #+ setup > > library('mapmisc') Loading required package: terra terra 1.7.71 map images will be cached in D:\temp\RtmpsDZ8ih/mapmiscCache > > #if(!exists('mapmiscCachePath')) > # mapmiscCachePath = system.file('extdata', package='mapmisc') > > #if(!exists('mapmiscCacheReadOnly')) > # mapmiscCacheReadOnly = TRUE > > > options( + # mapmiscCachePath = mapmiscCachePath, + # mapmiscCacheReadOnly = mapmiscCacheReadOnly, + mapmiscVerbose=TRUE) > > #getOption("mapmiscCachePath") > #getOption("mapmiscCacheReadOnly") > #' > > if(!interactive()) pdf("openmap.pdf") > > #+ simplePlot > myraster = rast(ext(8,18,0,10), crs=crsLL) > values(myraster) = seq(0,1,len=ncell(myraster)) > > myPoints = as.points(myraster)[ + seq(1,ncell(myraster),len=5)] > > plot(myraster) > points(myPoints) > #' > #' > #+ africaPlots > > # utm zone 32 > utmproj = crs("+init=epsg:3064") > myrasterUTM = project(myraster, utmproj) > myPointsUTM = project(myPoints, utmproj) > plot(myrasterUTM) > points(myPointsUTM) > > myPointsMercator = project(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 > > print(1) [1] 1 > > # 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) http://tile.openstreetmap.org/ http://tile.openstreetmap.org/ downloading http://tile.openstreetmap.org/6/33/30.png trying URL 'http://tile.openstreetmap.org/6/33/30.png' Content type 'image/png' length 25329 bytes (24 KB) ================================================== downloaded 24 KB downloading http://tile.openstreetmap.org/6/33/31.png trying URL 'http://tile.openstreetmap.org/6/33/31.png' Content type 'image/png' length 24542 bytes (23 KB) ================================================== downloaded 23 KB downloading http://tile.openstreetmap.org/6/33/32.png trying URL 'http://tile.openstreetmap.org/6/33/32.png' Content type 'image/png' length 10007 bytes ================================================== downloaded 10007 bytes downloading http://tile.openstreetmap.org/6/34/30.png trying URL 'http://tile.openstreetmap.org/6/34/30.png' Content type 'image/png' length 34242 bytes (33 KB) ================================================== downloaded 33 KB downloading http://tile.openstreetmap.org/6/34/31.png trying URL 'http://tile.openstreetmap.org/6/34/31.png' Content type 'image/png' length 29451 bytes (28 KB) ================================================== downloaded 28 KB downloading http://tile.openstreetmap.org/6/34/32.png trying URL 'http://tile.openstreetmap.org/6/34/32.png' Content type 'image/png' length 23443 bytes (22 KB) ================================================== downloaded 22 KB downloading http://tile.openstreetmap.org/6/35/30.png trying URL 'http://tile.openstreetmap.org/6/35/30.png' Content type 'image/png' length 23773 bytes (23 KB) ================================================== downloaded 23 KB downloading http://tile.openstreetmap.org/6/35/31.png trying URL 'http://tile.openstreetmap.org/6/35/31.png' Content type 'image/png' length 22203 bytes (21 KB) ================================================== downloaded 21 KB downloading http://tile.openstreetmap.org/6/35/32.png trying URL 'http://tile.openstreetmap.org/6/35/32.png' Content type 'image/png' length 20546 bytes (20 KB) ================================================== downloaded 20 KB reprojecting reprojecting: 4 cycles:1 2 3 3 > terra::is.int(mytiles) [1] TRUE TRUE TRUE > > mytiles2 = rast(attributes(mytiles)$source) > has.RGB(mytiles2) [1] TRUE > plot(mytiles2) > terra::is.int(mytiles2) [1] TRUE TRUE TRUE > > theFile = tempfile(fileext='.tif') > writeRaster(mytiles, theFile) > mytiles3 = rast(theFile) > has.RGB(mytiles3) [1] TRUE > plot(mytiles3) > terra::is.int(mytiles3) [1] TRUE TRUE TRUE > > > myplot(myraster, myPoints) > > print(2) [1] 2 > > > # slash at the end > mytiles = openmap(extend(myraster,1),zoom=thezoom, + path="http://tile.openstreetmap.org/") http://tile.openstreetmap.org/ http://tile.openstreetmap.org/ tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/32.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/32.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/32.png cached reprojecting reprojecting: 4 cycles:1 2 3 3 > # mycities = GNcities(extend(myraster,1),max=5) > myplot(myraster, myPoints) > print(3) [1] 3 > > > # no http at beginning > mytiles = openmap(extend(myraster,1),path="tile.openstreetmap.org") zoom is 6 , 8 tiles tile.openstreetmap.org http://tile.openstreetmap.org/ tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/32.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/32.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/32.png cached reprojecting reprojecting: 4 cycles:1 2 3 3 > # mycities = GNcities(extend(myraster,1),max=5) > myplot(myraster, myPoints) > > > print(4) [1] 4 > > > # extent, tiles will be long-lat > mytiles = openmap(ext(myraster),zoom=thezoom) http://tile.openstreetmap.org/ http://tile.openstreetmap.org/ tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/31.png cached reprojecting reprojecting: 3 cycles:1 2 2 > # cities will be long=lat > # mycities = GNcities(extent(myraster),max=5,lang="fr") > # myplot(mycities,myPoints) > > print(5) [1] 5 > > > # give the bbox, long lat > mytiles = openmap(ext(myraster),zoom=thezoom) http://tile.openstreetmap.org/ http://tile.openstreetmap.org/ tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/31.png cached reprojecting reprojecting: 3 cycles:1 2 2 > # mycities = GNcities(bbox(myraster),max=5) > # myplot(mycities,myPoints) > > > print(6) [1] 6 > > > # give points, result is CRS of points (long-lat) > mytiles = openmap(myPoints,zoom=thezoom) http://tile.openstreetmap.org/ http://tile.openstreetmap.org/ tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/31.png cached reprojecting reprojecting: 3 cycles:1 2 2 > # mycities = GNcities(myPoints,max=5,lang="es") > myplot(myPoints) > > print(7) [1] 7 > > > # UTM raster > mytiles = openmap(myrasterUTM,zoom=thezoom) http://tile.openstreetmap.org/ http://tile.openstreetmap.org/ tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/31.png cached reprojecting reprojecting: 3 cycles:1 2 2 > # mycities = GNcities(myrasterUTM,max=5) > myplot(myrasterUTM, myPointsUTM) > > print(8) [1] 8 > > > # supply a crs > mytiles = openmap(x=ext(myrasterUTM),zoom=thezoom, + crs=crs(myrasterUTM)) http://tile.openstreetmap.org/ http://tile.openstreetmap.org/ tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/31.png cached reprojecting reprojecting: 3 cycles:1 2 2 > # mycities = GNcities(myrasterUTM,max=5) > myplot(myrasterUTM, myPointsUTM) > > print(9) [1] 9 > > > # utm points > mytiles = openmap(myPointsUTM,zoom=thezoom) http://tile.openstreetmap.org/ http://tile.openstreetmap.org/ tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/31.png cached reprojecting reprojecting: 3 cycles:1 2 2 > # mycities = GNcities(myPointsUTM,max=5) > myplot(myPointsUTM) > > print(10) [1] 10 > > > # specify different output crs > mytiles = openmap(myPointsUTM, crs=crsLL) zoom is 6 , 6 tiles http://tile.openstreetmap.org/ http://tile.openstreetmap.org/ tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/33/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/34/31.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/30.png cached tile D:\temp\RtmpsDZ8ih/mapmiscCache/org/6/35/31.png cached reprojecting reprojecting: 3 cycles:1 2 2 > # mycities = GNcities(myPoints,max=5) > myplot(myPoints) > > print(11) [1] 11 > > > # one point only > mytiles = openmap(x=crds(myPoints)[1,], zoom=4, crs=crs(myPoints), buffer=10, fact=2) http://tile.openstreetmap.org/ http://tile.openstreetmap.org/ downloading http://tile.openstreetmap.org/4/7/6.png trying URL 'http://tile.openstreetmap.org/4/7/6.png' Content type 'image/png' length 12454 bytes (12 KB) ================================================== downloaded 12 KB downloading http://tile.openstreetmap.org/4/7/7.png trying URL 'http://tile.openstreetmap.org/4/7/7.png' Content type 'image/png' length 16088 bytes (15 KB) ================================================== downloaded 15 KB downloading http://tile.openstreetmap.org/4/7/8.png trying URL 'http://tile.openstreetmap.org/4/7/8.png' Content type 'image/png' length 364 bytes ================================================== downloaded 364 bytes downloading http://tile.openstreetmap.org/4/8/6.png trying URL 'http://tile.openstreetmap.org/4/8/6.png' Content type 'image/png' length 16436 bytes (16 KB) ================================================== downloaded 16 KB downloading http://tile.openstreetmap.org/4/8/7.png trying URL 'http://tile.openstreetmap.org/4/8/7.png' Content type 'image/png' length 20397 bytes (19 KB) ================================================== downloaded 19 KB downloading http://tile.openstreetmap.org/4/8/8.png trying URL 'http://tile.openstreetmap.org/4/8/8.png' Content type 'image/png' length 11341 bytes (11 KB) ================================================== downloaded 11 KB downloading http://tile.openstreetmap.org/4/9/6.png trying URL 'http://tile.openstreetmap.org/4/9/6.png' Content type 'image/png' length 22215 bytes (21 KB) ================================================== downloaded 21 KB downloading http://tile.openstreetmap.org/4/9/7.png trying URL 'http://tile.openstreetmap.org/4/9/7.png' Content type 'image/png' length 20237 bytes (19 KB) ================================================== downloaded 19 KB downloading http://tile.openstreetmap.org/4/9/8.png trying URL 'http://tile.openstreetmap.org/4/9/8.png' Content type 'image/png' length 21204 bytes (20 KB) ================================================== downloaded 20 KB reprojecting reprojecting: 12 cycles:1 2 3 4 5 6 7 8 9 10 11 11 > myplot(myPoints) > > print(12) [1] 12 > #' > #' > #' ams city hall > #+ ams > cityHall = vect(cbind(4.891111, 52.373056), + crs=crsLL) > # cityHall = spTransform(cityHall,CRS("+init=epsg:28992")) > cityHall = project(cityHall,crs("+init=epsg:32631")) > mytiles = openmap(cityHall, buffer=50) zoom is 17 , 6 tiles http://tile.openstreetmap.org/ http://tile.openstreetmap.org/ downloading http://tile.openstreetmap.org/17/67316/43072.png trying URL 'http://tile.openstreetmap.org/17/67316/43072.png' Content type 'image/png' length 24977 bytes (24 KB) ================================================== downloaded 24 KB downloading http://tile.openstreetmap.org/17/67316/43073.png trying URL 'http://tile.openstreetmap.org/17/67316/43073.png' Content type 'image/png' length 22522 bytes (21 KB) ================================================== downloaded 21 KB downloading http://tile.openstreetmap.org/17/67316/43074.png trying URL 'http://tile.openstreetmap.org/17/67316/43074.png' Content type 'image/png' length 27127 bytes (26 KB) ================================================== downloaded 26 KB downloading http://tile.openstreetmap.org/17/67317/43073.png trying URL 'http://tile.openstreetmap.org/17/67317/43073.png' Content type 'image/png' length 24057 bytes (23 KB) ================================================== downloaded 23 KB downloading http://tile.openstreetmap.org/17/67317/43074.png trying URL 'http://tile.openstreetmap.org/17/67317/43074.png' Content type 'image/png' length 21860 bytes (21 KB) ================================================== downloaded 21 KB reprojecting reprojecting: 2 cycles:1 1 > > map.new(mytiles) > plot(mytiles, add=TRUE) > points(cityHall, pch=3, col='blue',cex=4) > scaleBar(mytiles, 'topleft', bty='n', col='red') > #' > > # transparency > > secondMap = openmap( + c(-11, 9), + buffer=2, maxTiles = 5, + fact=2 + ) zoom is 5 , 4 tiles http://tile.openstreetmap.org/ http://tile.openstreetmap.org/ downloading http://tile.openstreetmap.org/5/14/14.png trying URL 'http://tile.openstreetmap.org/5/14/14.png' Content type 'image/png' length 13717 bytes (13 KB) ================================================== downloaded 13 KB downloading http://tile.openstreetmap.org/5/14/15.png trying URL 'http://tile.openstreetmap.org/5/14/15.png' Content type 'image/png' length 4818 bytes ================================================== downloaded 4818 bytes downloading http://tile.openstreetmap.org/5/15/14.png trying URL 'http://tile.openstreetmap.org/5/15/14.png' Content type 'image/png' length 15678 bytes (15 KB) ================================================== downloaded 15 KB downloading http://tile.openstreetmap.org/5/15/15.png trying URL 'http://tile.openstreetmap.org/5/15/15.png' Content type 'image/png' length 18907 bytes (18 KB) ================================================== downloaded 18 KB reprojecting reprojecting: 3 cycles:1 2 2 > transMap2 = tonerToTrans(secondMap, mostCommon=1:2, threshold = 200, + col = 'red') > map.new(transMap2, bg='green') > plot(transMap2, add=TRUE) > > transMap3 = rast(attributes(transMap2)$source) > map.new(transMap2, bg='green') > plot(transMap2, add=TRUE) > > > > if(!interactive()) dev.off() null device 1 > > proc.time() user system elapsed 52.76 3.07 57.70