Skip to content

Commit

Permalink
address point 2. mentioned in #1310
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Mar 20, 2020
1 parent 53f4dfb commit 05f14dc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ S3method(st_reverse,sfc)
S3method(st_reverse,sfg)
S3method(st_sample,sf)
S3method(st_sample,sfc)
S3method(st_sample,sfg)
S3method(st_segmentize,sf)
S3method(st_segmentize,sfc)
S3method(st_segmentize,sfg)
Expand Down
6 changes: 6 additions & 0 deletions R/sample.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ st_sample.sfc = function(x, size, ..., type = "random", exact = TRUE) {
res
}

#' @export
#' @name st_sample
st_sample.sfg = function(x, size, ...) {
st_sample(st_geometry(x), size, ...)
}

st_poly_sample = function(x, size, ..., type = "random",
offset = st_sample(st_as_sfc(st_bbox(x)), 1)[[1]]) {

Expand Down
3 changes: 2 additions & 1 deletion R/valid.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ st_make_valid.sfg = function(x) {

#' @export
st_make_valid.sfc = function(x) {
crs = st_crs(x)
x = if (sf_extSoftVersion()["GEOS"] < "3.8.0") {
if (!requireNamespace("lwgeom", quietly = TRUE))
stop("lwgeom required: install that first") # nocov
lwgeom::lwgeom_make_valid(x)
} else
CPL_geos_make_valid(x) # nocov
st_sfc(x, crs = st_crs(x))
st_sfc(x, crs = crs)
}

#' @export
Expand Down
3 changes: 3 additions & 0 deletions man/st_sample.Rd

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

1 change: 1 addition & 0 deletions tests/sfc.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ options(digits=6)
x = st_sfc(st_polygon(list(rbind(c(0,1),c(90,1),c(90,90),c(0,90),c(0,1)))), crs = st_crs(4326))
#if (sf_extSoftVersion()["proj.4"] >= "4.9.0")
(p <- st_sample(x, 10))
p <- st_sample(x[[1]], 10) # sfg method
x = st_sfc(st_polygon(list(rbind(c(0,0),c(90,0),c(90,90),c(0,90),c(0,0))))) # NOT long/lat:
p <- st_sample(x, 10)
x = st_sfc(st_polygon(list(rbind(c(-180,-90),c(180,-90),c(180,90),c(-180,90),c(-180,-90)))),
Expand Down

0 comments on commit 05f14dc

Please sign in to comment.