Skip to content

Commit

Permalink
Test gj2008 with sf
Browse files Browse the repository at this point in the history
  • Loading branch information
ateucher committed Oct 19, 2023
1 parent 3a4a0bd commit 8b69405
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/testthat/_snaps/simplify.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,31 @@
"value": ["{\"type\":\"FeatureCollection\", \"features\": [\n{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[100,0],[100,10],[110,10],[110,0],[100,0]],[[101,1],[109,1],[109,9],[101,9],[101,1]]]},\"properties\":null}\n]}"]
}

# gj2008 flag reverses winding order as expected with sf

{
"type": "character",
"attributes": {
"class": {
"type": "character",
"attributes": {},
"value": ["geojson", "json"]
}
},
"value": ["{\"type\":\"Polygon\",\"coordinates\":[[[100.0,0.0],[110.0,0.0],[110.0,10.0],[100.0,10.0],[100.0,0.0]],[[101.0,1.0],[101.0,9.0],[109.0,9.0],[109.0,1.0],[101.0,1.0]]]}"]
}

---

{
"type": "character",
"attributes": {
"class": {
"type": "character",
"attributes": {},
"value": ["geojson", "json"]
}
},
"value": ["{\"type\":\"Polygon\",\"coordinates\":[[[100.0,0.0],[100.0,10.0],[110.0,10.0],[110.0,0.0],[100.0,0.0]],[[101.0,1.0],[109.0,1.0],[109.0,9.0],[101.0,9.0],[101.0,1.0]]]}"]
}

36 changes: 36 additions & 0 deletions tests/testthat/test-simplify.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,39 @@ test_that("gj2008 flag reverses winding order as expected", {
expect_snapshot_value(ms_simplify(poly_with_hole, keep = 1, gj2008 = FALSE), style = "json2")
expect_snapshot_value(ms_simplify(poly_with_hole, keep = 1, gj2008 = TRUE), style = "json2")
})

test_that("gj2008 flag reverses winding order as expected with sf", {
# https://github.com/ateucher/rmapshaper/issues/167
poly_with_hole <- geojsonsf::geojson_sf(
structure('{"type":"FeatureCollection","features":[
{"type":"Feature",
"geometry":{
"type": "Polygon",
"coordinates": [
[[100.0, 0.0], [100.0, 10.0], [110.0, 10.0], [110.0, 0.0], [100.0, 0.0]],
[[101.0, 1.0], [109.0, 1.0], [109.0, 9.0], [101.0, 9.0], [101.0, 1.0]]
]
},
"properties":{}
}]
}', class = c("geojson", "json"))
)
expect_snapshot_value(
geojsonsf::sf_geojson(
ms_simplify(
poly_with_hole,
keep = 1,
gj2008 = FALSE
)
), style = "json2"
)
expect_snapshot_value(
geojsonsf::sf_geojson(
ms_simplify(
poly_with_hole,
keep = 1,
gj2008 = TRUE
)
), style = "json2"
)
})

0 comments on commit 8b69405

Please sign in to comment.