{"id":16272632,"url":"https://github.com/milesmcbain/slippymath","last_synced_at":"2025-03-16T13:31:13.315Z","repository":{"id":56936847,"uuid":"156339546","full_name":"MilesMcBain/slippymath","owner":"MilesMcBain","description":"R functions for dealing with slippy map tile servers.","archived":false,"fork":false,"pushed_at":"2019-07-16T02:55:46.000Z","size":2238,"stargazers_count":66,"open_issues_count":3,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-14T23:44:39.725Z","etag":null,"topics":["google-maps","mapbox","osm","r","slippy-map"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MilesMcBain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-06T06:55:30.000Z","updated_at":"2024-11-14T18:16:37.000Z","dependencies_parsed_at":"2022-08-21T07:20:45.299Z","dependency_job_id":null,"html_url":"https://github.com/MilesMcBain/slippymath","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MilesMcBain%2Fslippymath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MilesMcBain%2Fslippymath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MilesMcBain%2Fslippymath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MilesMcBain%2Fslippymath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MilesMcBain","download_url":"https://codeload.github.com/MilesMcBain/slippymath/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243816922,"owners_count":20352454,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google-maps","mapbox","osm","r","slippy-map"],"created_at":"2024-10-10T18:18:33.466Z","updated_at":"2025-03-16T13:31:12.767Z","avatar_url":"https://github.com/MilesMcBain.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# slippymath\n[![Travis build status](https://travis-ci.org/MilesMcBain/slippymath.svg?branch=master)](https://travis-ci.org/MilesMcBain/slippymath) [![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/MilesMcBain/slippymath?branch=master\u0026svg=true)](https://ci.appveyor.com/project/MilesMcBain/slippymath) [![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing) [![CRAN status](https://www.r-pkg.org/badges/version/slippymath)](https://cran.r-project.org/package=slippymath)\n\nR functions for dealing with slippy map tile servers (Google maps, Open Street\nMap, Mapbox, Stamen et. al.)\n\nThe goal of this package is to take a bunch of logic that was lying around in\ndefunct packages and obscure wikis and make it #rstats cannon in a way that is\ndecoupled from any particular tile service or visualisation front end. Happy\nmapping!\n\n# Installation\n\n```r\n## Dev version\nremotes::install_github(\"milesmcbain/slippymath\")\n\n## CRAN version\ninstall.packages('slippymath')\n```\n\n# Usage\n\n\n## Tile maths\nLook at how many tiles you might need: \n```r\nlibrary(sf)\n\nuluru_bbox \u003c-\n  st_bbox(c(xmin = 131.02084,\n            xmax = 131.0535,\n            ymin = -25.35461,\n            ymax = -25.33568),\n          crs = st_crs(\"+proj=longlat +ellps=WGS84\"))\n\nbbox_tile_query(uluru_bbox)\n\n# A tibble: 17 x 8\n#    x_min  y_min  x_max  y_max y_dim x_dim total_tiles  zoom\n#    \u003cdbl\u003e  \u003cdbl\u003e  \u003cdbl\u003e  \u003cdbl\u003e \u003cdbl\u003e \u003cdbl\u003e       \u003cdbl\u003e \u003cint\u003e\n# 1      3      2      3      2     1     1           1     2\n# 2      6      4      6      4     1     1           1     3\n# 3     13      9     13      9     1     1           1     4\n# 4     27     18     27     18     1     1           1     5\n# 5     55     36     55     36     1     1           1     6\n# 6    110     73    110     73     1     1           1     7\n# 7    221    146    221    146     1     1           1     8\n# 8    442    293    442    293     1     1           1     9\n# 9    884    586    884    586     1     1           1    10\n#10   1769   1173   1769   1173     1     1           1    11\n#11   3538   2346   3539   2346     1     2           2    12\n#12   7077   4692   7078   4692     1     2           2    13\n#13  14154   9384  14156   9385     2     3           6    14\n#14  28309  18769  28312  18771     3     4          12    15\n#15  56619  37538  56625  37542     5     7          35    16\n#16 113239  75076 113251  75084     9    13         117    17\n#17 226478 150153 226502 150168    16    25         400    18\n```\n\nGet a grid of slippy map tile coordinates for a bounding box, given a `zoom`, or\nguess a zoom given a `max_tiles`:\n\n```r\nbbox_to_tile_grid(uluru_bbox, max_tiles = 15)\n\n#$tiles\n#       x     y\n#1  28309 18769\n#2  28310 18769\n#3  28311 18769\n#4  28312 18769\n#5  28309 18770\n#6  28310 18770\n#7  28311 18770\n#8  28312 18770\n#9  28309 18771\n#10 28310 18771\n#11 28311 18771\n#12 28312 18771\n#\n#$zoom\n#[1] 15\n#\n#attr(,\"class\")\n#[1] \"tile_grid\"\n```\n\nFetch a grid using your favourite tile server API. Creep on many tile providers [here](http://leaflet-extras.github.io/leaflet-providers/preview/). \n\nHere's a Mapbox example:\n\n```r\n\nlibrary(purrr)\nlibrary(curl)\nlibrary(glue)\n\ntile_grid \u003c- bbox_to_tile_grid(uluru_bbox, max_tiles = 15)\n\nmapbox_query_string \u003c-\n  paste0(\"https://api.mapbox.com/v4/mapbox.satellite/{zoom}/{x}/{y}.jpg90\",\n         \"?access_token=\",\n         Sys.getenv(\"MAPBOX_API_KEY\"))\n\nimages \u003c-\n  pmap(tile_grid$tiles,\n       function(x, y, zoom){\n         outfile \u003c- glue(\"{x}_{y}.jpg\")\n         curl_download(url = glue(mapbox_query_string),\n                       destfile = outfile) \n         outfile \n       },\n       zoom = tile_grid$zoom)\n\n```\n\n## Tile compositing\n\nYou can compose a list of images and a corresponding tile grid to a spatially\nreferenced raster, meaning you can plot over it with `tmap` etc.\n\n```r\nlibrary(raster)\nlibrary(rgdal)\n\nraster_out \u003c- compose_tile_grid(tile_grid, images)\n\n## A convenient wrapper for raster image exports using png::writePNG.\nraster_to_png(raster_out, \"uluru.png\")\n\n```\nResult:\n![](inst/media/uluru.png)\n\n© \u003ca href='https://www.mapbox.com/about/maps/'\u003eMapbox\u003c/a\u003e © \u003ca href='http://www.openstreetmap.org/copyright'\u003eOpenStreetMap\u003c/a\u003e \u003cstrong\u003e\u003ca href='https://www.mapbox.com/map-feedback/' target='_blank'\u003eImprove this map\u003c/a\u003e\u003c/strong\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilesmcbain%2Fslippymath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilesmcbain%2Fslippymath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilesmcbain%2Fslippymath/lists"}