Browse Source

added function points_elided() which should convert the Alaska and Hawaii areas of a SpatialPoints object to the elided portion in this package

master
Robert Dinterman 7 years ago
parent
commit
ef752ac6ea
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 1
      NAMESPACE
  2. 56
      R/points_elided.R
  3. 2
      man/albersusa.Rd
  4. 19
      man/points_elided.Rd
  5. 2
      man/usa_composite.Rd

1
NAMESPACE

@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand
export(counties_composite)
export(points_elided)
export(us_aeqd_proj)
export(us_eqdc_proj)
export(us_laea_proj)

56
R/points_elided.R

@ -0,0 +1,56 @@
#' Shift points around Alaska and Hawaii to the elided area
#'
#' This function will take a SpatialPoints object and shift the points around
#' Alaska and Hawaii to the elided area from this package.
#'
#' @param sp An object of SpatialPoints class
#' @return An elided version of the original SpatialPoints class
#' @export
points_elided <- function(sp){
orig_proj <- sp::proj4string(sp)
# convert it to Albers equal area
sp <- sp::spTransform(sp, CRS("+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs"))
ak_bb <- readRDS(system.file("extdata/alaska_bb.rda", package="albersusa"))
#ak_bb <- readRDS("inst/extdata/alaska_bb.rda")
ak_poly <- as(raster::extent(as.vector(t(ak_bb))), "SpatialPolygons")
sp::proj4string(ak_poly) <- "+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs"
# Determine which points fall in the Alaska bounding box, subset and remove
# from the original points
ak_l <- sp::over(sp, ak_poly)
ak <- sp[!is.na(ak_l),]
sp <- sp[is.na(ak_l),]
# Elide the points, the key here is to set "bb" to what the original
# transformation's bounding box was!
ak <- maptools::elide(ak,
scale=max(apply(ak_bb, 1, diff)) / 2.3,
rotate = -50,
bb = ak_bb) # NEED the bb option here
ak <- maptools::elide(ak, shift = c(-1298669, -3018809)) # bb doesn't matter
sp::proj4string(ak) <- sp::proj4string(sp)
hi_bb <- readRDS(system.file("extdata/hawaii_bb.rda", package="albersusa"))
#hi_bb <- readRDS("inst/extdata/hawaii_bb.rda")
hi_poly <- as(raster::extent(as.vector(t(hi_bb))), "SpatialPolygons")
sp::proj4string(hi_poly) <- "+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs"
# Determine which points fall in the Alaska bounding box, subset and remove
# from the original points
hi_l <- sp::over(sp, hi_poly)
hi <- sp[!is.na(hi_l),]
sp <- sp[is.na(hi_l),]
hi <- maptools::elide(hi,
rotate = -35,
bb = hi_bb) # NEED the bb option here
hi <- maptools::elide(hi, shift = c(5400000, -1400000)) # bb doesn't matter
sp::proj4string(hi) <- sp::proj4string(sp)
# Bring them back together with original projection
sp <- rbind(sp, ak, hi)
sp <- sp::spTransform(sp, CRS(orig_proj))
return(sp)
}

2
man/albersusa.Rd

@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/albersusa-package.r
% Please edit documentation in R/albersusa-package.R
\docType{package}
\name{albersusa}
\alias{albersusa}

19
man/points_elided.Rd

@ -0,0 +1,19 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/points_elided.R
\name{points_elided}
\alias{points_elided}
\title{Shift points around Alaska and Hawaii to the elided area}
\usage{
points_elided(sp)
}
\arguments{
\item{sp}{An object of SpatialPoints class}
}
\value{
An elided version of the original SpatialPoints class
}
\description{
This function will take a SpatialPoints object and shift the points around
Alaska and Hawaii to the elided area from this package.
}

2
man/usa_composite.Rd

@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/albersusa.r
% Please edit documentation in R/albersusa.R
\name{usa_composite}
\alias{usa_composite}
\title{Retreive a U.S. state composite map, optionally with a projection}

Loading…
Cancel
Save