paleolimbot / wk

Lightweight Well-Known Geometry Parsing

Home Page:https://paleolimbot.github.io/wk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sfc_writer drops CRS

JosiahParry opened this issue · comments

I likely do not completely understand how wk works so this may be a non-issue.

The intent is to be able to parse a wkt string using wk and then cast it to an sfc object using wk as well. wk will successfully keep the CRS but when writing to sfc object it gets dropped.

nc <- sf::st_read(system.file("shapes/sids.shp", package="spData")[1], quiet=TRUE)
sf::st_crs(nc) <- "+proj=longlat +datum=NAD27"

wkt <- nc$geometry |> 
  sf::st_as_text()

wkt_parsed <- wk::parse_wkt(
  wkt,
  sf::st_crs(nc)
)

wk::wk_handle(wkt_parsed, wk::sfc_writer())
#> Geometry set for 100 features 
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> CRS:           NA
#> First 5 geometries:
#> MULTIPOLYGON (((-81.47276 36.23436, -81.54084 3...
#> MULTIPOLYGON (((-81.23989 36.36536, -81.24069 3...
#> MULTIPOLYGON (((-80.45634 36.24256, -80.47639 3...
#> MULTIPOLYGON (((-76.00897 36.3196, -76.01735 36...
#> MULTIPOLYGON (((-77.21767 36.24098, -77.23461 3...

Created on 2022-11-02 by the reprex package (v2.0.1)

Yes, the sfc_writer() drops the CRS (because you could also do it to transform coordinate values, in which case the CRS wouldn't make much sense).

I think what you probably want is st_as_sfc(parse_wkt(wkt, sf::st_crs(nc))?