Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/rm sp group polys #55

Merged
merged 28 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
42767f5
rox -> md
robitalec Aug 17, 2023
3616961
sfPolys not sp
robitalec Aug 17, 2023
ed3055d
test sfPolys
robitalec Aug 17, 2023
50d592f
stop if id null
robitalec Aug 17, 2023
efef67c
fix return id as provided
robitalec Aug 18, 2023
8feef42
test if id returned as provided
robitalec Aug 18, 2023
701a7bd
fix modify by reference in build_polys, breaks group_polys by
robitalec Aug 18, 2023
aeaaf9f
flex return if DT/sfPolys provided
robitalec Aug 18, 2023
4b50752
intersection
robitalec Aug 18, 2023
09e99c7
area, proportions return units
robitalec Aug 18, 2023
d51f900
set agr to constant to avoid warnings
robitalec Aug 18, 2023
e44278b
check disjointed, return 0 area proportion
robitalec Aug 18, 2023
b5961ce
fix col checks
robitalec Aug 18, 2023
e03e7d8
use epsg num
robitalec Aug 18, 2023
3344ed9
fix unnecessary promises, warnings
robitalec Aug 18, 2023
306856e
test lengths returned expected
robitalec Aug 18, 2023
f8d8bb7
test area, proportions returned expected
robitalec Aug 18, 2023
f894ebf
fix quote percent
robitalec Aug 18, 2023
bf92aa3
intro
robitalec Aug 18, 2023
3a3916e
r spatial evol
robitalec Aug 18, 2023
aef937b
projection edits
robitalec Aug 18, 2023
83f8bd7
note units returned
robitalec Aug 18, 2023
ded91bc
note splitBy cant be used with sfPolys
robitalec Aug 18, 2023
b8f3310
use epsg numb
robitalec Aug 18, 2023
de7a5df
double |
robitalec Aug 18, 2023
7f8bd53
update group polys descriptions in vignettes
robitalec Aug 18, 2023
6650588
man
robitalec Aug 18, 2023
9d9d211
fix typos
robitalec Aug 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions R/build_polys.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#'
#' Please note, spatsoc has followed updates from R spatial, GDAL and PROJ for
#' handling projections, see more below and details at
#' \url{https://r-spatial.org/r/2020/03/17/wkt.html}.
#' <https://r-spatial.org/r/2020/03/17/wkt.html>.
#'
#' In addition, `build_polys` previously used [sp::SpatialPoints] but has been
#' updated to use [sf::st_as_sf] according to the R-spatial evolution, see more
#' at \url{https://r-spatial.org/r/2022/04/12/evolution.html}. A deprecated
#' at <https://r-spatial.org/r/2022/04/12/evolution.html>. A deprecated
#' version of this function using [sp::SpatialPoints] is retained as
#' [build_polys_sp] temporarily but users are urged to transition as soon as
#' possible.
Expand All @@ -39,7 +39,7 @@
#' defining the coordinate reference system to be passed to [sf::st_crs].
#' For example, for UTM zone 36S (EPSG 32736), the projection
#' argument is `projection = "EPSG:32736"` or `projection = 32736`.
#' See \url{https://spatialreference.org}
#' See <https://spatialreference.org>
#' for a list of EPSG codes.
#'
#' The `hrType` must be either one of "kernel" or "mcp". The
Expand Down Expand Up @@ -181,14 +181,16 @@ build_polys <- function(DT = NULL,
}

if (is.null(spPts)) {
DT[, ade_id := do.call(function(...) paste(..., sep = '-'), .SD),
.SDcols = c(splitBy)]
ade_id <- DT[, do.call(function(...) paste(..., sep = '-'), .SD),
.SDcols = c(splitBy)]

spPts <- sf::as_Spatial(
sf::st_as_sf(
DT[, .SD, .SDcols = c(coords, 'ade_id')],
DT[, cbind(.SD, ade_id), .SDcols = c(coords)],
coords = coords,
crs = sf::st_crs(projection)),
IDs = DT$ade_id
crs = sf::st_crs(projection)
),
IDs = ade_id
)
}

Expand Down Expand Up @@ -240,7 +242,9 @@ build_polys <- function(DT = NULL,
stop('hrType not one of "kernel" or "mcp"')
}

return(sf::st_as_sf(out))
out_sf <- sf::st_as_sf(out)
colnames(out_sf) <- gsub('id', id, colnames(out_sf))
return(out_sf)
}


2 changes: 1 addition & 1 deletion R/build_polys_sp.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @export
#'
#' @family Build functions
#' @seealso \code{\link{group_polys}}
#' @seealso [group_polys()]
build_polys_sp <- function(DT = NULL,
projection = NULL,
hrType = NULL,
Expand Down
Loading