Skip to content

Commit

Permalink
Fix bug in construct_buffer()
Browse files Browse the repository at this point in the history
  • Loading branch information
mhesselbarth committed Dec 5, 2023
1 parent e08ceec commit 2ae9d20
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# landscapemetrics 2.1.0
# landscapemetrics 2.1.1
* Bugfixes
* Bugfix in calculate of clumpy if NA calc is present
* Bugfix in calculate of clumpy if NA values are present
* Bugfix in construct_buffer that CRS was lost

# landscapemetrics 2.1.0
* Improvements
Expand Down
5 changes: 3 additions & 2 deletions R/construct_buffer.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @param size Size of sample plot. Equals the radius for circles or the
#' side-length for squares in map units
#' @param return_vec If TRUE, vector objects are returned.
#' @param crs The coordinate reference system used for vector objects.
#' @param verbose Print warning messages.
#'
#' @return
Expand All @@ -22,7 +23,7 @@
#' @keywords internal
#'
#' @export
construct_buffer <- function(coords, shape , size, return_vec = TRUE, verbose = TRUE) {
construct_buffer <- function(coords, shape , size, return_vec = TRUE, crs="", verbose = TRUE) {

# make sure coords are matrix
coords <- points_as_mat(pts = coords)
Expand Down Expand Up @@ -80,7 +81,7 @@ construct_buffer <- function(coords, shape , size, return_vec = TRUE, verbose =

mat <- matrix(x, ncol = 2)

terra::vect(x = mat, type = "polygon")
terra::vect(x = mat, type = "polygon", crs = crs)

})

Expand Down
5 changes: 4 additions & 1 deletion R/sample_lsm.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,15 @@ sample_lsm_int <- function(landscape, y, plot_id, shape, size,
# convert to terra
y <- methods::as(y, "SpatVector")

# get crs
crs <- terra::crs(y)

if (terra::geomtype(y) == "points") {

if (is.null(size) | size == 0) stop("Please provide size argument size > 0.", call. = FALSE)

y <- construct_buffer(coords = y, shape = shape, size = size,
return_vec = TRUE, verbose = verbose)
return_vec = TRUE, crs = crs, verbose = verbose)

}

Expand Down
11 changes: 10 additions & 1 deletion man/construct_buffer.Rd

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

0 comments on commit 2ae9d20

Please sign in to comment.