Description Usage Arguments Details Author(s) See Also Examples
makeTile creates from a GDAL raster file a leaflet compatible tile structure in a given directory. Additionally it produces a correct map.types list for the use with projView
1 2 3 4 5 | makeTile(x = NULL, outPath = NULL, scalec = (0,8848), s_epsg =NULL ,
t_srs = "+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 +wktext +no_defs", t_epsg =
"EPSG:3857", rType = "average", attribution = "to be done", cLat = NULL,
cLon = NULL, zoom = NULL, res = NULL, srvrUrl = "http://localhost:4321/")
|
x |
character GDAL raster file name or a |
outPath |
character path where the tiles will be generated. Note it is always
extented by |
scale |
numeric. (c(src_min,src_max,dst_min,dst_max)). Rescale the input
pixels values from the range src_min to src_max to the range dst_min to
dst_max. |
s_epsg |
character source proj4 string |
t_srs |
character target proj4 string |
t_epsg |
character target EPSG code |
rType |
character resampling method for |
cLat |
numeric center of Latitude of the leaflet map object has to be in decimal degrees |
cLon |
numeric center of Longitude of the leaflet map object has to be in decimal degrees |
zoom |
numeric if you want to override the automatic calculation of maxZoom you can provide here a value up to 21 |
res |
numeric if you want to override the automatic calculation of the resolution you can provide a predifined list like c(512,256,128) |
srvrUrl |
character the root address of the locale http daemon default see details, seealso |
GDALFormat |
character see GDAL formats |
The integration of local tiles in leaflet is first of all straightforward. You can easyly generate them with gdal2tyles. Actually the modified version of commenthol is used, that has some leaflet specific arguments and engages all available cpus for tiling.
The basic concept is focused on piping the result to projView. That means for each tile a nested map.types list is generated. For convenience reasons this list is also saved in the root directory of the tiles for later use. For more information about this list and serving have a look at online help of projView
Nevertheless one has to take care of some pitfalls.
For the first it seems to be more efficient to override the concept of
createWidget which copys all necessary files of a htmlwidget instance
to the temporary path and then serves location with the the build in http
daemon of RStudio. Imagine if you just have 6-8 SRTM tiles you need to copy
about 1-2 GB of tiles to the temporary directory. An easy solution is to use
a seperate http daemon as httd from the package servr.
The physical generation of raster tiles is with the help of the gdal tools
fairly simple. Nevertheless it is a bit tricky to glue the raster tiles at
the correct position in the map frame because Leaflet is made for mapping of
seamless and continuously existing tiles like the OSM ones.
Owing to this concept you have to rescale each raster on the given canvas of the browser.
Additionally there you must define the zoom levels which you want to use. Unlike the OSM tiles that
have a defined resolution, the local raster files usually have a generic pixel resolution
as a function of the sensor and the post-processing. To meet the 256 pixel tiling
concept this original resolution has to be scaled to the tiles.
In the end maketile uses the original or reprojected resolution of the pixel as reference for the
maximum zoom level which is synchronized with the OSM zoom levels. Therefore the pixel resolution
depends on (1) the original and/or (2) the projected resolution.
To keep
overlays and raster tiles geometrically in line, the leaflet "bounds" settings
is applied strictly, so you sometimes you may have to zoom some levels into
or pan around the map to see the background tiles ...
Chris Reudenbach
NOTE: tile serving usually would work from the local file system without
engaging a http daemon. Due to security issues this scenario is a pretty
complex topic. To do soo you have to override the default security properties
of your browser wich is NOT encouraged. See
Wikipedia for some
basic expalanation. You may override this setting (here for
chrome/chromium),
but again this is a first order security vulneration.
So it is strictly
recommended to use a local http server to provide full access to local tiles
and files. There are several solutions within R. Most easiest way to do so is
the package httd
.
Nevertheless it is much more convenient to
install seperatly a http daemon. If you are not used to the topic the
twistd daemon is a very good cross platform
powerful, save and simple solution. For some basic information and
installation advices have a look at stackoverflow
simplehttpserver.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | ## Not run:
### we need a running gdal with all python bindings ###
require(raster)
require("curl")
require(servr)
### Typical workflow (1) start http deamon (2) makeTile, (3) use projView()
## get Denmark vector data
gadmDNK <- getGeoData(name="GADM",country="DNK",level="1")
## get SRTM elevation data for the Danish coast area
r<-getGeoData(name="SRTM",xtent = extent(11,11,58,58), merge=TRUE)
## start http daemon
servr::httd("~/tmp/data/makeTile/srtm",daemon=TRUE)
## First pseudomercator
map.typesList<-makeTile(x=r,outPath="/home/creu/tmp/data/makeTile/srtm",
cLat=56.5,
cLon=11,
attribution = " <a href='https://github.com/kartena/Proj4Leaflet'> Proj4Leaflet</a> | <a href='http://srtm.csi.cgiar.org/'>SRTM CGIAR</a> | <a href='http://www.gadm.org'>GADM</a> | <a href='http://spatialreference.org/ref/sr-org/7483/'> EPSG:3857</a>")
## map it
mapview::projView(gadmDNK , map.types = map.typesList$layerName)
## define new target projection note then you must provide the source projection
s_epsg<-"EPSG:4326"
t_epsg<-"EPSG:32632"
t_srs<-"+proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
## create tiles and parameter list
map.typesList<-makeTile(x=r,outPath="/home/creu/tmp/data/makeTile/srtm",
s_epsg=s_epsg,
t_srs=t_srs,
t_epsg=t_epsg,
cLat=56.5,
cLon=11,
attribution = "<a href='https://github.com/kartena/Proj4Leaflet'> Proj4Leaflet</a> | <a href='http://srtm.csi.cgiar.org/'>SRTM CGIAR</a> | <a href='http://www.gadm.org'>GADM</a> | <a href='http://spatialreference.org/ref/epsg/32632/'> EPSG:32632</a>")
## map it
mapview::projView(gadmDNK , map.types = map.typesList$layerName)
## stop all daemon instances
servr::daemon_stop(daemon_list())
####### data from Quantarctica, http://www.quantarctica.org #######
## create persistant temp folder
tmpDir<-"~/tmp/data/quantartica"
## get Camps data
data(campsQ2)
## choose a file
fn<-paste0(tmpDir,"/Quantarctica2/Basemap/Terrain/ETOPO1_DEM.tif")
## define target projection
s_epsg="EPSG:3031"
t_epsg="EPSG:3031"
t_srs="+proj=stere +lat_0=-90 +lat_ts=-71 +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"
## create tiles and parameter list
map.typesList<-makeTile(x=fn,outPath="~/tmp/data/makeTile/quantica",
s_epsg=s_epsg,
t_srs=t_srs,
t_epsg=t_epsg,
cLat=-90,
cLon=0,
attribution = "<a href='https://github.com/kartena/Proj4Leaflet'> Proj4Leaflet</a> | <a href='http://www.quantarctica.org'> Quantarctica </a> provided by: <a href='http://www.npolar.no/en'>Norwegian Polar Institute</a> | <a href='https://github.com/kartena/Proj4Leaflet'> Proj4Leaflet</a> |<a href='http://spatialreference.org/ref/epsg/wgs-84-antarctic-polar-stereographic/'> EPSG3031</a>")
## strt http daemon
servr::httd("~/tmp/data/makeTile/quantica/",daemon=TRUE)
## map it
mapview::projView(campsQ2 , map.types = map.typesList$layerName)
## stop all daemon instances
daemon_stop(daemon_list())
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.