Title: | Create Geographic and Non-Geographic Map Tiles |
---|---|
Description: | Creates geographic map tiles from geospatial map files or non-geographic map tiles from simple image files. This package provides a tile generator function for creating map tile sets for use with packages such as 'leaflet'. In addition to generating map tiles based on a common raster layer source, it also handles the non-geographic edge case, producing map tiles from arbitrary images. These map tiles, which have a non-geographic, simple coordinate reference system (CRS), can also be used with 'leaflet' when applying the simple CRS option. Map tiles can be created from an input file with any of the following extensions: tif, grd and nc for spatial maps and png, jpg and bmp for basic images. This package requires 'Python' and the 'gdal' library for 'Python'. 'Windows' users are recommended to install 'OSGeo4W' (<https://trac.osgeo.org/osgeo4w/>) as an easy way to obtain the required 'gdal' support for 'Python'. |
Authors: | Matthew Leonawicz [aut, cre] , Alex M Chubaty [ctb] |
Maintainer: | Matthew Leonawicz <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.2 |
Built: | 2024-12-10 05:45:12 UTC |
Source: | https://github.com/ropensci/tiler |
Create geographic and non-geographic map tiles from a file.
tile( file, tiles, zoom, crs = NULL, resume = FALSE, viewer = TRUE, georef = TRUE, ... )
tile( file, tiles, zoom, crs = NULL, resume = FALSE, viewer = TRUE, georef = TRUE, ... )
file |
character, input file. |
tiles |
character, output directory for generated tiles. |
zoom |
character, zoom levels. Example format: |
crs |
character, Proj4 string. Use this to force set the CRS of a loaded
raster object from |
resume |
logical, only generate missing tiles. |
viewer |
logical, also create |
georef |
logical, for non-geographic tiles only. If |
... |
additional arguments for projected maps: reprojection method or
any arguments to |
This function supports both geographic and non-geographic tile generation.
When file
is a simple image file such as png
, tile()
generates
non-geographic, simple CRS tiles. Files that can be loaded by the raster
package yield geographic tiles as long as file
has projection information.
If the raster object's Proj4 string is NA
, it falls back on non-geographic
tile generation and a warning is thrown.
Choice of appropriate zoom levels for non-geographic image files may depend
on the size of the image. A zoom
value may be partially ignored for image
files under certain conditions. For instance using the example map.png
below, when passing strictly zoom = n
where n
is less than 3, this still
generates tiles for zoom n
up through 3.
Supported simple CRS/non-geographic image file types include png
, jpg
and
bmp
. For projected map data, supported file types include three types
readable by the raster
package: grd
, tif
, and nc
(requires ncdf4
).
Other currently unsupported file types passed to file
throw an error.
If a map file loadable by raster
is a single-layer raster object, tile
coloring is applied. To override default coloring of data and noData
pixels, pass the additional arguments col
and colNA
to ...
.
Multi-layer raster objects are rejected with an error message. The only
exception is a three- or four-band raster, which is assumed to represent
red, green, blue and alpha channels, respectively.
In this case, processing will continue but coloring arguments are ignored as
unnecessary.
Prior to tiling, a geographically-projected raster layer is reprojected to
EPSG:4326 only if it has some other projection. The only reprojection
argument available through ...
is method
, which can be "bilinear"
(default) or"ngb"
. If complete control over reprojection is required, this
should be done prior to passing the rasterized file to the tile
function.
Then no reprojection is performed by tile()
. When file
consists of RGB or
RGBA bands, method
is ignored if provided and reprojection uses nearest
neighbor.
It is recommended to avoid using a projected 4-band RGBA raster file.
However, the alpha channel appears to be ignored anyway. gdal2tiles
gives
an internal warning. Instead, create your RGBA raster file in unprojected
form and it should pass through to gdal2tiles
without any issues.
Three-band RGB raster files are unaffected by reprojection.
gdal2tiles
generates TMS tiles. If expecting XYZ, for example when using
with Leaflet, you can change the end of the URL to your hosted tiles from
{z}/{x}/{y}.png
to {z}/{x}/{-y}.png
.
This function is supported by two different versions of gdal2tiles
. There
is the standard version, which generates geospatial tiles in TMS format. The
other version of gdal2tiles} handles basic image files like a matrix of rows and columns, using a simple Cartesian coordinate system based on pixel dimensions of the image file. See the Leaflet JS library and
leaflet'
package documentation for working with custom tiles in Leaflet.
nothing is returned but tiles are written to disk.
# non-geographic/simple CRS x <- system.file("maps/map.png", package = "tiler") tiles <- file.path(tempdir(), "tiles") tile(x, tiles, "2-3") ## Not run: # unprojected map x <- system.file("maps/map_wgs84.tif", package = "tiler") tile(x, tiles, 0) # projected map x <- system.file("maps/map_albers.tif", package = "tiler") tile(x, tiles, 0) ## End(Not run)
# non-geographic/simple CRS x <- system.file("maps/map.png", package = "tiler") tiles <- file.path(tempdir(), "tiles") tile(x, tiles, "2-3") ## Not run: # unprojected map x <- system.file("maps/map_wgs84.tif", package = "tiler") tile(x, tiles, 0) # projected map x <- system.file("maps/map_albers.tif", package = "tiler") tile(x, tiles, 0) ## End(Not run)
Create an HTML file that displays a tile preview using Leaflet.
tile_viewer(tiles, zoom, width = NULL, height = NULL, georef = TRUE, ...)
tile_viewer(tiles, zoom, width = NULL, height = NULL, georef = TRUE, ...)
tiles |
character, directory where tiles are stored. |
zoom |
character, zoom levels full range. Example format: |
width |
|
height |
|
georef |
logical, for non-geographic tiles only. If |
... |
additional optional arguments include |
This function creates a file preview.html
adjacent to the tiles
base
directory. When loaded in the browser, this file displays map tiles from the
adjacent folder. For example, if tiles are stored in project/tiles
, this
function creates project/preview.html
.
By default, tile()
creates this file. The only reasons to call
tile_viewer()
directly after producing map tiles are: (1) if
viewer = FALSE
was set in the call to tile()
, (2) if tile()
was called
multiple times, e.g., for different batches of zoom levels, and thus the most
recent call did not use the full zoom range, or (3) preview.html
was
deleted for some other reason.
If calling this function directly, ensure that the min and max zoom, and
original image pixel dimensions if applicable, match the generated tiles.
These arguments are passed to tile_viewer} automatically when called within
tile(), based on the source file provided to
tile()'.
nothing is returned, but a file is written to disk.
tile_viewer(file.path(tempdir(), "tiles"), "3-7") # requires existing tiles
tile_viewer(file.path(tempdir(), "tiles"), "3-7") # requires existing tiles
Creates geographic map tiles from geospatial map files or non-geographic map tiles from simple image files. This package provides a tile generator function for creating map tile sets for use with packages such as 'leaflet'. In addition to generating map tiles based on a common raster layer source, it also handles the non-geographic edge case, producing map tiles from arbitrary images. These map tiles, which have a non-geographic, simple coordinate reference system (CRS), can also be used with 'leaflet' when applying the simple CRS option. Map tiles can be created from an input file with any of the following extensions: tif, grd and nc for spatial maps and png, jpg and bmp for basic images. This package requires 'Python' and the 'gdal' library for 'Python'. 'Windows' users are recommended to install 'OSGeo4W' (https://trac.osgeo.org/osgeo4w/) as an easy way to obtain the required 'gdal' support for 'Python'.
Maintainer: Matthew Leonawicz [email protected] (ORCID)
Other contributors:
Alex M Chubaty [email protected] (ORCID) [contributor]
Useful links:
Report bugs at https://github.com/ropensci/tiler/issues
Options for tiler package.
tiler_options(...)
tiler_options(...)
... |
a list of options. |
On Windows systems, if the system paths for python.exe
and OSGeo4W.bat
are not added to the system PATH variable, they must be provided by the user
after loading the package. It is recommended to add these to the system path
so they do not need to be specified for every R session.
As long as you are using OSGeo4W, you can ignore the Python path specification and do not even need to install it on your system separately; OSGeo4W will use its own built-in version.
The recommended way to have GDAL available to Python in Windows is to install OSGeo4W. This is commonly installed along with QGIS.
By default, tiler_options()
is set on package load with
osgeo4w = "OSGeo4W.bat"
. It is expected that the user has added the path to
this file to the system PATH variable in Windows. For example, if it is
installed to C:/OSGeo4W64/OSGeo4W.bat
, add C:/OSGeo4W64
to your PATH. If
you do want to specify the path in the R session using tiler_options()
,
provide the full path including the filename. See the example.
None of this applies to other systems. As long as the system requirements,
Python and GDAL, are installed, then tile()
should generate tiles without
getting or setting any tiler_options()
.
The function prints all set options if called with no arguments. When setting options, nothing is returned.
tiler_options() tiler_options(osgeo4w = "C:/OSGeo4W64/OSGeo4W.bat")
tiler_options() tiler_options(osgeo4w = "C:/OSGeo4W64/OSGeo4W.bat")
The tiler package creates geographic map tiles from geospatial map files or non-geographic map tiles from simple image files.
This package provides a tile generator function for creating map tile sets
for use with packages such as leaflet
. In addition to generating map tiles
based on a common raster layer source, it also handles the non-geographic
edge case, producing map tiles from arbitrary images. These map tiles, which
have a non-geographic simple coordinate reference system (CRS), can also be
used with leaflet
when applying the simple CRS option.
Map tiles can be created from an input file with any of the following
extensions: tif
, grd
and nc
for spatial maps and png
, jpg
and bmp
for basic images.
This package requires Python and the gdal
library for Python. Windows users
are recommended to install OSGeo4W
: https://trac.osgeo.org/osgeo4w/
as an
easy way to obtain the required gdal
support for Python in Windows.
View map tiles in the browser using leaflet.
view_tiles(tiles)
view_tiles(tiles)
tiles |
character, directory where tiles are stored. |
This function opens preview.html
in a web browser. This file displays
map tiles in a Leaflet widget. The file is created when tile()
is called to
generate the map tiles, unless viewer = FALSE
. Alternatively, it is created
(or re-created) subsequent to tile creation using tile_viewer()
.
nothing is returned, but the default browser is launched.
# launches browser; requires an existing tile set ## Not run: view_tiles(file.path(tempdir(), "tiles"))
# launches browser; requires an existing tile set ## Not run: view_tiles(file.path(tempdir(), "tiles"))