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

Please remove dependencies on **rgdal**, **rgeos**, and/or **maptools** #833

Closed
rsbivand opened this issue Dec 15, 2022 · 7 comments
Closed
Assignees

Comments

@rsbivand
Copy link

rsbivand commented Dec 15, 2022

This package depends on (depends, imports or suggests) raster and one or more of the retiring packages rgdal, rgeos or maptools (https://r-spatial.org/r/2022/04/12/evolution.html, https://r-spatial.org/r/2022/12/14/evolution2.html). Since raster 3.6.3, all use of external FOSS library functionality has been transferred to terra, making the retiring packages very likely redundant. It would help greatly if you could remove dependencies on the retiring packages as soon as possible.

My guess is that dropping rgdal and rgeos and replacing them by terra, conditioning raster on >= 3.6.3 will resolve this (untried). You use rgeos::createPolygonsComment, but should be able to work around that with either sf or terra.

@jcheng5
Copy link
Member

jcheng5 commented Dec 16, 2022

Thanks @rsbivand. With regard to rgeos::createPolygonsComment, it looks to me like we use this for sp Polygons objects whenever they're missing comment data indicating, for each hole, what non-hole they belong to.

createPolygonsComment attempts to create a valid comment for a Polygons object by assessing which polygons contain a given hole (using gContains). Ownership is assigned to the smallest polygon (by area) that contains the given hole.

Is there some higher-level functionality in sf or terra that we can use for this, or were you imagining a reimplementation using just st_contains and st_area?

@rsbivand
Copy link
Author

rsbivand commented Dec 16, 2022

I'll create a reprex in r-spatial/evolution#9 and explore. It should no longer be a big problem, if for example ESRI Shapefiles are read through the GDAL driver where GDAL was built linking to GEOS, the driver itself restores Simple Features specs even via rgdal::readOGR(). It was a problem before about 2010, and still would be for serialised Polygons objects pre-dating those changes, and for other manually created objects.

@jcheng5
Copy link
Member

jcheng5 commented Dec 16, 2022

2010! Wow...

What if we detect Polygons with 1) missing comment, 2) holes, 3) more than one island, and throw a warning (or even error)? Technically breaking backward compatibility I suppose, but this seems like such an extreme edge case.

@rsbivand
Copy link
Author

Right, an edge case, but if r-spatial/sf#2063 can lead to coercion to a conformant sfg, or a list of sfg's (sfc), then back to a Simple-Features conformant Polygons or SpatialPolygons object, it might make sense to do that. Other than leaflet, occTest uses rgeos::createPolygonsComment(), and ggOceanMaps uses rgeos::createSPComment(), calling rgeos::createPolygonsComment() internally.

@jcheng5
Copy link
Member

jcheng5 commented Dec 16, 2022

OK, that’d be great. In the meantime I can get the rest of the PR ready. Thank you.

@jcheng5
Copy link
Member

jcheng5 commented Mar 1, 2023

Fixed in #837. Thanks @rsbivand for all of your help.

@schloerke, the main branch now contains a VERY slight/obscure regression that will go away when the next version of {sf} goes to CRAN. If you give leaflet {sp} objects that contain holes but not hole ownership information, you'll get an error that we're missing hole information and need {sf} version 1.0-10 or above. {sp} doesn't create such objects anymore, but it's conceivable that an old object could've been persisted to an .rds.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jun 6, 2023
# version 1.0-13

* `gdal_utils()` adds `"ogrinfo"` utility (requires GDAL >= 3.7.0); #2160

* `st_as_sf()` catches errors when setting invalid crs values, raised by Jon Skøien

* add `rename_with.sf()` method; #1472

* use GEOS' overlayNG routines for (GEOS) Intersection, Difference,
  Union and SymDifference; #2143

* added `duplicated.sf()`; #2138, #2140, thanks to @bart1

* `select.sf()` allows selecting the same column twice under different names; #1886

* `st_as_sf.ppplist()` is deprecated; #1926

* `st_cast()` handles empty geometries; #1961

* don't repeat longlat messages in `summarise.sf()`; #1519

* fix random sampling on the sphere; #2133

# version 1.0-12

* update NAMESPACE to `useDynLib(sf, .registration=TRUE)`; #2127 thanks to @eddelbuettel

* fix call in `gdal_addo()`; #2124

* fix issues that came up with older GDAL version, use `GDAL_VERSION_NUM` consistently; #2123 #2121 #2119

# version 1.0-11

* `st_make_grid()` also accepts area units for `cellsize`, for square and hexagonal grids; #1505

* add `st_concave_hull()`, for concave hulls, if GEOS >= 3.11.0; #1964

* add `st_triangulate_constrained()`, for constrained Delaunay triangulation, if GEOS >= 3.10.0; #1964

* clean up the retrieval of length or angle units from WKT
  representations;
  https://lists.osgeo.org/pipermail/gdal-dev/2023-March/056994.html

* conversion to GEOS uses the `GEOS_PREC_VALID_OUTPUT` flag, which
  makes sure that the "[o]utput is always valid. Collapsed geometry
  elements (including both polygons and lines) are removed."

# version 1.0-10

* `gdal_utils()` has a `config_options` argument to set further GDAL
  options, just like `st_write()`; #2003

* fix slow writing of logical vectors in `st_write()`; #1409; #1689

* `st_drivers()` has an argument `regex` to filter on driver (long) name; #2090

* drop C++11 as a system requirement

* `c.sfc()` (and, consequently, `dplyr::bind_rows()`) gives an error
  if components have different CRS; #1884

* data imported from `maps` are associated with the Clark 1866 ellipsoid; #2080

* fix importing legacy `SpatialPolygon` objects without comments;
  #2063, #2069, rstudio/leaflet#833

* `st_read()` no longer errors on mixes of `XY` and `XYZ` geometries; #2046 #1592

* in `plot.sf()`, when numeric `breaks` are given a legend key is always plotted; #2065

* `st_crs()$axes` returns a `data.frame` with axes properties (name,
  orientation, conversion factor) when GDAL >= 3.0.0

* clean up unit handling for geometry measures (length, area, distance) and crs;

* `st_crs(x)$ud_unit` returns `NULL` if units are unknown; #2049

* `st_write()` substitutes an `NA` crs with `ENGCRS["Undefined
  Cartesian SRS with unknown unit"]`; #2049, #2054

* `st_can_transform()` checks whether a transformation between two crs
  exists; see dieghernan/tidyterra#64; #2049

* the matrix returned by `st_coordinates()` has no row names, to reduce output size

# version 1.0-9

* adjust for changes how R-devel handles `POSIXlt`; #2028

* add `st_break_antimeridian()`; #1983, #1991 by Roger Bivand

* add `Fibonacci` as a spatial sampling type in `st_sample()`

* use the global `options("sf_use_s2")` to determine whether to use
  s2, rather than a value in a local environment; #1977

* fix utils `mdiminfo` and `mdimtranslate` in `gdal_utils()`

* extend arguments of `gdal_read_mdim()` needed by
  `stars::read_mdim()` if `stars` >= 0.5-7; add `gdal_write_mdim()`

* add `drop_na()` method for `sf` objects; #1975

# version 1.0-8

* `st_drop_geometry.default()` returns `x` unmodified;

* `sf_project()` accepts 3- or 4-column matrices, containing z and t values;

* optimizations for `st_sfc()` by @paleolimbot; #1938, #1925

* `[<-.sfc()` recomputes the bounding box; `st_sfc()` gets parameter `compute_bbox`; #1965

* add new algorithm and drop option to `st_make_valid()` when using GEOS and GEOS >= 3.10.1; #1655

* add `st_minimum_rotated_rectangle()`, available when GEOS >= 3.9.0; #1953

* fix `st_sample()` with `type = "hexagonal"` for corner case (n=1),
  add a `progress` argument for a progress bar; #1945

* add package `pbapply` to Suggests; #1945

* add pdf driver to windows build; #1942

* clarify `pipeline` argument in `st_transform()` when axis order is ambiguous; #1934

* handle argument `xpd` in calls to `plot.sfc_POLYGON()` and `plot.sfc_MULTIPOLYGON()`

* add `pivot_wider()` method, by Henning Teickner; #1915

* add `gdal_addo()` to add or remove overviews from raster images; #1921

* `st_layers()` returns `crs` of each layer in a `crs` list of `crs` objects

* restore `st_graticule()` behaviour to pre-sf 1.0-0;
  tidyverse/ggplot2#4571

* `gdal_metadata()` sets metadata item names properly

* `st_read()` gains an argument `optional` passed on to
  `as.data.frame` to avoid changing column names; #1916

* GPX files are autodetected by `st_read()`; #1917

* unnecessary coordinate names are not returned in `st_sample()`,
  making the output size smaller; #1879

# version 1.0-7

* `st_drop_geometry()` is a generic; #1914

* `st_crs(x)$ud_unit` returns the unit of the coordinate reference system of `x`

* geometric predicates return `sgbp` objects omitting
  self-intersections etc. by passing `remove_self = TRUE` and unique
  symmetric relationship by passing `retain_unique = TRUE` (to `...`
  if needed); this simplifies identifying (and removing) duplicated
  geometries; duplicates are identified by e.g. by `st_equals(x,
  retain_unique = TRUE) |> unlist() |> unique()`; #1893

* fix compile issue against GDAL < 2.5.0 introduced in 1.0-6; #1899

# version 1.0-6

* adapt to new `spatstat.random` package; #1892

* `st_geometry<-()` also allows to rename a geometry column in an `sf` object; #1890

* for `sf` objects, the `st_as_sfc()` method is an alias for `st_geometry()`; #1882

* `st_make_grid()` speeded up; #1579 thanks to Krzysztof Dyba

* remove direct and indirect dependencies on `rgeos` and `rgdal`; #1869

* use `stats::dist` rather than GEOS for symmetric point-point Euclidian distance computation; #1874

# version 1.0-5

* package startup message reports status of `sf_use_s2()`; #1782

* `sf_use_s2()` uses `message()` to report a change; #1782

* `st_sample()` using regular sampling for ellipsoidal coordinates
  "works" as if coordinates were Cartesian; #1837

# version 1.0-4

* new function `st_delete()` deletes a data source, or layer(s) within
  a data source; #1828

* fix memory leak in `WKT1_ESRI` retrieval; #1690

# version 1.0-3

* cope with how GEOS >= 3.10.0 handles illegal geometries (e.g., non-closed rings); #1807

* `crs` objects have a `$srid` method to extract the SRID (as authority "name:code"); #1804

* `st_as_grob()` methods for `sfc_*` objects correctly handle empty
  geometries; #1789 with help from Hiroaki Yutani

* when writing objects with `NA` as CRS to GeoPackage, assign "Unknown
  Cartesian CRS" first - this is in line with using Cartesian geometry
  operations for objects with `NA` as CRS; #1776

* add coerce method from `sgbp` to `sparseMatrix`; #1750

* fix `st_cast()` for `GEOMETRYCOLLECTIONS` containing empty geometries; #1767

* fix `st_is_valid()` for bogus polygons and projected coordinates; #1666, #1760; #1761
@cpsievert
Copy link
Contributor

Seems this can be closed (the leaflet changes for this are now on main)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants