ropensci-archive / wicket

:no_entry: ARCHIVED :no_entry: Utilities to Handle WKT Spatial Data
Other
9 stars 1 forks source link

sp_convert/sf_convert not dealing with holes correctly #27

Closed sckott closed 2 years ago

sckott commented 4 years ago

@mdsumner any thoughts here?

@Ironholds thanks for merging my latest changes. I think though that sp_convert and sf_convert aren't handling holes correctly. Maybe we decided not to deal with that? I can't remember. Anyway, would be nice to handle holes correctly. An example;

devtools::install_github("hypertidy/silicate")
library(sf)
library(sp)
library(silicate)
library(wicket) # need latest

A polygon with a hole: wicket functions make a multipolygon instead of a polygon with a hole.

poly_sf <- st_as_sfc(poly)
poly_sp <- as(poly_sf, "Spatial")
st_as_text(poly_sf)
#> [1] "POLYGON ((0 0, 1 0, 3 2, 2 4, 1 4, 0 0), (1 1, 1 2, 2 2, 1 1))"
sp_convert(poly_sp)
#> [1] "MULTIPOLYGON(((0 0,1 4,2 4,3 2,1 0,0 0)),((1 1,2 2,1 2,1 1)))"
sf_convert(poly_sf)
#> [1] "MULTIPOLYGON(((0 0,1 0,3 2,2 4,1 4,0 0)),((1 1,1 2,2 2,1 1)))"

A multipolygon with holes: wicket functions change the multipolygon holes

mpoly <- sfzoo$multipolygon
mpoly_sp <- as(mpoly, "Spatial")
st_as_text(sfzoo$multipolygon)
#> [1] "MULTIPOLYGON (((0 0, 1 0, 3 2, 2 4, 1 4, 0 0), (1 1, 1 2, 2 2, 1 1)), ((3 0, 4 0, 4 1, 3 1, 3 0), (3.3 0.3, 3.3 0.8, 3.8 0.8, 3.8 0.3, 3.3 0.3)), ((3 3, 4 2, 4 3, 3 3)))"
sp_convert(mpoly_sp)
#> [1] "MULTIPOLYGON(((0 0,1 4,2 4,3 2,1 0,0 0)),((1 1,2 2,1 2,1 1)),((3 0,3 1,4 1,4 0,3 0)),((3.3 0.3,3.8 0.3,3.8 0.8,3.3 0.8,3.3 0.3)),((3 3,4 3,4 2,3 3)))"
sf_convert(mpoly)
#> [1] "MULTIPOLYGON(((0 0,1 0,3 2,2 4,1 4,0 0)),((1 1,1 2,2 2,1 1)),((3 0,4 0,4 1,3 1,3 0)),((3.3 0.3,3.3 0.8,3.8 0.8,3.8 0.3,3.3 0.3)),((3 3,4 2,4 3,3 3)))"
sckott commented 4 years ago

any thoughts on this @Ironholds or @mdsumner ?