R Under development (unstable) (2024-01-20 r85814 ucrt) -- "Unsuffered Consequences" 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.65 map images will be cached in D:\temp\Rtmp2tLG9e/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 25293 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 24545 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 10011 bytes ================================================== downloaded 10011 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 34250 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 29238 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 23844 bytes (23 KB) ================================================== downloaded 23 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 23820 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 22082 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 20957 bytes (20 KB) ================================================== downloaded 20 KB reprojecting reprojecting: 4 cycles:1 2 3 3 > # mycities = GNcities(extend(myraster,1),max=5) > 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\Rtmp2tLG9e/mapmiscCache/org/6/33/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/33/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/33/32.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/32.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/31.png cached tile D:\temp\Rtmp2tLG9e/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 , 9 tiles tile.openstreetmap.org http://tile.openstreetmap.org/ tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/33/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/33/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/33/32.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/32.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/31.png cached tile D:\temp\Rtmp2tLG9e/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\Rtmp2tLG9e/mapmiscCache/org/6/33/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/33/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/31.png cached reprojecting reprojecting: 4 cycles:1 2 3 3 > # 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\Rtmp2tLG9e/mapmiscCache/org/6/33/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/33/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/31.png cached reprojecting reprojecting: 4 cycles:1 2 3 3 > # 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\Rtmp2tLG9e/mapmiscCache/org/6/33/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/33/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/30.png cached tile D:\temp\Rtmp2tLG9e/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\Rtmp2tLG9e/mapmiscCache/org/6/33/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/33/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/31.png cached reprojecting reprojecting: 4 cycles:1 2 3 3 > # 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\Rtmp2tLG9e/mapmiscCache/org/6/33/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/33/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/31.png cached reprojecting reprojecting: 4 cycles:1 2 3 3 > # 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\Rtmp2tLG9e/mapmiscCache/org/6/33/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/33/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/30.png cached tile D:\temp\Rtmp2tLG9e/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\Rtmp2tLG9e/mapmiscCache/org/6/33/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/33/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/30.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/34/31.png cached tile D:\temp\Rtmp2tLG9e/mapmiscCache/org/6/35/30.png cached tile D:\temp\Rtmp2tLG9e/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 12437 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 16021 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 16421 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 20371 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 11328 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 22252 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 20199 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 21137 bytes (20 KB) ================================================== downloaded 20 KB reprojecting reprojecting: 10 cycles:1 2 3 4 5 6 7 8 9 9 > 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 24915 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 22547 bytes (22 KB) ================================================== downloaded 22 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 27090 bytes (26 KB) ================================================== downloaded 26 KB downloading http://tile.openstreetmap.org/17/67317/43072.png trying URL 'http://tile.openstreetmap.org/17/67317/43072.png' Content type 'image/png' length 24545 bytes (23 KB) ================================================== downloaded 23 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 24182 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 21821 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') > #' > > if(!interactive()) dev.off() null device 1 > > proc.time() user system elapsed 40.17 2.68 44.67