Skip to content

Commit

Permalink
Merge pull request #239 from luukvdmeer/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
luukvdmeer authored Mar 22, 2023
2 parents d3374b5 + d9b5ad2 commit 23a4125
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 98 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: sfnetworks
Title: Tidy Geospatial Networks
Version: 0.6.2
Version: 0.6.3
Authors@R:
c(person(given = "Lucas",
family = "van der Meer",
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# sfnetworks v0.6.3

### Bug fixes

* Argument names of sfnetwork S3 methods for `sf::st_geometry()`, `sf::st_bbox()`, `sf::st_m_range()` and `sf::st_set_precision()` are updated to be consistent with their corresponding generic functions in sf.
* Arguments `active` and `...` are removed from the sfnetwork S3 method for `sf::st_precision()` to be consistent with its corresponding generic function in sf.
* Argument `active` is removed from the sfnetwork S3 method for `sf::st_crs()` to be consistent with the above-mentioned change regarding `sf::st_precision()` (since both CRS and precision can not differ between nodes and edges).

# sfnetworks v0.6.2

### Bug fixes
Expand Down
117 changes: 34 additions & 83 deletions R/sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ is.sfg = function(x) {
#'
#' @param x An object of class \code{\link{sfnetwork}}.
#'
#' @param obj An object of class \code{\link{sfnetwork}}.
#'
#' @param y An object of class \code{\link[sf]{sf}}, or directly convertible to
#' it using \code{\link[sf]{st_as_sf}}. In some cases, it can also be an object
#' of \code{\link[sf:st]{sfg}} or \code{\link[sf:st_bbox]{bbox}}. Always look
Expand All @@ -30,6 +32,9 @@ is.sfg = function(x) {
#' @param value The value to be assigned. See the documentation of the
#' corresponding sf function for details.
#'
#' @param precision The precision to be assigned. See
#' \code{\link[sf]{st_precision}} for details.
#'
#' @return The \code{sfnetwork} method for \code{\link[sf]{st_as_sf}} returns
#' the active element of the network as object of class \code{\link[sf]{sf}}.
#' The \code{sfnetwork} and \code{morphed_sfnetwork} methods for
Expand Down Expand Up @@ -95,13 +100,7 @@ edges_as_sf = function(x, ...) {
#' @importFrom sf st_as_s2
#' @export
st_as_s2.sfnetwork = function(x, active = NULL, ...) {
if (is.null(active)) active = attr(x, "active")
switch(
active,
nodes = st_as_s2(pull_node_geom(x), ...),
edges = st_as_s2(pull_edge_geom(x), ...),
raise_unknown_input(active)
)
st_as_s2(pull_geom(x, active), ...)
}

# =============================================================================
Expand All @@ -118,8 +117,8 @@ st_as_s2.sfnetwork = function(x, active = NULL, ...) {
#'
#' @importFrom sf st_geometry
#' @export
st_geometry.sfnetwork = function(x, active = NULL, ...) {
pull_geom(x, active)
st_geometry.sfnetwork = function(obj, active = NULL, ...) {
pull_geom(obj, active)
}

#' @name sf
Expand Down Expand Up @@ -147,45 +146,31 @@ st_drop_geometry.sfnetwork = function(x, ...) {
#' # Get bbox of the active network element.
#' st_bbox(net)
#'
#' @importFrom sf st_bbox st_geometry
#' @importFrom sf st_bbox
#' @export
st_bbox.sfnetwork = function(x, active = NULL, ...) {
if (is.null(active)) active = attr(x, "active")
switch(
active,
nodes = st_bbox(pull_node_geom(x), ...),
edges = st_bbox(pull_edge_geom(x), ...),
raise_unknown_input(active)
)
st_bbox.sfnetwork = function(obj, active = NULL, ...) {
st_bbox(pull_geom(obj, active), ...)
}

#' @name sf
#' @importFrom sf st_coordinates st_geometry
#' @importFrom sf st_coordinates
#' @export
st_coordinates.sfnetwork = function(x, active = NULL, ...) {
if (is.null(active)) active = attr(x, "active")
switch(
active,
nodes = st_coordinates(pull_node_geom(x), ...),
edges = st_coordinates(pull_edge_geom(x), ...),
raise_unknown_input(active)
)
st_coordinates(pull_geom(x, active), ...)
}

#' @name sf
#' @importFrom sf st_is
#' @export
st_is.sfnetwork = function(x, ...) {
active = attr(x, "active")
st_is(pull_geom(x, active), ...)
st_is(pull_geom(x), ...)
}

#' @name sf
#' @importFrom sf st_is_valid
#' @export
st_is_valid.sfnetwork = function(x, ...) {
active = attr(x, "active")
st_is_valid(pull_geom(x, active), ...)
st_is_valid(pull_geom(x), ...)
}

# =============================================================================
Expand All @@ -199,14 +184,8 @@ st_is_valid.sfnetwork = function(x, ...) {
#'
#' @importFrom sf st_crs
#' @export
st_crs.sfnetwork = function(x, active = NULL, ...) {
if (is.null(active)) active = attr(x, "active")
switch(
active,
nodes = st_crs(pull_node_geom(x), ...),
edges = st_crs(pull_edge_geom(x), ...),
raise_unknown_input(active)
)
st_crs.sfnetwork = function(x, ...) {
st_crs(pull_geom(x), ...)
}

#' @name sf
Expand All @@ -226,27 +205,21 @@ st_crs.sfnetwork = function(x, active = NULL, ...) {
#' @name sf
#' @importFrom sf st_precision
#' @export
st_precision.sfnetwork = function(x, active = NULL, ...) {
if (is.null(active)) active = attr(x, "active")
switch(
active,
nodes = st_precision(pull_node_geom(x), ...),
edges = st_precision(pull_edge_geom(x), ...),
raise_unknown_input(active)
)
st_precision.sfnetwork = function(x) {
st_precision(pull_geom(x))
}

#' @name sf
#' @importFrom sf st_set_precision st_precision<-
#' @export
st_set_precision.sfnetwork = function(x, value) {
st_set_precision.sfnetwork = function(x, precision) {
if (attr(x, "active") == "edges" || has_explicit_edges(x)) {
geom = pull_edge_geom(x)
st_precision(geom) = value
st_precision(geom) = precision
x = mutate_edge_geom(x, geom)
}
geom = pull_node_geom(x)
st_precision(geom) = value
st_precision(geom) = precision
mutate_node_geom(x, geom)
}

Expand Down Expand Up @@ -286,29 +259,17 @@ st_zm.sfnetwork = function(x, ...) {
}

#' @name sf
#' @importFrom sf st_geometry st_m_range
#' @importFrom sf st_m_range
#' @export
st_m_range.sfnetwork = function(x, active = NULL, ...) {
if (is.null(active)) active = attr(x, "active")
switch(
active,
nodes = st_m_range(pull_node_geom(x), ...),
edges = st_m_range(pull_edge_geom(x), ...),
raise_unknown_input(active)
)
st_m_range.sfnetwork = function(obj, active = NULL, ...) {
st_m_range(pull_geom(obj, active), ...)
}

#' @name sf
#' @importFrom sf st_geometry st_z_range
#' @importFrom sf st_z_range
#' @export
st_z_range.sfnetwork = function(x, active = NULL, ...) {
if (is.null(active)) active = attr(x, "active")
switch(
active,
nodes = st_z_range(pull_node_geom(x), ...),
edges = st_z_range(pull_edge_geom(x), ...),
raise_unknown_input(active)
)
st_z_range.sfnetwork = function(obj, active = NULL, ...) {
st_z_range(pull_geom(obj, active), ...)
}

change_coords = function(x, op, ...) {
Expand Down Expand Up @@ -337,13 +298,7 @@ change_coords = function(x, op, ...) {
#' @importFrom sf st_agr
#' @export
st_agr.sfnetwork = function(x, active = NULL, ...) {
if (is.null(active)) active = attr(x, "active")
switch(
active,
nodes = node_agr(x),
edges = edge_agr(x),
raise_unknown_input(active)
)
agr(x, active)
}

#' @name sf
Expand Down Expand Up @@ -779,34 +734,30 @@ find_indices_to_drop = function(x, y, ..., .operator = sf::st_filter) {
#' @importFrom sf st_geometry st_intersects
#' @export
st_intersects.sfnetwork = function(x, y, ...) {
active = attr(x, "active")
if (missing(y)) {
st_intersects(pull_geom(x, active), ...)
st_intersects(pull_geom(x), ...)
} else {
st_intersects(pull_geom(x, active), st_geometry(y), ...)
st_intersects(pull_geom(x), st_geometry(y), ...)
}
}

#' @name sf
#' @importFrom sf st_as_sf st_sample
#' @export
st_sample.sfnetwork = function(x, ...) {
active = attr(x, "active")
st_sample(st_as_sf(x, active), ...)
st_sample(st_as_sf(x), ...)
}

#' @name sf
#' @importFrom sf st_geometry st_nearest_points
#' @export
st_nearest_points.sfnetwork = function(x, y, ...) {
active = attr(x, "active")
st_nearest_points(pull_geom(x, active), st_geometry(y), ...)
st_nearest_points(pull_geom(x), st_geometry(y), ...)
}

#' @name sf
#' @importFrom sf st_area
#' @export
st_area.sfnetwork = function(x, ...) {
active = attr(x, "active")
st_area(pull_geom(x, active), ...)
st_area(pull_geom(x), ...)
}
20 changes: 14 additions & 6 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
In this release we have made the following changes:

* The reference to `sf:::agr_levels` is removed, solving the note in the CRAN checks about the usage of the `:::` operator.
* Unit tests that where failing after an igraph update now run successfully again. Refs [#232](https://github.com/luukvdmeer/sfnetworks/issues/232). This means the CRAN checks that where failing should now be passing successfully again.
* Unit test stuck in an infinite loop caused by usage of `sf::st_sample()` on a polygon crossing the date line updated accordingly. See [this sf issue](https://github.com/r-spatial/sf/issues/1984) for details on the underlying problem.
* The `to_spatial_contracted()` morpher now correctly handles cases for undirected networks in which only loop edges are created after contraction. Refs [#237](https://github.com/luukvdmeer/sfnetworks/issues/237).
* The `to_spatial_contracted()` morpher now directly returns the original network when none of the contraction groups contain more than one node.
* Umbrella packages tidyverse and spatstat are no longer suggested packages. Only individual members of these packages are now suggested packages.
* Argument names of sfnetwork S3 methods for `sf::st_geometry()`, `sf::st_bbox()`, `sf::st_m_range()` and `sf::st_set_precision()` are updated to be consistent with their corresponding generic functions in sf.
* Arguments `active` and `...` are removed from the sfnetwork S3 method for `sf::st_precision()` to be consistent with its corresponding generic function in sf.
* Argument `active` is removed from the sfnetwork S3 method for `sf::st_crs()` to be consistent with the above-mentioned change regarding `sf::st_precision()` (since both CRS and precision can not differ between nodes and edges).

These changes solve the warnings in the CRAN checks regarding S3 method consistency.

## R CMD check results

0 errors | 0 warnings | 0 notes

When running checks on R-hub, the following note occured only on Windows (Server 2022, R-devel 64-bit):

```
* checking for detritus in the temp directory ... NOTE
Found the following files/directories:
'lastMiKTeXException'
```
As noted in [R-hub issue #503](https://github.com/r-hub/rhub/issues/503), this is a bug in R-hub rather than a bug in our package, and can likely be ignored.

## revdepcheck results

We checked 1 reverse dependencies (0 from CRAN + 1 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package.
Expand Down
2 changes: 1 addition & 1 deletion man/as.linnet.Rd

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

19 changes: 12 additions & 7 deletions man/sf.Rd

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

0 comments on commit 23a4125

Please sign in to comment.