Skip to content

Commit

Permalink
merge conflicts
Browse files Browse the repository at this point in the history
Merge branch 'master' of https://github.com/jhollist/quickmapr

Conflicts:
	.Rbuildignore
  • Loading branch information
jhollist committed Oct 3, 2016
2 parents 3dea882 + 806f698 commit eaee510
Show file tree
Hide file tree
Showing 34 changed files with 870 additions and 92 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Expand Up @@ -10,4 +10,5 @@
^README\.pdf$
^figure$
^NEWS\.md$
^log_check\.R$
^log_check\.R$
^manuscript$
20 changes: 9 additions & 11 deletions .travis.yml
@@ -1,26 +1,24 @@
language: r
warnings_are_errors: true
dist: trusty
cache: packages
sudo: true

r:
- oldrel
- release
- devel

addons:
apt:
packages:
- libgdal-dev
- libproj-dev
r_binary_packages:
- rgdal
- sp

notifications:
email:
on_success: change
on_failure: change

r_github_packages:
- jimhester/covr

after_success:
- Rscript -e 'library(covr); coveralls()'

notifications:
email:
on_success: change
on_failure: change
18 changes: 9 additions & 9 deletions DESCRIPTION
@@ -1,8 +1,8 @@
Package: quickmapr
Type: Package
Title: Quickly Map and Explore Spatial Data
Version: 0.1.2
Date: 2016-04-05
Version: 0.2.0
Date: 2016-09-16
Authors@R: person(given = "Jeffrey W.",family = "Hollister",
role = c("aut","cre"),
email = "hollister.jeff@epa.gov")
Expand All @@ -14,21 +14,21 @@ Description: While analyzing geospatial data, easy visualization is often
needed that allows for quick plotting, and simple, but easy interactivity.
Additionally, visualizing geospatial data in projected coordinates is also
desirable. The 'quickmapr' package provides a simple method to visualize 'sp'
and 'raster' objects, allows for basic zooming, panning, identifying, and
labeling of spatial objects, and does not require that the data be in geographic
coordinates.
and 'raster' objects, allows for basic zooming, panning, identifying,
labeling, selecting, and measuring spatial objects. Importantly, it does
not require that the data be in geographic coordinates.
Depends:
R (>= 3.0.0)
Imports:
rgeos,
raster,
sp,
rgeos,
rgdal,
httr,
stats,
grDevices,
graphics,
methods,
httr,
raster
methods
Suggests:
testthat,
knitr
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Expand Up @@ -5,8 +5,10 @@ S3method(print,qmap)
export(f)
export(i)
export(l)
export(m)
export(p)
export(qmap)
export(s)
export(ze)
export(zi)
export(zo)
Expand Down
17 changes: 17 additions & 0 deletions NEWS.md
@@ -1,3 +1,20 @@
# quickmapr v0.2.0 (2016-09-16)

## API changes
- the `i()` function now allows for selecting multiple points and only prints
results to screen. To access selected `sp` objects, see `s()` (listed below)

## New functions
- Two new functions were added, `s()` for selecting objects and returning the sp
object, and `m()` for measuring distances on the `qmap`.

## Minor changes
- closed several issues
- added message if number of colors doesn't match number of data layers

## Bug Fixes
- colormap on zoomed rasters not plotting correctly.

# quickmapr v0.1.2

- cleaned up code
Expand Down
51 changes: 30 additions & 21 deletions R/i.R
@@ -1,18 +1,14 @@
#' Identify
#'
#' Interactively select an \code{sp} or \code{raster} object and return the
#' Interactively select an \code{sp} or \code{raster} object and print the
#' data associated with it. \code{i()} only accepts a single input point.
#'
#' @param qmap_obj a \code{qmap} object from which to identify features.
#' An \code{sp} object may also be passed directly
#' @param i_idx a numeric value specifying which data layer to identify or a
#' character string indicating the name of the layer. Defaults to 1.
#' @param loc A list with an x and y numeric indicating a location. Default is
#' to interactively get loc value until escaped.
#' @return Returns a list that contains data for the selected object (data is
#' NULL if not a Spatial DataFrame object), the \code{sp} object, and
#' additional information for each object (e.g. area and perimeter for
#' polygons).
#' @return Returns NULL. Identified values are printed to the screen.
#'
#' @export
#' @import sp rgeos
Expand All @@ -30,11 +26,18 @@ i <- function(qmap_obj = NULL, i_idx = 1, loc = NULL) {
} else {
spdata <- qmap_obj$map_data[[i_idx]]
}
switch(EXPR = get_sp_type(spdata),
polygon = i_poly(spdata, loc),
grid = i_grid(spdata, loc),
line = i_line(spdata, loc),
point = i_point(spdata, loc))
if (is.null(loc)) {
message("Click on plot to identify. Press 'Esc' to exit.")
loc <- locator(1)
while (!is.null(loc)) {
switch(EXPR = get_sp_type(spdata),
polygon = i_poly(spdata, loc),
grid = i_grid(spdata, loc),
line = i_line(spdata, loc),
point = i_point(spdata, loc))
loc <- locator(1)
}
}
}

#' Identify Polys
Expand All @@ -59,10 +62,10 @@ i_poly <- function(spdata, loc) {
} else {
data <- NULL
}
idata <- list(data = data, spobj = spdata[idx, ],
idata <- list(data = data, #spobj = spdata[idx, ],
area = gArea(spdata[idx, ]), perim = gLength(spdata[idx, ]))

return(idata)
print(idata)
}

#' Identify Lines
Expand All @@ -78,17 +81,18 @@ i_line <- function(spdata, loc) {
}
idx <- gWithinDistance(loc_pt, spdata, gDistance(loc_pt, spdata), byid = T)
if (sum(idx) == 0) {
message("No line features at that location.")
return(NULL)
message("No line features at that location.")
return(NULL)
}
if (regexpr("DataFrame", class(spdata)) > 0) {
data <- spdata@data[idx, ]
} else {
data <- NULL
}
idata <- list(data = data, spobj = spdata[which(idx), ], length = gLength(spdata[which(idx),
idata <- list(data = data, #spobj = spdata[which(idx), ],
length = gLength(spdata[which(idx),
]))
return(idata)
print(idata)
}

#' Identify Points
Expand All @@ -113,8 +117,9 @@ i_point <- function(spdata, loc) {
} else {
data <- NULL
}
idata <- list(data = data, spobj = spdata[which(idx), ])
return(idata)
idata <- list(data = data, #spobj = spdata[which(idx), ])
location = sp::coordinates(loc_pt))
print(idata)
}

#' Identify Rasters
Expand All @@ -126,9 +131,13 @@ i_point <- function(spdata, loc) {
i_grid <- function(spdata, loc) {
spdata2 <- as(spdata, "SpatialGridDataFrame")
if (is.null(loc)){
data <- over(SpatialPoints(locator(1), CRS(proj4string(spdata2))), spdata2)
loc_pt <- SpatialPoints(locator(1), CRS(proj4string(spdata)))
data <- over(SpatialPoints(loc_pt, CRS(proj4string(spdata2))), spdata2)
} else {
loc_pt <- SpatialPoints(loc, CRS(proj4string(spdata)))
data <- over(SpatialPoints(loc, CRS(proj4string(spdata2))), spdata2)
}
return(data)
idata <- list(data = data, #spobj = spdata[which(idx), ])
location = sp::coordinates(loc_pt))
print(idata)
}
2 changes: 1 addition & 1 deletion R/internals.R
Expand Up @@ -146,7 +146,7 @@ zoom_test<-function(qmap_obj,map_extent){
}

#' sp bbox to poly
#' @param sp
#' @param sp an sp object
#' @keywords internal
bbox_to_sp <- function(sp) {
bbox <- bbox(sp)
Expand Down
27 changes: 27 additions & 0 deletions R/m.R
@@ -0,0 +1,27 @@
#' Measure
#'
#' Allows interactive selection of points and returns length of selecte line in
#' units of the current \code{qmap} object.
#' @param qmap_obj a \code{qmap} object from which to measure features.
#'
#' @import sp
#' @export
m <- function(qmap_obj = NULL){
if (class(qmap_obj) != "qmap") {
stop("Requires a valid qmap_obj.")
}
plot(qmap_obj)
message("Click on plot to draw line to measure. Press 'Esc' to exit.")
loc <- locator(1)
locs <- coordinates(loc)
while (!is.null(loc)) {
sl <- SpatialLines(list(Lines(list(Line(locs)), "id")))
plot(sl,add=T)
loc <- locator(1)
if(!is.null(loc)){
locs<-rbind(locs,coordinates(loc))
}
}
rgeos::gLength(sl)
}

18 changes: 9 additions & 9 deletions R/qmap.R
Expand Up @@ -47,7 +47,6 @@ qmap <- function(..., extent = NULL, order = 1:length(mapdata),

basemap <- match.arg(basemap)
if(basemap == "none") {basemap <- NULL}

mapdata <- build_map_data(...)
# Test Projections
if (prj) {
Expand Down Expand Up @@ -88,7 +87,11 @@ qmap <- function(..., extent = NULL, order = 1:length(mapdata),


# match colors to length of mapdata
colors <- rep(colors, length(mapdata))[1:length(mapdata)]

if(length(colors) != length(mapdata)){
message("number of specified colors does not match number of data layers and some colors are repeated.")
colors <- rep(colors, length(mapdata))[1:length(mapdata)]
}

qmap_obj <- list(map_data = mapdata, map_extent = bbx, orig_extent = bbx,
draw_order = order,
Expand Down Expand Up @@ -181,19 +184,16 @@ plot.qmap <- function(x, ...) {

}

#' Default printing of a qmap object
#' Default plotting of a qmap object
#'
#' Prints the summary of a qmap object
#' Plots a qmap object
#'
#' @param x input qmap class to print
#' @param ... options passed to summary
#' @param ... options passed to plot
#' @method print qmap
#' @export
print.qmap <- function(x, ...) {
print_it <- list(map_data = names(x$map_data), map_extent = x$map_extent,
draw_order = x$draw_order, colors = x$colors,
fill = x$fill, label = x$label)
return(print_it)
plot.qmap(x, ...)
}

#' Get a basemap from USGS National Map
Expand Down

0 comments on commit eaee510

Please sign in to comment.