Skip to content

Commit

Permalink
Add test for #167
Browse files Browse the repository at this point in the history
  • Loading branch information
ateucher committed Oct 18, 2023
1 parent e1dc87d commit 352b2bb
Show file tree
Hide file tree
Showing 2 changed files with 46 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 @@ -180,3 +180,31 @@
"value": ["{\"type\":\"FeatureCollection\", \"features\": [\n{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[101,2],[102,2],[103,2],[103,3],[101,3],[101,2]]]},\"properties\":null},\n{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[101,2],[101,1],[103,1],[103,2],[102,2],[101,2]]]},\"properties\":null}\n]}"]
}

# ms_simplify works with gj2008 flag

{
"type": "character",
"attributes": {
"class": {
"type": "character",
"attributes": {},
"value": ["geojson", "json"]
}
},
"value": ["{\"type\":\"FeatureCollection\", \"features\": [\n{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[100,0],[110,0],[110,10],[100,10],[100,0]],[[101,1],[101,9],[109,9],[109,1],[101,1]]]},\"properties\":null}\n]}"]
}

---

{
"type": "character",
"attributes": {
"class": {
"type": "character",
"attributes": {},
"value": ["geojson", "json"]
}
},
"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]}"]
}

18 changes: 18 additions & 0 deletions tests/testthat/test-simplify.R
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,21 @@ test_that("ms_simplify works with sf objects containing units", {
expect_s3_class(multipoly_sf_simple, "sf")
expect_type(multipoly_sf_simple$area, "double")
})

test_that("gj2008 flag reverses winding order as expected", {
# https://github.com/ateucher/rmapshaper/issues/167
poly_with_hole <- 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(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")
})

0 comments on commit 352b2bb

Please sign in to comment.