{"id":16274248,"url":"https://github.com/trinker/bounding_box","last_synced_at":"2025-08-23T13:08:31.108Z","repository":{"id":17613312,"uuid":"20417394","full_name":"trinker/bounding_box","owner":"trinker","description":null,"archived":false,"fork":false,"pushed_at":"2014-06-07T02:00:47.000Z","size":5156,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T16:33:06.980Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trinker.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-02T19:56:33.000Z","updated_at":"2019-08-13T15:42:59.000Z","dependencies_parsed_at":"2022-08-31T18:30:46.867Z","dependency_job_id":null,"html_url":"https://github.com/trinker/bounding_box","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/trinker/bounding_box","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Fbounding_box","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Fbounding_box/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Fbounding_box/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Fbounding_box/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trinker","download_url":"https://codeload.github.com/trinker/bounding_box/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Fbounding_box/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271748559,"owners_count":24813985,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-10T18:27:58.290Z","updated_at":"2025-08-23T13:08:31.058Z","avatar_url":"https://github.com/trinker.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bounding_box Function\n\nThis is an R implementation of Jan Philip Matuschek's bounding box article: [*Finding Points Within a Distance of a Latitude/Longitude Using Bounding Coordinates*](http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates).\n\n```{r}\n#' Calculate Bounding Box\n#' \n#' Caclulate a bounding box for a center point given a set of coordinates.\n#' \n#' @param lat The latitude of the center point.\n#' @param lon The longitude of the center point.\n#' @param dist The distance from the center point.  \n#' @param in.miles logical.  If \\code{TRUE} uses miles as the units of \n#' \\code{dist}.  If \\code{FALSE} uses kilometers.\n#' @return Returns a matrix with max/min latitude/longitude values.\n#' @references \\url{http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates}\n#' @keywords bounding_box, coordinates\n#' @export\n#' @examples\n#' bounding_box(38.8977, 77.0366, 1)\nbounding_box \u003c- function(lat, lon, dist, in.miles = TRUE) {\n\n    ## Helper functions\n    if (in.miles) {\n        ang_rad \u003c- function(miles) miles/3958.756\n    } else {\n        ang_rad \u003c- function(miles) miles/1000\n    }\n    `%+/-%` \u003c- function(x, margin){x + c(-1, +1)*margin}\n    deg2rad \u003c- function(x) x/(180/pi)\n    rad2deg \u003c- function(x) x*(180/pi)\n    lat_range \u003c- function(latr, r) rad2deg(latr %+/-% r)\n    lon_range \u003c- function(lonr, dlon) rad2deg(lonr %+/-% dlon)\n       \n    r \u003c- ang_rad(dist)\n    latr \u003c- deg2rad(lat)\n    lonr \u003c- deg2rad(lon)\n    dlon \u003c- asin(sin(r)/cos(latr))\n\n    m \u003c- matrix(c(lon_range(lonr = lonr, dlon = dlon), \n        lat_range(latr=latr, r=r)), nrow=2, byrow = TRUE)\n\n    dimnames(m) \u003c- list(c(\"lng\", \"lat\"), c(\"min\", \"max\"))\n    m\n}\n```\n\nSo here we can look at the area within one square mile of the White House:\n\n```{r}\nbounding_box(38.89768, -77.03653, 1)\n```\n\nLet's apply it.  Here's an example plotting a bounding box around the 2012 Olympic Stadium:\n\n```{r, message=FALSE}\nlibrary(ggplot2); library(ggmap)\n\nbb \u003c- bounding_box(lon = -0.016179, lat = 51.538525, 1)\n\nmapImageData \u003c- get_map(location = c(lon = -0.016179, lat = 51.538525),\n    color = \"color\",\n    source = \"google\",\n    maptype = \"hybrid\",\n    zoom = 14)\n \nggmap(mapImageData,\n    extent = \"device\",\n    ylab = \"Latitude\",\n    xlab = \"Longitude\") + \n\tgeom_rect(aes(xmin = bb[1, 1], xmax = bb[1, 2], ymin = bb[2, 1], \n \t\tymax = bb[2, 2]), color=\"red\", fill=NA, size=2) +\n\tgeom_point(data=data.frame(lon = -0.016179, lat = 51.538525), size=7, \n\t\tcolor=\"yellow\")\n\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrinker%2Fbounding_box","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrinker%2Fbounding_box","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrinker%2Fbounding_box/lists"}