Skip to content

Commit

Permalink
Merge pull request #57 from paleolimbot/geos-3-10-features
Browse files Browse the repository at this point in the history
Add support for new features in GEOS 3.10
  • Loading branch information
paleolimbot authored Oct 24, 2021
2 parents 9d6ada0 + 1c80196 commit 1a6ca9a
Show file tree
Hide file tree
Showing 16 changed files with 668 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: '3.6'}
# Skip windows 3.6 for now because s2->sf fails to build
# - {os: windows-latest, r: '3.6'}
- {os: windows-latest, r: 'release'}
- {os: windows-2022, r: 'devel-ucrt'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
Expand Down
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export(geos_centroid)
export(geos_clearance_line_between)
export(geos_clip_by_rect)
export(geos_clone)
export(geos_constrained_delaunay_triangles)
export(geos_contains)
export(geos_contains_any)
export(geos_contains_matrix)
Expand All @@ -94,6 +95,7 @@ export(geos_crosses_any)
export(geos_crosses_matrix)
export(geos_delaunay_edges)
export(geos_delaunay_triangles)
export(geos_densify)
export(geos_difference)
export(geos_difference_prec)
export(geos_dimension)
Expand Down Expand Up @@ -131,6 +133,7 @@ export(geos_is_ring)
export(geos_is_simple)
export(geos_is_valid)
export(geos_is_valid_detail)
export(geos_is_within_distance)
export(geos_largest_empty_circle_spec)
export(geos_largest_empty_crc)
export(geos_length)
Expand All @@ -139,6 +142,7 @@ export(geos_make_linestring)
export(geos_make_point)
export(geos_make_polygon)
export(geos_make_valid)
export(geos_make_valid_params)
export(geos_maximum_inscribed_circle_spec)
export(geos_maximum_inscribed_crc)
export(geos_merge_lines)
Expand Down Expand Up @@ -180,11 +184,13 @@ export(geos_prepared_crosses)
export(geos_prepared_disjoint)
export(geos_prepared_distance)
export(geos_prepared_intersects)
export(geos_prepared_is_within_distance)
export(geos_prepared_overlaps)
export(geos_prepared_touches)
export(geos_prepared_within)
export(geos_project)
export(geos_project_normalized)
export(geos_read_geojson)
export(geos_read_hex)
export(geos_read_wkb)
export(geos_read_wkt)
Expand Down Expand Up @@ -225,6 +231,7 @@ export(geos_voronoi_polygons)
export(geos_within)
export(geos_within_any)
export(geos_within_matrix)
export(geos_write_geojson)
export(geos_write_hex)
export(geos_write_wkb)
export(geos_write_wkt)
Expand Down
20 changes: 19 additions & 1 deletion R/geos-binary-atomic.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#' Distance calculations
#'
#' @param geom1,geom2 [GEOS geometry vectors][as_geos_geometry],
#' recycled to a common length.
#' recycled to a common length.
#' @param distance A threshold distance, below which [geos_is_within_distance()]
#' and [geos_prepared_is_within_distance()] will return `TRUE`.
#' @param densify A fraction between 0 and 1 denoting the degree to which
#' edges should be subdivided (smaller value means more subdivisions).
#' Use NULL to calculate the distance as-is.
Expand Down Expand Up @@ -60,6 +62,22 @@ geos_distance_frechet <- function(geom1, geom2, densify = NULL) {
}
}

#' @rdname geos_distance
#' @export
geos_is_within_distance <- function(geom1, geom2, distance) {
recycled <- recycle_common(list(sanitize_geos_geometry(geom1), sanitize_geos_geometry(geom2), as.numeric(distance)))
wk_crs_output(recycled[[1]], recycled[[2]])
.Call(geos_c_is_within_distance, recycled[[1]], recycled[[2]], recycled[[3]])
}

#' @rdname geos_distance
#' @export
geos_prepared_is_within_distance <- function(geom1, geom2, distance) {
recycled <- recycle_common(list(sanitize_geos_geometry(geom1), sanitize_geos_geometry(geom2), as.numeric(distance)))
wk_crs_output(recycled[[1]], recycled[[2]])
.Call(geos_c_prepared_is_within_distance, recycled[[1]], recycled[[2]], recycled[[3]])
}

#' Linear referencing
#'
#' - [geos_project()] and [geos_project_normalized()] return
Expand Down
35 changes: 31 additions & 4 deletions R/geos-io.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#' @param precision The number of significant digits to include iin WKT
#' output.
#' @param endian 0 for big endian or 1 for little endian.
#' @param flavor One of "extended" (i.e., EWKB) or "iso".
#' @param indent The number of spaces to use when indenting a formatted
#' version of the output. Use -1 to indicate no formatting.
#' @inheritParams geos_segment_intersection
#' @param hex A hexidecimal representation of well-known binary
#' @inheritParams wk::wk_crs
Expand All @@ -40,6 +43,22 @@ geos_write_wkt <- function(geom, include_z = TRUE, precision = 16, trim = TRUE)
)
}

#' @rdname geos_read_wkt
#' @export
geos_read_geojson <- function(wkt, crs = NULL) {
new_geos_geometry(.Call(geos_c_read_geojson, as.character(wkt)), crs = crs)
}

#' @rdname geos_read_wkt
#' @export
geos_write_geojson <- function(geom, indent = -1) {
.Call(
geos_c_write_geojson,
sanitize_geos_geometry(geom),
sanitize_integer_scalar(indent)
)
}

#' @rdname geos_read_wkt
#' @export
geos_read_wkb <- function(wkb, crs = NULL) {
Expand All @@ -48,14 +67,18 @@ geos_read_wkb <- function(wkb, crs = NULL) {

#' @rdname geos_read_wkt
#' @export
geos_write_wkb <- function(geom, include_z = TRUE, include_srid = FALSE, endian = 1) {
geos_write_wkb <- function(geom, include_z = TRUE, include_srid = FALSE, endian = 1,
flavor = c("extended", "iso")) {
flavor <- match.arg(flavor)

structure(
.Call(
geos_c_write_wkb,
sanitize_geos_geometry(geom),
sanitize_logical_scalar(include_z),
sanitize_logical_scalar(include_srid),
sanitize_integer_scalar(endian)
sanitize_integer_scalar(endian),
match(flavor, c("extended", "iso"))
),
class = "blob"
)
Expand All @@ -69,13 +92,17 @@ geos_read_hex <- function(hex, crs = NULL) {

#' @rdname geos_read_wkt
#' @export
geos_write_hex <- function(geom, include_z = TRUE, include_srid = FALSE, endian = 1) {
geos_write_hex <- function(geom, include_z = TRUE, include_srid = FALSE, endian = 1,
flavor = c("extended", "iso")) {
flavor <- match.arg(flavor)

.Call(
geos_c_write_hex,
sanitize_geos_geometry(geom),
sanitize_logical_scalar(include_z),
sanitize_logical_scalar(include_srid),
sanitize_integer_scalar(endian)
sanitize_integer_scalar(endian),
match(flavor, c("extended", "iso"))
)
}

Expand Down
51 changes: 47 additions & 4 deletions R/geos-unary-geometry.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#' Geometry transformers
#'
#' @inheritParams geos_read_wkt
#' @param tolerance A minimum distance to use for simplification. Use a higher
#' value for more simplification.
#' @param tolerance A minimum distance to use for simplification or
#' densification. Use a higher value for more simplification (or
#' less densification).
#' @param index The index of the point or geometry to extract.
#' @param rect A `list()` representing rectangles in the form
#' `list(xmin, ymin, xmax, ymax)`. List items with length 1 will be
Expand All @@ -15,6 +16,13 @@
#' be preserved?
#' @param keep_collapsed Should items that become EMPTY due to rounding
#' be kept in the output?
#' @param make_valid_params A [geos_make_valid_params()] object.
#' @param method The method to use for [geos_make_valid()]. One of:
#' - "make_valid_linework" combines all rings into a set of noded lines
#' and then extracts valid polygons from that linework.
#' - "make_valid_structure" Structured method, first makes all rings valid
#' then merges shells and subtracts holes from shells to generate valid
#' result. Assumes that holes and shells are correctly categorized.
#' @param grid_size For `_prec()` variants, the grid size such that all vertices of
#' the resulting geometry will lie on the grid.
#'
Expand Down Expand Up @@ -173,9 +181,27 @@ geos_node <- function(geom) {

#' @rdname geos_centroid
#' @export
geos_make_valid <- function(geom) {
geos_make_valid <- function(geom, make_valid_params = geos_make_valid_params()) {
geom <- sanitize_geos_geometry(geom)
new_geos_geometry(.Call(geos_c_make_valid, geom), crs = attr(geom, "crs", exact = TRUE))
new_geos_geometry(
.Call(geos_c_make_valid_with_params, geom, make_valid_params),
crs = attr(geom, "crs", exact = TRUE)
)
}

#' @rdname geos_centroid
#' @export
geos_make_valid_params <- function(keep_collapsed = TRUE,
method = c("make_valid_linework", "make_valid_structure")) {
method <- match.arg(method)

structure(
list(
keep_collapsed = sanitize_logical_scalar(keep_collapsed),
method = match(method, c("make_valid_linework", "make_valid_structure")) - 1L
),
class = "geos_make_valid_params"
)
}

#' @rdname geos_centroid
Expand Down Expand Up @@ -332,6 +358,13 @@ geos_normalize <- function(geom) {
new_geos_geometry(.Call(geos_c_normalize, geom), crs = attr(geom, "crs", exact = TRUE))
}

#' @rdname geos_centroid
#' @export
geos_densify <- function(geom, tolerance) {
recycled <- recycle_common(list(sanitize_geos_geometry(geom), as.numeric(tolerance)))
new_geos_geometry(.Call(geos_c_densify, recycled[[1]], recycled[[2]]), crs = attr(geom, "crs", exact = TRUE))
}

#' @rdname geos_centroid
#' @export
geos_clip_by_rect <- function(geom, rect) {
Expand Down Expand Up @@ -488,6 +521,16 @@ geos_delaunay_triangles <- function(geom, tolerance = 0) {
)
}

#' @rdname geos_delaunay_triangles
#' @export
geos_constrained_delaunay_triangles <- function(geom) {
geom <- sanitize_geos_geometry(geom)
new_geos_geometry(
.Call(geos_c_constrained_delaunay_triangulation, geom),
crs = attr(geom, "crs", exact = TRUE)
)
}

#' @rdname geos_delaunay_triangles
#' @export
geos_delaunay_edges <- function(geom, tolerance = 0) {
Expand Down
33 changes: 27 additions & 6 deletions man/geos_centroid.Rd

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

3 changes: 3 additions & 0 deletions man/geos_delaunay_triangles.Rd

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

9 changes: 9 additions & 0 deletions man/geos_distance.Rd

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

Loading

0 comments on commit 1a6ca9a

Please sign in to comment.