Skip to content

Commit

Permalink
MULTICURVE -> MULTILINESTRING cast; fixes #1194
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Nov 18, 2019
1 parent ca08ad1 commit 587b90d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ S3method(st_cast,COMPOUNDCURVE)
S3method(st_cast,CURVE)
S3method(st_cast,GEOMETRYCOLLECTION)
S3method(st_cast,LINESTRING)
S3method(st_cast,MULTICURVE)
S3method(st_cast,MULTILINESTRING)
S3method(st_cast,MULTIPOINT)
S3method(st_cast,MULTIPOLYGON)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# version 0.8-1

* add `st_cast` method from `MULTICURVE` to `MULTILINESTRING`; #1194

* `st_read` gains a parameter `wkt_filter` for spatially filtering the features to be read; #1192

* `st_area()` and `st_length()` handle `+to_meter` argument in PROJ strings; #1170
Expand Down
1 change: 1 addition & 0 deletions R/cast_sfc.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ which_sfc_col = function(cls) {
MULTILINESTRING = 2,
POLYGON = 2,
MULTIPOLYGON = 3,
MULTICURVE = 3,
GEOMETRYCOLLECTION = 4,
MULTISURFACE = 4,
GEOMETRY = 5,
Expand Down
13 changes: 11 additions & 2 deletions R/cast_sfg.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,21 @@ st_cast.MULTISURFACE <- function(x, to, ...) {
#' @name st_cast
#' @export
st_cast.COMPOUNDCURVE <- function(x, to, ...) {
if (! missing(to))
stop("to should be missing")
if (! missing(to) && to != "LINESTRING")
stop("to should be missing or LINESTRING")
CPL_compoundcurve_to_linear(structure(list(x), crs = NA_crs_, precision = 0.0,
class = c("sfc_COMPOUNDCURVE", "sfc")))[[1]]
}

#' @name st_cast
#' @export
st_cast.MULTICURVE <- function(x, to, ...) {
if (! missing(to))
stop("to should be missing")
st_multilinestring(lapply(x, st_cast, to = "LINESTRING"))
}


#' @name st_cast
#' @export
st_cast.CURVE <- function(x, to, ...) { # nocov start
Expand Down
3 changes: 3 additions & 0 deletions man/st_cast.Rd

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

6 changes: 6 additions & 0 deletions tests/cast.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,9 @@ st_is(sfc, "POLYGON")
st_is(sfc, "LINESTRING")
st_is(st_sf(a = 1:2, sfc), "LINESTRING")
st_is(sfc, c("POINT", "LINESTRING"))

#1194:
wkt <- "MULTICURVE (COMPOUNDCURVE (LINESTRING (-83.62333 35.55244, -83.62328 35.55232, -83.62323 35.55223, -83.62319 35.55216, -83.62312 35.55209, -83.6231 35.55207), CIRCULARSTRING (-83.6231 35.55207, -83.62307 35.55205, -83.62302 35.55204), LINESTRING (-83.62302 35.55204, -83.62299 35.55203, -83.62289 35.55198, -83.62281 35.55189, -83.62271 35.55182)))"
g <- st_as_sfc(wkt)
g <- st_sf(demo = "test", geom = g, crs = 4326)
st_cast(g, "MULTILINESTRING")

0 comments on commit 587b90d

Please sign in to comment.