Browse Source

Merge pull request #2 from rdinter/master

Eliding points
master
boB Rudis 7 years ago
committed by GitHub
parent
commit
51a31f4aa4
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 1
      NAMESPACE
  2. 56
      R/points_elided.R
  3. BIN
      inst/extdata/alaska_bb.rda
  4. BIN
      inst/extdata/hawaii_bb.rda
  5. 19
      man/points_elided.Rd

1
NAMESPACE

@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand
export(counties_composite)
export(points_elided)
export(counties_sf)
export(us_aeqd_proj)
export(us_eqdc_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)
}

BIN
inst/extdata/alaska_bb.rda

Binary file not shown.

BIN
inst/extdata/hawaii_bb.rda

Binary file not shown.

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.
}
Loading…
Cancel
Save