Skip to content

Commit

Permalink
Merge pull request #2054 from rsbivand/can_transform
Browse files Browse the repository at this point in the history
WKT2 for NA planar CRS #2049
  • Loading branch information
edzer authored Dec 7, 2022
2 parents 7c7b838 + 22225b0 commit dc383c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 5 additions & 3 deletions R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,11 @@ st_write.sf = function(obj, dsn, layer = NULL, ...,
if (write_geometries <- inherits(obj, "sf")) {
geom = st_geometry(obj)
obj[[attr(obj, "sf_column")]] = NULL
if (driver == "GPKG" && is.na(st_crs(geom))) {
message('writing GPKG: substituting LOCAL_CS["Undefined Cartesian SRS"] for missing CRS')
st_crs(geom) = st_crs("LOCAL_CS[\"Undefined Cartesian SRS\"]")
if (#driver == "GPKG" &&
is.na(st_crs(geom))) {
message(#'writing GPKG: substituting ENGCRS["Undefined Cartesian SRS with unknown unit"] for missing CRS')
'writing: substituting ENGCRS["Undefined Cartesian SRS with unknown unit"] for missing CRS')
st_crs(geom) = st_crs("ENGCRS[\"Undefined Cartesian SRS with unknown unit\",EDATUM[\"Unknown engineering datum\"],CS[Cartesian,2],AXIS[\"X\",unspecified,ORDER[1],LENGTHUNIT[\"unknown\",0]],AXIS[\"Y\",unspecified,ORDER[2],LENGTHUNIT[\"unknown\",0]]]")
}
} else { # create fake geometries:
v = vector("list", nrow(obj))
Expand Down
10 changes: 8 additions & 2 deletions tests/testthat/test_tm.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ test_that("st_read and write handle date and time", {
geometry = structure(st_sfc(st_point(c(1,1)), st_point(c(2,2)))))
shp <- paste0(tempfile(), ".shp")
gpkg <- paste0(tempfile(), ".gpkg")

st_crs(x) = st_crs("ENGCRS[\"Undefined Cartesian SRS with unknown unit\",EDATUM[\"Unknown engineering datum\"],CS[Cartesian,2],AXIS[\"X\",unspecified,ORDER[1],LENGTHUNIT[\"unknown\",0]],AXIS[\"Y\",unspecified,ORDER[2],LENGTHUNIT[\"unknown\",0]]]")

st_write(x[-4], shp[1], quiet = TRUE)
x2 = st_read(shp[1], quiet = TRUE)
expect_equal(x[-4], x2)
expect_equal(x[-4], x2, check.attributes=FALSE)
# WKT2 CRS do not roundtrip for ESRI Shapefile

st_write(x, gpkg, quiet = TRUE)
x2 = st_read(gpkg, quiet = TRUE)
Expand All @@ -23,10 +26,13 @@ test_that("st_read and write handle date and time", {
geometry = structure(st_sfc(st_point(c(1,1)), st_point(c(2,2)))))
shp <- paste0(tempfile(), ".shp")
gpkg <- paste0(tempfile(), ".gpkg")

st_crs(x) = st_crs("ENGCRS[\"Undefined Cartesian SRS with unknown unit\",EDATUM[\"Unknown engineering datum\"],CS[Cartesian,2],AXIS[\"X\",unspecified,ORDER[1],LENGTHUNIT[\"unknown\",0]],AXIS[\"Y\",unspecified,ORDER[2],LENGTHUNIT[\"unknown\",0]]]")

st_write(x[-4], shp[1], quiet = TRUE)
x2 = st_read(shp[1], quiet = TRUE)
expect_equal(x[-4], x2)
expect_equal(x[-4], x2, check.attributes=FALSE)
# WKT2 CRS do not roundtrip for ESRI Shapefile

st_write(x, gpkg, quiet = TRUE)
x2 = st_read(gpkg, quiet = TRUE)
Expand Down

0 comments on commit dc383c4

Please sign in to comment.