Browse Source

basic functionality

master
boB Rudis 8 years ago
parent
commit
0d7182623d
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 7
      .Rbuildignore
  2. 25
      .travis.yml
  3. 22
      DESCRIPTION
  4. 2
      LICENSE
  5. 12
      NAMESPACE
  6. 2
      NEWS.md
  7. 7
      R/albersusa-package.R
  8. 39
      R/albersusa.R
  9. 82
      R/proj.r
  10. 42
      README.Rmd
  11. 6
      albersusa.Rproj
  12. 58
      inst/extdata/composite_us_states.geojson
  13. BIN
      inst/extdata/states.rda
  14. 14
      man/albersusa.Rd
  15. 30
      man/us_aeqd_proj.Rd
  16. 31
      man/us_eqdc_proj.Rd
  17. 28
      man/us_laea_proj.Rd
  18. 28
      man/us_lcc_proj.Rd
  19. 23
      man/us_longlat_proj.Rd
  20. 23
      man/usa_composite.Rd
  21. 2
      tests/test-all.R
  22. 6
      tests/testthat/test-albersusa.R

7
.Rbuildignore

@ -0,0 +1,7 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.travis\.yml$
^README\.*md$
^README\.*html$
^NOTES\.*md$
^NOTES\.*html$

25
.travis.yml

@ -0,0 +1,25 @@
language: r
warnings_are_errors: true
sudo: required
env:
global:
- CRAN: http://cran.rstudio.com
notifications:
email:
on_success: change
on_failure: change
script: ./travis-tool.sh run_tests
on_failure:
- ./travis-tool.sh dump_logs
branches:
except:
- /-expt$/
notifications:
email:
on_success: change
on_failure: change

22
DESCRIPTION

@ -0,0 +1,22 @@
Package: albersusa
Type: Package
Title: Tools, Shapefiles & Data to Work with an 'AlbersUSA' Composite Projection
Version: 0.1.0
Date: 2016-03-28
Author: Bob Rudis (@hrbrmstr)
Maintainer: Bob Rudis <bob@rudis.net>
Description: Tools, Shapefiles & Data to Work with an 'AlbersUSA' Composite Projection
URL: http://github.com/hrbrmstr/albersusa
BugReports: https://github.com/hrbrmstr/albersusa/issues
License: AGPL + file LICENSE
Suggests:
testthat,
ggalt
Depends:
R (>= 3.0.0)
Imports:
sp,
rgeos,
rgdal,
maptools
RoxygenNote: 5.0.1

2
LICENSE

@ -0,0 +1,2 @@
YEAR: 2016
COPYRIGHT HOLDER: Bob Rudis

12
NAMESPACE

@ -0,0 +1,12 @@
# Generated by roxygen2: do not edit by hand
export(us_aeqd_proj)
export(us_eqdc_proj)
export(us_laea_proj)
export(us_lcc_proj)
export(us_longlat_proj)
export(usa_composite)
import(maptools)
import(rgdal)
import(rgeos)
import(sp)

2
NEWS.md

@ -0,0 +1,2 @@
0.1.0
* Initial release

7
R/albersusa-package.R

@ -0,0 +1,7 @@
#' Tools, Shapefiles & Data to Work with an 'AlbersUSA' Composite Projection
#'
#' @name albersusa
#' @docType package
#' @author Bob Rudis (@@hrbrmstr)
#' @import sp rgeos rgdal maptools
NULL

39
R/albersusa.R

@ -0,0 +1,39 @@
#' Retreive a U.S. composite map, optionally with a projection
#'
#' The \code{proj} parameter is intende to simplify usage for those using base
#' plotting. If anything but \code{longlat} is specified the composite map
#' will be pre-projected to those
#'
#' @param proj if anything but \code{longlat} is specified, the shapefile will
#' be pre-projected before being returned
#' @export
#' @examples
#' plot(usa_composite())
#'
#' plot(usa_composite("laea"))
usa_composite <- function(proj=c("longlat", "laea", "lcc", "eqdc", "aeqd")) {
# us <- readOGR(system.file("extdata/composite_us_states.geojson", package="albersusa"),
# "OGRGeoJSON",
# stringsAsFactors=FALSE,
# verbose=FALSE)
us <- readRDS(system.file("extdata/states.rda", package="albersusa"))
proj <- match.arg(proj, c("longlat", "laea", "lcc", "eqdc", "aeqd"))
if (proj != "longlat") {
proj <- switch(proj,
laea=us_laea_proj,
lcc=us_lcc_proj,
eqdc=us_eqdc_proj,
aeqd=us_aeqd_proj)
us <- sp::spTransform(us, sp::CRS(proj))
}
us
}

82
R/proj.r

@ -0,0 +1,82 @@
#' Albers equal-area conic convenience projection
#'
#' The following PROJ.4 string is used: \code{+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs}
#'
#' In a ggplot2+ggalt context, you can just use variable name as the value for the \code{proj}
#' parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_laea_proj)}.
#'
#' @family convenience projections
#' @export
#' @examples
#' us <- usa_composite()
#' us <- sp::spTransform(us, CRS(us_laea_proj))
#' us <- usa_composite(proj="laea")
us_laea_proj <- "+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs"
#' Generic long/lat convenience projection
#'
#' The following PROJ.4 string is used: \code{+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0}
#'
#' In a ggplot2+ggalt context, you can just use variable name as the value for the \code{proj}
#' parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_longlat_proj)}.
#'
#' @export
#' @examples
#' us <- usa_composite() # it's the default
#' us <- sp::spTransform(us, CRS(us_longlat_proj))
us_longlat_proj <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
#' Lambert conformal conic convenience projection
#'
#' The following PROJ.4 string is used: \code{+proj=lcc +lat_1=27.11637320883929 +lat_2=53.050729042644335 +lon_0=-95.44921875}
#'
#' In a ggplot2+ggalt context, you can just use variable name as the value for the \code{proj}
#' parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_lcc_proj)}.
#'
#' @family convenience projections
#' @export
#' @examples
#' us <- usa_composite()
#' us <- sp::spTransform(us, CRS(us_lcc_proj))
#' us <- usa_composite(proj="lcc")
us_lcc_proj <- "+proj=lcc +lat_1=27.11637320883929 +lat_2=53.050729042644335 +lon_0=-95.44921875"
#' Equidistant conic convenience projection
#'
#' Distance correct along meridians
#'
#' The following PROJ.4 string is used: \code{+proj=eqdc +lat_1=27.11637320883929 +lat_2=53.050729042644335 +lon_0=-95.44921875}
#'
#' In a ggplot2+ggalt context, you can just use variable name as the value for the \code{proj}
#' parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_eqdc_proj)}.
#'
#' @family convenience projections
#' @export
#' @examples
#' us <- usa_composite()
#' us <- sp::spTransform(us, CRS(us_eqdc_proj))
#' us <- usa_composite(proj="eqdc")
#'
us_eqdc_proj <- "+proj=eqdc +lat_1=27.11637320883929 +lat_2=53.050729042644335 +lon_0=-95.44921875"
#' Oblique azimuthal equidistant convenience projection
#'
#' Distance correct along any line passing through the center of the map (i.e., great circle)
#'
#' The following PROJ.4 string is used: \code{+proj=aeqd +lat_0=40.08355112574181 +lon_0=-95.44921875}
#'
#' In a ggplot2+ggalt context, you can just use variable name as the value for the \code{proj}
#' parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_aeqd_proj)}.
#'
#' @family convenience projections
#' @export
#' @examples
#' us <- usa_composite()
#' us <- sp::spTransform(us, CRS(us_aeqd_proj))
#' us <- usa_composite(proj="aeqd")
us_aeqd_proj <- "+proj=aeqd +lat_0=40.08355112574181 +lon_0=-95.44921875"

42
README.Rmd

@ -1,11 +1,45 @@
---
title: "README"
author: "@hrbrmstr"
date: March 28, 2016
output:
html_document:
keep_md: true
md_document:
variant: markdown_github
---
albersusa is ...
`albersusa` : ...
The following functions are implemented:
The following data sets are included:
### Installation
```{r eval=FALSE}
devtools::install_github("hrbrmstr/albersusa")
```
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
options(width=120)
```
### Usage
```{r}
library(albersusa)
# current verison
packageVersion("albersusa")
```
### Test Results
```{r}
library(albersusa)
library(testthat)
date()
test_dir("tests/")
```

6
albersusa.Rproj

@ -13,3 +13,9 @@ RnwWeave: Sweave
LaTeX: pdfLaTeX
StripTrailingWhitespace: Yes
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageBuildArgs: --resave-data
PackageRoxygenize: rd,collate,namespace

58
inst/extdata/composite_us_states.geojson

File diff suppressed because one or more lines are too long

BIN
inst/extdata/states.rda

Binary file not shown.

14
man/albersusa.Rd

@ -0,0 +1,14 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/albersusa-package.R
\docType{package}
\name{albersusa}
\alias{albersusa}
\alias{albersusa-package}
\title{Tools, Shapefiles & Data to Work with an 'AlbersUSA' Composite Projection}
\description{
Tools, Shapefiles & Data to Work with an 'AlbersUSA' Composite Projection
}
\author{
Bob Rudis (@hrbrmstr)
}

30
man/us_aeqd_proj.Rd

@ -0,0 +1,30 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/proj.r
\docType{data}
\name{us_aeqd_proj}
\alias{us_aeqd_proj}
\title{Oblique azimuthal equidistant convenience projection}
\format{An object of class \code{character} of length 1.}
\usage{
us_aeqd_proj
}
\description{
Distance correct along any line passing through the center of the map (i.e., great circle)
}
\details{
The following PROJ.4 string is used: \code{+proj=aeqd +lat_0=40.08355112574181 +lon_0=-95.44921875}
In a ggplot2+ggalt context, you can just use variable name as the value for the \code{proj}
parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_aeqd_proj)}.
}
\examples{
us <- usa_composite()
us <- sp::spTransform(us, CRS(us_aeqd_proj))
us <- usa_composite(proj="aeqd")
}
\seealso{
Other convenience.projections: \code{\link{us_eqdc_proj}},
\code{\link{us_laea_proj}}, \code{\link{us_lcc_proj}}
}
\keyword{datasets}

31
man/us_eqdc_proj.Rd

@ -0,0 +1,31 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/proj.r
\docType{data}
\name{us_eqdc_proj}
\alias{us_eqdc_proj}
\title{Equidistant conic convenience projection}
\format{An object of class \code{character} of length 1.}
\usage{
us_eqdc_proj
}
\description{
Distance correct along meridians
}
\details{
The following PROJ.4 string is used: \code{+proj=eqdc +lat_1=27.11637320883929 +lat_2=53.050729042644335 +lon_0=-95.44921875}
In a ggplot2+ggalt context, you can just use variable name as the value for the \code{proj}
parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_eqdc_proj)}.
}
\examples{
us <- usa_composite()
us <- sp::spTransform(us, CRS(us_eqdc_proj))
us <- usa_composite(proj="eqdc")
}
\seealso{
Other convenience.projections: \code{\link{us_aeqd_proj}},
\code{\link{us_laea_proj}}, \code{\link{us_lcc_proj}}
}
\keyword{datasets}

28
man/us_laea_proj.Rd

@ -0,0 +1,28 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/proj.r
\docType{data}
\name{us_laea_proj}
\alias{us_laea_proj}
\title{Albers equal-area conic convenience projection}
\format{An object of class \code{character} of length 1.}
\usage{
us_laea_proj
}
\description{
The following PROJ.4 string is used: \code{+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs}
}
\details{
In a ggplot2+ggalt context, you can just use variable name as the value for the \code{proj}
parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_laea_proj)}.
}
\examples{
us <- usa_composite()
us <- sp::spTransform(us, CRS(us_laea_proj))
us <- usa_composite(proj="laea")
}
\seealso{
Other convenience.projections: \code{\link{us_aeqd_proj}},
\code{\link{us_eqdc_proj}}, \code{\link{us_lcc_proj}}
}
\keyword{datasets}

28
man/us_lcc_proj.Rd

@ -0,0 +1,28 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/proj.r
\docType{data}
\name{us_lcc_proj}
\alias{us_lcc_proj}
\title{Lambert conformal conic convenience projection}
\format{An object of class \code{character} of length 1.}
\usage{
us_lcc_proj
}
\description{
The following PROJ.4 string is used: \code{+proj=lcc +lat_1=27.11637320883929 +lat_2=53.050729042644335 +lon_0=-95.44921875}
}
\details{
In a ggplot2+ggalt context, you can just use variable name as the value for the \code{proj}
parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_lcc_proj)}.
}
\examples{
us <- usa_composite()
us <- sp::spTransform(us, CRS(us_lcc_proj))
us <- usa_composite(proj="lcc")
}
\seealso{
Other convenience.projections: \code{\link{us_aeqd_proj}},
\code{\link{us_eqdc_proj}}, \code{\link{us_laea_proj}}
}
\keyword{datasets}

23
man/us_longlat_proj.Rd

@ -0,0 +1,23 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/proj.r
\docType{data}
\name{us_longlat_proj}
\alias{us_longlat_proj}
\title{Generic long/lat convenience projection}
\format{An object of class \code{character} of length 1.}
\usage{
us_longlat_proj
}
\description{
The following PROJ.4 string is used: \code{+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0}
}
\details{
In a ggplot2+ggalt context, you can just use variable name as the value for the \code{proj}
parameter to \code{ggalt::coord_proj()}. i.e. \code{coord_proj(us_longlat_proj)}.
}
\examples{
us <- usa_composite() # it's the default
us <- sp::spTransform(us, CRS(us_longlat_proj))
}
\keyword{datasets}

23
man/usa_composite.Rd

@ -0,0 +1,23 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/albersusa.R
\name{usa_composite}
\alias{usa_composite}
\title{Retreive a U.S. composite map, optionally with a projection}
\usage{
usa_composite(proj = c("longlat", "laea", "lcc", "eqdc", "aeqd"))
}
\arguments{
\item{proj}{if anything but \code{longlat} is specified, the shapefile will
be pre-projected before being returned}
}
\description{
The \code{proj} parameter is intende to simplify usage for those using base
plotting. If anything but \code{longlat} is specified the composite map
will be pre-projected to those
}
\examples{
plot(usa_composite())
plot(usa_composite("laea"))
}

2
tests/test-all.R

@ -0,0 +1,2 @@
library(testthat)
test_check("albersusa")

6
tests/testthat/test-albersusa.R

@ -0,0 +1,6 @@
context("basic functionality")
test_that("we can do something", {
#expect_that(some_function(), is_a("data.frame"))
})
Loading…
Cancel
Save