Skip to content

Commit

Permalink
Merge branch 'sf' of github.com:dramanica/geograph into sf
Browse files Browse the repository at this point in the history
  • Loading branch information
dramanica committed Dec 19, 2023
2 parents 28fb308 + eac996f commit 532a42e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 15 deletions.
14 changes: 9 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ Depends:
methods,
graph
Imports:
fields,
RBGL,
sp
fields,
RBGL,
rnaturalearth,
rnaturalearthdata,
sp,
sf,
magrittr
Suggests:
testthat,
knitr,
rmarkdown,
sf
rmarkdown
RoxygenNote: 7.2.3
Collate:
'classes.R'
Expand All @@ -49,5 +52,6 @@ Collate:
'rebuild.R'
'setCosts.R'
'setDistCosts.R'
'utils-pipe.R'
'zoom.R'
'zzz.R'
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(plot,gPath)
export("%>%")
export()
export(.gData.valid)
export(.gGraph.valid)
Expand Down Expand Up @@ -77,3 +78,4 @@ import(sp)
importFrom(graphics,identify)
importFrom(graphics,locator)
importFrom(graphics,segments)
importFrom(magrittr,"%>%")
9 changes: 7 additions & 2 deletions R/extractFromLayer.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ setGeneric("extractFromLayer", function(x, ...) {
#' @rdname extractFromLayer
#' @export
setMethod("extractFromLayer", "matrix", function(x, layer = "world", attr = "all", ...) {
sf::sf_use_s2(FALSE)


## This functions automatically assigns to land all points overlapping the country polygons
# if(!require(maptools)) stop("maptools package is required.")
Expand All @@ -93,13 +93,18 @@ setMethod("extractFromLayer", "matrix", function(x, layer = "world", attr = "all
if (is.character(layer) && layer[1] == "world") {
# use rnaturalearth instead of the inbuilt dataset
# layer <- rnaturalearth::ne_countries(scale="medium", returnclass = "sf")
# sf::sf_use_s2(FALSE)
layer <- sf::st_read(system.file("files/shapefiles/world-countries.shp", package = "geoGraph"))
}

## TODO if the layer is null, we should throw an error!!!
if (!is.null(layer)) {
if (!inherits(layer, "sf")) {
stop("Layer must be a sf object \n(see st_read in sf to import such data from a GIS shapefile).")
if (inherits(layer, "SpatialPolygonsDataFrame")){
layer <- sf::st_as_sf(layer)
} else {
stop("Layer must be a sf object \n(see st_read in sf to import such data from a GIS shapefile).")
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions R/utils-pipe.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#' Pipe operator
#'
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
#'
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @export
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
#' @param lhs A value or the magrittr placeholder.
#' @param rhs A function call using the magrittr semantics.
#' @return The result of calling `rhs(lhs)`.
NULL
8 changes: 1 addition & 7 deletions man/extractFromLayer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/pipe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/setCosts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 532a42e

Please sign in to comment.