From 8b69405ebeed411d42598538612eab77e5777433 Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Thu, 19 Oct 2023 12:18:37 -0700 Subject: [PATCH] Test gj2008 with sf --- tests/testthat/_snaps/simplify.md | 28 ++++++++++++++++++++++++ tests/testthat/test-simplify.R | 36 +++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/tests/testthat/_snaps/simplify.md b/tests/testthat/_snaps/simplify.md index aa8faa1..828d861 100644 --- a/tests/testthat/_snaps/simplify.md +++ b/tests/testthat/_snaps/simplify.md @@ -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]]]}"] + } + diff --git a/tests/testthat/test-simplify.R b/tests/testthat/test-simplify.R index 74af576..22d16d3 100644 --- a/tests/testthat/test-simplify.R +++ b/tests/testthat/test-simplify.R @@ -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" + ) +})