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

Reference geos_unnest() in geos_make_collection() man page #68

Closed
JosiahParry opened this issue Jun 17, 2022 · 1 comment · Fixed by #70
Closed

Reference geos_unnest() in geos_make_collection() man page #68

JosiahParry opened this issue Jun 17, 2022 · 1 comment · Fixed by #70

Comments

@JosiahParry
Copy link

Request: Please reference geos_unnest() in the man page for geos_make_collection()—perhaps under the details.

Context: After creating a geometry collection using geos::geos_make_collection() I found myself casting to an sf object to use sf::st_collection_extract(). After digging through the package documentation I finally found geos_unnest().

nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"))
#> Reading layer `nc' from data source 
#>   `/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/sf/shape/nc.shp' 
#>   using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS:  NAD27

geo <- sf::st_centroid(nc) |> 
  sf::st_geometry()
#> Warning in st_centroid.sf(nc): st_centroid assumes attributes are constant over
#> geometries of x

tris <- geo |> 
  geos::geos_make_collection() |> 
  geos::geos_delaunay_triangles()

# this is what i was doing 
sf::st_collection_extract(sf::st_as_sf(tris))
#> Simple feature collection with 186 features and 0 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -84.05986 ymin: 34.07671 xmax: -75.8095 ymax: 36.49111
#> Geodetic CRS:  NAD27
#> First 10 features:
#>                          geometry
#> 1  POLYGON ((-84.05986 35.1311...
#> 2  POLYGON ((-83.82962 35.3450...
#> 3  POLYGON ((-83.82962 35.3450...
#> 4  POLYGON ((-83.82962 35.3450...
#> 5  POLYGON ((-82.70541 35.8532...
#> 6  POLYGON ((-82.70541 35.8532...
#> 7  POLYGON ((-82.70541 35.8532...
#> 8  POLYGON ((-82.70541 35.8532...
#> 9  POLYGON ((-82.70541 35.8532...
#> 10 POLYGON ((-81.49823 36.4314...

# this is what i would've preferred (and now do)
geos::geos_unnest(tris) |> 
  head()
#> <geos_geometry[6] with CRS=NAD27>
#> [1] <POLYGON ((-84.05986 35.13111, -83.74725 35.05384, -83.82962 35.34507, -84.05986 35.13111))>
#> [2] <POLYGON ((-83.82962 35.34507, -83.74725 35.05384, -83.42226 35.14516, -83.82962 35.34507))>
#> [3] <POLYGON ((-83.82962 35.34507, -83.42226 35.14516, -83.48992 35.48069, -83.82962 35.34507))>
#> [4] <POLYGON ((-83.82962 35.34507, -83.48992 35.48069, -82.70541 35.85323, -83.82962 35.34507))>
#> [5] <POLYGON ((-82.70541 35.85323, -83.48992 35.48069, -82.98086 35.55136, -82.70541 35.85323))>
#> [6] <POLYGON ((-82.70541 35.85323, -82.98086 35.55136, -82.52831 35.60684, -82.70541 35.85323))>

Created on 2022-06-17 by the reprex package (v2.0.1)

@paleolimbot
Copy link
Owner

Good catch! See also wk::wk_flatten() and wk::wk_collection(), too, which work on a wider variety of objects (e.g., sf, sfc, geos).

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

Successfully merging a pull request may close this issue.

2 participants