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

Add new features from GEOS 3.11.0 #69

Merged
merged 16 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 5 additions & 6 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ jobs:
matrix:
config:
- {os: macOS-latest, r: 'release'}
# Skip windows 3.6 for now because s2->sf fails to build
# - {os: windows-latest, r: '3.6'}
- {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 All @@ -34,19 +33,19 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-pandoc@v1
- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v1
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: rcmdcheck

- uses: r-lib/actions/check-r-package@v1
- uses: r-lib/actions/check-r-package@v2

- name: Show testthat output
if: always()
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-pandoc@v1
- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v1
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: pkgdown
needs: website
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v1
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: covr

Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Description: Provides an R API to the Open Source Geometry Engine
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.0
Suggests:
testthat (>= 3.0.0),
vctrs,
Expand Down
10 changes: 10 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export(geos_centroid)
export(geos_clearance_line_between)
export(geos_clip_by_rect)
export(geos_clone)
export(geos_concave_hull)
export(geos_concave_hull_of_polygons)
export(geos_constrained_delaunay_triangles)
export(geos_contains)
export(geos_contains_any)
Expand All @@ -90,6 +92,7 @@ export(geos_covered_by_matrix)
export(geos_covers)
export(geos_covers_any)
export(geos_covers_matrix)
export(geos_create_rectangle)
export(geos_crosses)
export(geos_crosses_any)
export(geos_crosses_matrix)
Expand All @@ -115,10 +118,12 @@ export(geos_equals_exact)
export(geos_equals_exact_any)
export(geos_equals_exact_matrix)
export(geos_equals_matrix)
export(geos_extent)
export(geos_geometry)
export(geos_geometry_n)
export(geos_geometry_writer)
export(geos_has_z)
export(geos_hilbert_code)
export(geos_interpolate)
export(geos_interpolate_normalized)
export(geos_intersection)
Expand All @@ -137,6 +142,8 @@ export(geos_is_within_distance)
export(geos_largest_empty_circle_spec)
export(geos_largest_empty_crc)
export(geos_length)
export(geos_line_merge)
export(geos_line_merge_directed)
export(geos_make_collection)
export(geos_make_linestring)
export(geos_make_point)
Expand Down Expand Up @@ -171,6 +178,7 @@ export(geos_point_end)
export(geos_point_n)
export(geos_point_on_surface)
export(geos_point_start)
export(geos_polygon_hull_simplify)
export(geos_polygonize)
export(geos_polygonize_cut_edges)
export(geos_polygonize_full)
Expand Down Expand Up @@ -199,6 +207,7 @@ export(geos_relate)
export(geos_relate_pattern)
export(geos_relate_pattern_create)
export(geos_relate_pattern_match)
export(geos_remove_repeated_points)
export(geos_reverse)
export(geos_ring_n)
export(geos_segment_intersection)
Expand All @@ -217,6 +226,7 @@ export(geos_sym_difference_prec)
export(geos_touches)
export(geos_touches_any)
export(geos_touches_matrix)
export(geos_transform_xy)
export(geos_type)
export(geos_type_id)
export(geos_unary_union)
Expand Down
2 changes: 1 addition & 1 deletion R/geos-geometry.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' Create GEOS Geometry Vectors
#'
#' @param x An object to be coerced to a geometry vector
#' @inheritParams wk::wk_crs
#' @param crs An object that can be interpreted as a CRS. See [wk::wk_crs()].
#' @param ... Unused
#'
#' @return A geos geometry vector
Expand Down
21 changes: 12 additions & 9 deletions R/geos-io.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' @param wkb A `list()` of `raw()` vectors (or `NULL` representing
#' an `NA` value).
#' @param wkt a `character()` vector of well-known text
#' @param geojson A `character()` vector fo GeoJSON features
#' @param include_z,include_srid Include the values of the Z and M coordinates and/or
#' SRID in the output?
#' Use `FALSE` to omit, `TRUE` to include, or `NA` to
Expand All @@ -19,16 +20,18 @@
#' 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
#' @param fix_structure Set the reader to automatically repair structural errors
#' in the input (currently just unclosed rings) while reading.
#' @inheritParams as_geos_geometry
#'
#' @export
#'
#' @examples
#' geos_read_wkt("POINT (30 10)")
#' geos_write_wkt(geos_read_wkt("POINT (30 10)"))
#'
geos_read_wkt <- function(wkt, crs = NULL) {
new_geos_geometry(.Call(geos_c_read_wkt, as.character(wkt)), crs = crs)
geos_read_wkt <- function(wkt, fix_structure = FALSE, crs = NULL) {
new_geos_geometry(.Call(geos_c_read_wkt, as.character(wkt), as.logical(fix_structure)[1]), crs = crs)
}

#' @rdname geos_read_wkt
Expand All @@ -45,8 +48,8 @@ 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)
geos_read_geojson <- function(geojson, crs = NULL) {
new_geos_geometry(.Call(geos_c_read_geojson, as.character(geojson)), crs = crs)
}

#' @rdname geos_read_wkt
Expand All @@ -61,8 +64,8 @@ geos_write_geojson <- function(geom, indent = -1) {

#' @rdname geos_read_wkt
#' @export
geos_read_wkb <- function(wkb, crs = NULL) {
new_geos_geometry(.Call(geos_c_read_wkb, as.list(wkb)), crs = crs)
geos_read_wkb <- function(wkb, fix_structure = FALSE, crs = NULL) {
new_geos_geometry(.Call(geos_c_read_wkb, as.list(wkb), as.logical(fix_structure)[1]), crs = crs)
}

#' @rdname geos_read_wkt
Expand All @@ -86,8 +89,8 @@ geos_write_wkb <- function(geom, include_z = TRUE, include_srid = FALSE, endian

#' @rdname geos_read_wkt
#' @export
geos_read_hex <- function(hex, crs = NULL) {
new_geos_geometry(.Call(geos_c_read_hex, as.character(hex)), crs = crs)
geos_read_hex <- function(hex, fix_structure = FALSE, crs = NULL) {
new_geos_geometry(.Call(geos_c_read_hex, as.character(hex), as.logical(fix_structure)[1]), crs = crs)
}

#' @rdname geos_read_wkt
Expand Down
35 changes: 33 additions & 2 deletions R/geos-make.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

#' Create geometries from vectors of coordinates
#'
#' @inheritParams wkutils::coords_point_translate_wkt
#' @param x,y,z Vectors of coordinate values
#' @param feature_id,ring_id Vectors for which a change in sequential values
#' indicates a new feature or ring. Use [factor()] to convert from a character
#' vector.
#' @inheritParams geos_empty
#' @inheritParams geos_write_wkt
#'
Expand Down Expand Up @@ -100,6 +103,34 @@ geos_make_collection <- function(geom, type_id = "geometrycollection", feature_i
}
}

#' Create rectangles from bounds
#'
#' @param xmin Left bound of envelope
#' @param ymin Lower bound of envelope
#' @param xmax Right bound of envelope
#' @param ymax Upper bound of envelope
#' @inheritParams as_geos_geometry
#'
#' @return A [geos_geometry()] consisting of a polygon
#' @export
#'
geos_create_rectangle <- function(xmin, ymin, xmax, ymax,
crs = NULL) {
args <- lapply(list(xmin, ymin, xmax, ymax), as.numeric)
recycled <- recycle_common(args)

new_geos_geometry(
.Call(
geos_c_create_rectangle,
recycled[[1]],
recycled[[2]],
recycled[[3]],
recycled[[4]]
),
crs = crs
)
}


#' Create empty geometries
#'
Expand All @@ -109,7 +140,7 @@ geos_make_collection <- function(geom, type_id = "geometrycollection", feature_i
#' (default to calling [geos_type_id()]). This is most
#' usefully a character vector with the geometry type
#' (e.g., point, linestring, polygon).
#' @inheritParams wk::wk_crs
#' @inheritParams as_geos_geometry
#'
#' @return A [GEOS geometry vector][as_geos_geometry].
#' @export
Expand Down
18 changes: 18 additions & 0 deletions R/geos-unary-atomic.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#' Similarly, the min/max functions will error on empty geometries.
#'
#' @inheritParams geos_read_wkt
#' @param level The Hilbert level of precision (between 0 and 15).
#' @param extent A geometry describing the extent of `geom` within which
#' Hilbert codes should be computed. Defaults to [wk::wk_bbox()] of `geom`.
#'
#' @return A vector of length `geom`
#' @export
Expand Down Expand Up @@ -206,6 +209,21 @@ geos_is_clockwise <- function(geom) {
.Call(geos_c_is_clockwise, sanitize_geos_geometry(geom))
}

#' @rdname geos_area
#' @export
geos_hilbert_code <- function(geom, extent = wk::wk_bbox(geom), level = 15) {
geom <- sanitize_geos_geometry(geom)
extent <- sanitize_geos_geometry(extent)[1]
level <- sanitize_integer_scalar(level)
wk::wk_crs_output(geom, extent)

if (is.na(level) || is.na(extent)) {
rep(NA_integer_, length(geom))
} else {
.Call(geos_c_hilbert_code, geom, extent, level)
}
}

#' Geometry validity
#'
#' - [geos_is_valid()] returns a logical vector denoting if each feature
Expand Down
Loading