Skip to content

Commit

Permalink
Purge package of the evil camelCase
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Oct 23, 2015
1 parent 54abcc4 commit 815afa2
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 51 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Date: 2015-10-18
Authors@R: c(
person("Robin", "Lovelace", email = "rob00x@gmail.com", role = c("aut", "cre")),
person("Richard", "Ellison", role = c("aut"), comment = "Author of various functions"),
person("Barry", "Rowlingson", role = c("aut"), comment = "Author of gOverline"),
person("Nick", "Bearman", role = c("aut"), comment = "Co-author of gClip")
person("Barry", "Rowlingson", role = c("aut"), comment = "Author of overline"),
person("Nick", "Bearman", role = c("aut"), comment = "Co-author of gclip")
)
Description: Functionality and data access tools for transport planning, including origin-destination analysis, route allocation and modelling travel patterns.
License: MIT + file LICENSE
Expand Down
12 changes: 6 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export(dd_logcub)
export(dd_loglin)
export(dd_logsqrt)
export(disab_recat)
export(gClip)
export(gMapshape)
export(gOnewaygeo)
export(gOnewayid)
export(gOverline)
export(gSection)
export(gclip)
export(mapshape)
export(onewaygeo)
export(onewayid)
export(overline)
export(gsection)
export(islines)
export(line2df)
export(line2route)
Expand Down
26 changes: 13 additions & 13 deletions R/geo-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' \code{geojson_write} from the geojsonio package
#' provides the same functionality \url{https://github.com/ropensci/geojsonio}.
#'
#' @inheritParams gClip
#' @inheritParams gclip
#' @param filename File name of the output geojson
writeGeoJSON <- function(shp, filename){
name <- nm <-deparse(substitute(shp))
Expand All @@ -16,7 +16,7 @@ writeGeoJSON <- function(shp, filename){
#' Simplify geometry file of a shapfile.
#'
#' @section Details:
#' This is a wrapper funtion for the open source JavaScript command-line GIS application mapshaper: \url{https://github.com/mbloch/mapshaper} . mapshaper which must be installed locally for gMapshaper to work. Writes \code{gMapshape} writes new file to disk. Thanks to Richard and Adrian Ellison for demonstrating this in R.
#' This is a wrapper funtion for the open source JavaScript command-line GIS application mapshaper: \url{https://github.com/mbloch/mapshaper} . mapshaper which must be installed locally for mapshaper to work. Writes \code{mapshape} writes new file to disk. Thanks to Richard and Adrian Ellison for demonstrating this in R.
#'
#' @param dsn A character string providing the absolute path to the shapefile to simplify.
#' @param percent A number between 0 and 100 stating how aggressively to simplify
Expand All @@ -27,9 +27,9 @@ writeGeoJSON <- function(shp, filename){
#' @export
#' @examples
#' \dontrun{
#' gMapshape("~/geodata/myShapefile.shp", 5)
#' mapshape("~/geodata/myShapefile.shp", 5)
#' }
gMapshape <- function(dsn, percent){
mapshape <- function(dsn, percent){
from_layer <- gsub(".shp", replacement = "", dsn)
to_layer <- paste0(from_layer, "mapshaped_", percent, "%.shp")
cmd <- paste0("mapshaper ", dsn, " auto-snap -simplify keep-shapes ", percent, "% -o force ", to_layer)
Expand All @@ -56,12 +56,12 @@ gMapshape <- function(dsn, percent){
#' cb <- rgeos::gBuffer(cents[8, ], width = 0.012, byid = TRUE)
#' plot(cents)
#' plot(cb, add = TRUE)
#' clipped <- gClip(cents, cb)
#' clipped <- gclip(cents, cb)
#' row.names(clipped)
#' clipped$avslope # gClip also returns the data attribute
#' clipped$avslope # gclip also returns the data attribute
#' points(clipped)
#' points(cents[cb,], col = "red") # note difference
gClip <- function(shp, bb){
gclip <- function(shp, bb){
if(class(bb) == "matrix"){
b_poly <- as(raster::extent(as.vector(t(bb))), "SpatialPolygons")
}
Expand All @@ -71,14 +71,14 @@ gClip <- function(shp, bb){
clipped <- rgeos::gIntersection(shp, b_poly, byid = TRUE, id = row.names(shp))
if(grepl("DataFrame", class(shp))){
if(grepl("SpatialLines", class(shp)) & grepl("SpatialCollections",class(clipped))) {
geodata <- data.frame(gClip_id = row.names(clipped@lineobj))
geodata <- data.frame(gclip_id = row.names(clipped@lineobj))
}
else {
geodata <- data.frame(gClip_id = row.names(clipped))
geodata <- data.frame(gclip_id = row.names(clipped))
}
joindata <- cbind(gClip_id = row.names(shp), shp@data)
joindata <- cbind(gclip_id = row.names(shp), shp@data)
geodata <- dplyr::left_join(geodata, joindata)
row.names(geodata) <- geodata$gClip_id
row.names(geodata) <- geodata$gclip_id
#if the data are SpatialPolygonsDataFrame (based on https://stat.ethz.ch/pipermail/r-sig-geo/2008-January/003052.html)
if(grepl("SpatialPolygons", class(shp))){
#then rebuild SpatialPolygonsDataFrame selecting relevant rows by row.names (row ID values)
Expand All @@ -91,15 +91,15 @@ gClip <- function(shp, bb){
clipped <- sp::SpatialPointsDataFrame(clipped, geodata)
}
}
clipped@data$gClip_id <- NULL
clipped@data$gclip_id <- NULL
clipped
}

#' Scale a bounding box
#'
#' Takes a bounding box as an input and outputs a bounding box of a different size, centred at the same point.
#'
#' @inheritParams gClip
#' @inheritParams gclip
#' @param scale_factor Number determining how much the bounding box will grow or shrink. If the value is 1, the output size will be the same as the input.
#' @export
#' @examples
Expand Down
File renamed without changes.
34 changes: 17 additions & 17 deletions R/gOverline.R → R/overline.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Do the intersections between two geometries create lines?
#'
#' This is a function required in \code{\link{gOverline}}. It identifies
#' This is a function required in \code{\link{overline}}. It identifies
#' whether sets of lines overlap (beyond shared points) or
#' not.
#'
Expand All @@ -10,7 +10,7 @@
#'
#' @examples \dontrun{
#' data(routes_fast)
#' rnet <- gOverline(routes_fast[c(2, 3, 22),], attrib = "length")
#' rnet <- overline(routes_fast[c(2, 3, 22),], attrib = "length")
#' r1 <- routes_fast[2,]
#' r2 <- routes_fast[3,]
#' r3 <- routes_fast[22,]
Expand All @@ -37,15 +37,15 @@ islines <- function(g1, g2){
#' @export
#' @examples \dontrun{
#' data(routes_fast)
#' rsec <- gSection(routes_fast)
#' rsec <- gsection(routes_fast)
#' plot(routes_fast)
#' lines(rsec, col = "red", lwd = 3)
#' length(rsec)
#' set.seed(5)
#' sel <- sample(length(rsec), 20)
#' plot(rsec[sel,], col = "blue", add = TRUE, lwd = 3) # overlapping lines
#' }
gSection <- function(sl){
gsection <- function(sl){
## union and merge and disaggregate to make a
## set of non-overlapping line segments
sp::disaggregate(rgeos::gLineMerge(rgeos::gUnion(sl, sl)))
Expand Down Expand Up @@ -91,16 +91,16 @@ lineLabels <- function(sldf, attrib){
#' @examples \dontrun{
#' data(routes_fast)
#' data(cents)
#' rnet <- gOverline(sldf = routes_fast[1:7,], attrib = "length")
#' rnet <- overline(sldf = routes_fast[1:7,], attrib = "length")
#' plot(rnet)
#' points(cents)
#' lineLabels(sldf = rnet, "length")
#' sum(routes_fast$length[1:7], na.rm = TRUE) # verify highest flow
#' data(flowlines)
#' plot(flowlines)
#' aggflow <- gOverline(flowlines, attrib = "All")
#' aggflow <- overline(flowlines, attrib = "All")
#' nrow(aggflow)
#' aggflow2 <- gOverline(flowlines, attrib = "All", na.zero = TRUE)
#' aggflow2 <- overline(flowlines, attrib = "All", na.zero = TRUE)
#' plot(aggflow2) # 8 lines
#' sel <- as.logical(colSums(gEquals(flowlines, aggflow2, byid = TRUE)))
#' flowlines_sub <- flowlines[!sel,]
Expand All @@ -112,11 +112,11 @@ lineLabels <- function(sldf, attrib){
#' overlaps <- over()
#' nrow(overlaps)
#' }
gOverline <- function(sldf, attrib, fun = sum, na.zero = FALSE){
overline <- function(sldf, attrib, fun = sum, na.zero = FALSE){
## simplify down to SpatialLines
sl = as(sldf, "SpatialLines")
## get the line sections that make the network
slu = gSection(sl)
slu = gsection(sl)
## overlay network with routes
overs = sp::over(slu, sl, returnList=TRUE)
## overlay is true if end points overlay, so filter them out:
Expand Down Expand Up @@ -160,19 +160,19 @@ gOverline <- function(sldf, attrib, fun = sum, na.zero = FALSE){
#' @param attrib A text string containing the name of the line's attribute to
#' aggregate or a numeric vector of the columns to be aggregated
#'
#' @return \code{gOnewaygeo} outputs a SpatialLinesDataFrame with single lines
#' @return \code{onewaygeo} outputs a SpatialLinesDataFrame with single lines
#' and user-selected attribute values that have been aggregated. Only lines
#' with a distance (i.e. not intra-zone flows) are included
#' @export
#' @examples
#' data("flowlines")
#' plot(flowlines)
#' singlelines <- gOnewaygeo(flowlines, attrib = 3:14)
#' singlelines <- onewaygeo(flowlines, attrib = 3:14)
#' plot(singlelines, lwd = 3, col = "red")
#' lines(singlelines) # check we've got the right lines
#' sum(singlelines$All)
#' nrow(singlelines)
gOnewaygeo <- function(x, attrib){
onewaygeo <- function(x, attrib){
geq <- rgeos::gEquals(x, x, byid = T)
sel1 <- !duplicated(geq) # repeated rows
sel2 <- rowSums(geq) > 1 # all features with an overlap
Expand Down Expand Up @@ -223,7 +223,7 @@ gOnewaygeo <- function(x, attrib){
#' @param id1 A text string referring to the name of the variable containing the unique id of the origin
#' @param id2 A text string referring to the name of the variable containing the unique id of the destination
#'
#' @return \code{gOnewayid} outputs a SpatialLinesDataFrame with single lines
#' @return \code{onewayid} outputs a SpatialLinesDataFrame with single lines
#' and user-selected attribute values that have been aggregated. Only lines
#' with a distance (i.e. not intra-zone flows) are included.
#' @export
Expand All @@ -232,14 +232,14 @@ gOnewaygeo <- function(x, attrib){
#' id1 <- names(flowlines)[1]
#' id2 <- names(flowlines)[2]
#' plot(flowlines)
#' singlelines <- gOnewayid(flowlines, attrib = 3:14, id1, id2)
#' singlelines <- onewayid(flowlines, attrib = 3:14, id1, id2)
#' lines(singlelines) # check we've got the right lines
#' sum(singlelines$All)
#' nrow(singlelines)
#' sl2 <- gOnewaygeo(flowlines, attrib = 3:14)
#' # Demonstrate the results from gOnewayid and gOnewaygeo are identical
#' sl2 <- onewaygeo(flowlines, attrib = 3:14)
#' # Demonstrate the results from onewayid and onewaygeo are identical
#` identical(singlelines, sl2)
gOnewayid <- function(x, attrib, id1 = names(x)[1], id2 = names(x)[2]){
onewayid <- function(x, attrib, id1 = names(x)[1], id2 = names(x)[2]){
ids <- cbind(x[[id1]], x[[id2]])
idsort <- t(apply(ids, 1, sort))
# duplicate pairs - see http://stackoverflow.com/questions/9028369/
Expand Down
2 changes: 0 additions & 2 deletions R/routes.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
#' Sys.setenv(CYCLESTREET = mytoken)
#' }
#'
#'
#'
#' \code{
#' cckey <- Sys.getenv('CYCLESTREET')
#' }
Expand Down
2 changes: 1 addition & 1 deletion R/stplanr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#'
#' @section Interesting functions:
#' \itemize{
#' \item \code{\link{gOverline}} - Aggregate overlaying route lines and data intelligently
#' \item \code{\link{overline}} - Aggregate overlaying route lines and data intelligently
#' \item \code{\link{calc_catchment}} - Create a 'catchment area' to show the areas serving a destination
#' \item \code{\link{route_cyclestreet}} - Finds the fastest routes for cyclists between two places.
#' }
Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ plot(routes)

For more examples, `example("line2route")`.

`gOverline` is a function which takes a series of route-allocated lines,
`overline` is a function which takes a series of route-allocated lines,
splits them into unique segmentes and aggregates
the values of overlapping lines. This can represent where there will be
most traffic on the transport system, as illustrated
Expand All @@ -87,7 +87,7 @@ with the plotting using [tmap](https://github.com/mtennekes/tmap).]

```{r rnet}
routes$All <- travel_network$All
rnet <- gOverline(sldf = routes, attrib = "All", fun = sum)
rnet <- overline(sldf = routes, attrib = "All", fun = sum)
osm_tiles <- read_osm(bb(rnet, ext = 1.05))
rnet$lwd <- rnet$All / mean(rnet$All)
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ plot(routes)

For more examples, `example("line2route")`.

`gOverline` is a function which takes a series of route-allocated lines,
`overline` is a function which takes a series of route-allocated lines,
splits them into unique segmentes and aggregates
the values of overlapping lines. This can represent where there will be
most traffic on the transport system, as illustrated
Expand All @@ -121,7 +121,7 @@ with the plotting using [tmap](https://github.com/mtennekes/tmap).]

```r
routes$All <- travel_network$All
rnet <- gOverline(sldf = routes, attrib = "All", fun = sum)
rnet <- overline(sldf = routes, attrib = "All", fun = sum)

osm_tiles <- read_osm(bb(rnet, ext = 1.05))
rnet$lwd <- rnet$All / mean(rnet$All)
Expand Down Expand Up @@ -190,12 +190,12 @@ lsf.str("package:stplanr", all = TRUE)
## dd_loglin : function (x, a = 0.3, b1 = -0.2)
## dd_logsqrt : function (x, a, b1, b2)
## disab_recat : function (a)
## gClip : function (shp, bb)
## gMapshape : function (dsn, percent)
## gOnewaygeo : function (x, attrib)
## gOnewayid : function (x, attrib, id1 = names(x)[1], id2 = names(x)[2])
## gOverline : function (sldf, attrib, fun = sum, na.zero = FALSE)
## gSection : function (sl)
## gclip : function (shp, bb)
## mapshape : function (dsn, percent)
## onewaygeo : function (x, attrib)
## onewayid : function (x, attrib, id1 = names(x)[1], id2 = names(x)[2])
## overline : function (sldf, attrib, fun = sum, na.zero = FALSE)
## gsection : function (sl)
## islines : function (g1, g2)
## line2df : function (l)
## line2route : function (ldf, ...)
Expand Down

0 comments on commit 815afa2

Please sign in to comment.