ceramic

read image server tiles direct with GDAL, or download image server tiles to a local cache

https://github.com/hypertidy/ceramic

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.2%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

read image server tiles direct with GDAL, or download image server tiles to a local cache

Basic Info
Statistics
  • Stars: 92
  • Watchers: 3
  • Forks: 6
  • Open Issues: 3
  • Releases: 0
Created over 7 years ago · Last pushed over 2 years ago
Metadata Files
Readme Changelog Code of conduct

README.Rmd

---
output: github_document
editor_options: 
  chunk_output_type: console
---





[![CRAN status](https://www.r-pkg.org/badges/version/ceramic)](https://CRAN.R-project.org/package=ceramic)
[![R-CMD-check](https://github.com/hypertidy/ceramic/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/hypertidy/ceramic/actions/workflows/R-CMD-check.yaml)


```{r setup, include = FALSE}

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%", 
  dev = "png"
  #, dev.args = list( jpeg = list(quality =50))
)
options(warn = -1)
```
# ceramic

The goal of ceramic is to obtain web map tiles. Use a spatial object to define the region of interest. 




```{r extent1}
library(ceramic)
roi <- ext(100, 160, -50, 10)
im <- cc_location(roi)

plotRGB(im)
```

The terra package is always loaded by ceramic, so we can assume the use of its functions, ceramic accepts a wider range of inputs than terra does however. 

We can use  wk, geos, terra, raster, sp, sf, or stars objects, or an input lon,lat point
and a buffer (in metres) to define an extent. This provides a very easy way to
obtain imagery or elevation data for any almost any region using our own data.

```{r extent2, fig.width=8, fig.height=10}
sql <- "SELECT shapeGroup FROM geoBoundariesCGAZ_ADM0 WHERE shapeGroup IN ('BOL')"
dsn <- "/vsizip//vsicurl/https://github.com/wmgeolab/geoBoundaries/raw/main/releaseData/CGAZ/geoBoundariesCGAZ_ADM0.zip"
bol <- vect(dsn, query = sql)

im <- cc_location(bol)
plotRGB(im)
```

Even if the data uses a map projection it will be converted into a region to match the Mercator extents used by Mapbox image servers. 

```{r warn, include = FALSE}
options(warn = -1)
```

```{r nz-spData, include = FALSE}
data("nz", package = "spData")

library(sf)
im_nz2 <- cc_location(nz)
plotRGB(im_nz2)
plot(st_transform(nz, crs(im_nz2))[0], add = TRUE, col = rainbow(nrow(nz), alpha = 0.5))
```

There are basic heuristics to decide if data is projected or just in "longitude,latitude" in the usual way. 

Raster elevation data is also available. 

```{r}
north <- nz[nz$Island == "North", ]
dem_nz <- cc_elevation(north, type = "elevation-tiles-prod" )


## plot elevation data for NZ north
dem_nz[!dem_nz > 0] <- NA

plot(dem_nz, col = grey.colors(128))
plot(st_transform(st_cast(north, "MULTILINESTRING")["Name"], terra::crs(dem_nz)), add = TRUE, lwd = 5)

```

## I thought you said *tiles*?

Indeed, here's a function called `read_tiles()`, it shares the same interface as `get_tiles()`. 


```{r read-tiles}
read_tiles()
```


Note that, the `cc_location()` and `cc_elevation()` functions no longer use tiles, they read directly from the internet using GDAL and are not related to the tile download facilities. 

But, they used to run `get_tiles()` behind the scenes. The separation is still a little unfinished, but I want ceramic to have separation of loading data from the internet with downloading tiles. 

This function and its counterparts `get_tiles_zoom()`, `get_tiles_dim()` and `get_tiles_buffer()` will *only download files*. 

```{r tiles}
tile_summ <- get_tiles_zoom(north, zoom = 8)
length(tile_summ$files)
str(tile_summ$tiles)

(tile_rect <- tiles_to_polygon(ceramic_tiles(zoom = 8)))

```

This is really for expert use when you want to control the downloaded tile files yourself directly. 


## Providers

The default map provider is [Mapbox](https://www.mapbox.com/), but ceramic is written for general usage and also provides access to the [joerd AWS tiles](https://github.com/tilezen/joerd/) via the `type = "elevation-tiles-prod"` argument. 

```{r}
pt <- cbind(175.6082, -37.994)
nz_z12 <- cc_location(pt, buffer  = 100000,  type = "elevation-tiles-prod")
```

```{r, eval=FALSE, include = FALSE}
north_carolina <- sf::read_sf(system.file("gpkg/nc.gpkg", package = "sf", mustWork = TRUE))
nc_image <- cc_location(north_carolina)

rowan_dem <- cc_elevation(dplyr::filter(north_carolina, NAME == "Rowan"))
rowan_dem
```


## Installation

Install ceramic from CRAN with: 

```R
install.packages("ceramic")
```

You can install the development version of ceramic from  Github. 

```R
## install.packages("remotes")
remotes::install_github("hypertidy/ceramic")
```

Set your mapbox API key with 

```R
Sys.setenv(MAPBOX_API_KEY = "")
```




## Example

This complete example gets tiled imagery that we can use as real data.

The code here

-   generates a bounding box in longitude-latitude
- reads the raster data using GDAL

then we look at the actual tiles involved, 

-   uses [slippymath](https://CRAN.r-project.org/package=slippymath) to
    find sensible tiles for the region
-   downloads them to a local cache
-   summarizes the tiles as a spatial (wk) object


```{r example01}
library(ceramic)
## a point in longlat, and a buffer with in metres
pt <- cbind(136, -34)
im <- cc_location(pt, buffer = c(1e6, 5e5), type = "mapbox.satellite")
op <- par(bg = "black")
plotRGB(im)

## get the approximately matching tiles (zoom is magic here, it's all wrapped - needs thought)

tileset <- get_tiles(pt, buffer = c(1e6, 5e5))
tiles <- ceramic_tiles(zoom = tileset$tiles$zoom, type = "mapbox.satellite")
plot(tiles_to_polygon(tiles), add = TRUE, border = "white")



middle <- function(x, y) {
  x + (y - x)/2
}
text(middle(tiles$xmin, tiles$xmax), middle(tiles$ymin, tiles$ymax), lab = sprintf("[%i,%i]", tiles$tile_x, tiles$tile_y), 
     col = "yellow")
     
par(op)
```


## Tasmap maps


```{r tasmap}
library(ceramic)
library(terra)
template <- rast(ext(527358, 527880, 5252204, 5252704), res = .3, crs = "EPSG:32755")
ortho <- cc_location(template, type = "tasmap_orthophoto")

plot(ortho)

plot(cc_location(template, type = "tasmap_street"))

plot(cc_location(template, type = "tasmap_tasmapraster"))

plot(cc_location(template, type = "tasmap_hillshade"))

plot(cc_location(template, type = "tasmap_hillshadegrey"))
plot(cc_location(template, type = "tasmap_esgismapbookpublic"))  ## nope
plot(cc_location(template, type = "tasmap_topographic"))


plot(cc_location(template, type = "tasmap_tasmap25k"))  ## also 100k, 250k, 500k
 
```



```{r smash,include=FALSE}
quantize_figs <- function(dir = "man/figures") {
  f <- fs::dir_ls(dir, regexp = "png$")
  for (i in seq_along(f)) {
    tf <- tempfile(fileext = ".png")
    im <- magick::image_read(f[i])
    magick::image_write(magick::image_quantize(im), tf)
    
    ## I don't know how to properly unlink the original pointer, this just a guess (not sure it matters)
    rm(im)
    fs::file_delete(f[i])
    fs::file_move(tf, f[i])
  }
} 
quantize_figs()
```



---

Please note that the 'ceramic' project is released with a [Contributor Code of Conduct](https://github.com/hypertidy/ceramic/blob/master/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.



Owner

  • Name: hypertidy
  • Login: hypertidy
  • Kind: organization
  • Location: Hobart, Australia

[ ... ]

GitHub Events

Total
  • Watch event: 1
Last Year
  • Watch event: 1

Committers

Last synced: over 3 years ago

All Time
  • Total Commits: 169
  • Total Committers: 4
  • Avg Commits per committer: 42.25
  • Development Distribution Score (DDS): 0.024
Top Committers
Name Email Commits
Michael Sumner m****r@g****m 165
Enrico Spinielli e****i@g****m 2
Miles McBain m****n@g****m 1
Greg Macfarlane g****e@g****m 1

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 48
  • Total pull requests: 6
  • Average time to close issues: about 1 year
  • Average time to close pull requests: 3 days
  • Total issue authors: 12
  • Total pull request authors: 5
  • Average comments per issue: 2.6
  • Average comments per pull request: 0.5
  • Merged pull requests: 6
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • mdsumner (35)
  • mpadge (2)
  • ajlyons (1)
  • Quartaer (1)
  • vronizor (1)
  • djouallah (1)
  • rsbivand (1)
  • jdsher (1)
  • zacdav (1)
  • natereal (1)
  • Robinlovelace (1)
  • SpatLyu (1)
Pull Request Authors
  • espinielli (2)
  • olivroy (2)
  • MilesMcBain (1)
  • rhijmans (1)
  • gregmacfarlane (1)
Top Labels
Issue Labels
help wanted (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 254 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 2
  • Total versions: 4
  • Total maintainers: 1
cran.r-project.org: ceramic

Download Online Imagery Tiles

  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 2
  • Downloads: 254 Last month
Rankings
Stargazers count: 4.3%
Forks count: 9.6%
Average: 19.0%
Dependent repos count: 19.3%
Dependent packages count: 28.8%
Downloads: 33.3%
Maintainers (1)
Last synced: 11 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.5.0 depends
  • crsmeta * imports
  • curl * imports
  • dplyr * imports
  • fs >= 1.3.0 imports
  • glue * imports
  • graphics * imports
  • jpeg * imports
  • magrittr * imports
  • png * imports
  • purrr * imports
  • rappdirs * imports
  • raster * imports
  • reproj >= 0.4.2 imports
  • rlang * imports
  • slippymath >= 0.3.0 imports
  • sp * imports
  • spex >= 0.6.0.9005 imports
  • stats * imports
  • tibble * imports
  • utils * imports
  • covr * suggests
  • rgdal * suggests
  • spelling * suggests
  • testthat * suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action v4.4.1 composite
  • actions/checkout v3 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite