From f6e8ab3723299832dc0dee7bcc2de576e2cc93c9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 20:40:21 +0000 Subject: [PATCH 1/4] Initial plan From 564b792821bcf5fab018bcff95aa109fc14ae3f1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 20:46:47 +0000 Subject: [PATCH 2/4] Add st_zm() to sanitize_sf to handle ZM dimensions + tests Co-authored-by: jcheng5 <129551+jcheng5@users.noreply.github.com> --- R/normalize-sf.R | 2 + tests/testthat/test-normalize.R | 74 +++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/R/normalize-sf.R b/R/normalize-sf.R index 40916214a..2dda6d12d 100644 --- a/R/normalize-sf.R +++ b/R/normalize-sf.R @@ -9,6 +9,8 @@ metaData.sf <- function(obj) { sanitize_sf <- function(obj) { sanitized_sf <- sf::st_geometry(obj) attr(sanitized_sf, "names") <- NULL + # Remove Z and M dimensions if present + sanitized_sf <- sf::st_zm(sanitized_sf) sanitized_sf } diff --git a/tests/testthat/test-normalize.R b/tests/testthat/test-normalize.R index ab9c4ac65..3bbb80655 100644 --- a/tests/testthat/test-normalize.R +++ b/tests/testthat/test-normalize.R @@ -146,3 +146,77 @@ test_that("fails if not lat/long columns present", { "Couldn't infer longitude/latitude columns" ) }) + +# ZM dimensions ----------------------------------------------------------- + +test_that("derivePolygons handles sf LINESTRING with Z dimension", { + # Create a LINESTRING with Z dimension + s1 <- sf::st_linestring(matrix(c(0, 1, 0, 1, 5, 6), ncol = 3)) + + # Should work without error + result <- derivePolygons(s1) + verifyPolygonData(result) + + # Check that we get 2D coordinates (lng, lat only) + coords <- result[[1]][[1]][[1]] + expect_named(coords, c("lng", "lat")) + expect_equal(coords$lng, c(0, 1)) + expect_equal(coords$lat, c(0, 1)) +}) + +test_that("derivePolygons handles sf LINESTRING with ZM dimensions", { + # Create a LINESTRING with ZM dimensions + s2 <- sf::st_linestring(matrix(c(0, 1, 0, 1, 5, 6, 2, 3), ncol = 4), dim = "XYZM") + + # Should work without error + result <- derivePolygons(s2) + verifyPolygonData(result) + + # Check that we get 2D coordinates (lng, lat only) + coords <- result[[1]][[1]][[1]] + expect_named(coords, c("lng", "lat")) + expect_equal(coords$lng, c(0, 1)) + expect_equal(coords$lat, c(0, 1)) +}) + +test_that("derivePolygons handles sf object with Z dimension", { + # Create a simple feature collection with Z dimension + s1 <- sf::st_linestring(matrix(c(0, 1, 0, 1, 5, 6), ncol = 3)) + sfc <- sf::st_sfc(s1) + sf_obj <- sf::st_sf(id = 1, geometry = sfc) + + # Should work without error + result <- derivePolygons(sf_obj) + verifyPolygonData(result) + + # Check that we get 2D coordinates (lng, lat only) + coords <- result[[1]][[1]][[1]] + expect_named(coords, c("lng", "lat")) + expect_equal(coords$lng, c(0, 1)) + expect_equal(coords$lat, c(0, 1)) +}) + +test_that("derivePoints handles sf POINT with Z dimension", { + # Create a POINT with Z dimension + p1 <- sf::st_point(c(1, 2, 3)) + + # Should work without error + result <- derivePoints(p1) + expect_named(result, c("lng", "lat")) + expect_equal(result$lng, 1) + expect_equal(result$lat, 2) +}) + +test_that("derivePoints handles sf object with Z dimension", { + # Create a simple feature collection with Z dimension + p1 <- sf::st_point(c(1, 2, 3)) + p2 <- sf::st_point(c(4, 5, 6)) + sfc <- sf::st_sfc(p1, p2) + sf_obj <- sf::st_sf(id = 1:2, geometry = sfc) + + # Should work without error + result <- derivePoints(sf_obj) + expect_named(result, c("lng", "lat")) + expect_equal(result$lng, c(1, 4)) + expect_equal(result$lat, c(2, 5)) +}) From a63347bef9746d6b56bedf63105b65617d5be57c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 20:49:13 +0000 Subject: [PATCH 3/4] Add st_zm() to all sf geometry methods for comprehensive ZM handling Co-authored-by: jcheng5 <129551+jcheng5@users.noreply.github.com> --- R/normalize-sf.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/R/normalize-sf.R b/R/normalize-sf.R index 2dda6d12d..eaf2b93fd 100644 --- a/R/normalize-sf.R +++ b/R/normalize-sf.R @@ -28,6 +28,9 @@ pointData.sfc_POINT <- function(obj) { } check_crs(obj) + + # Remove Z and M dimensions if present + obj <- sf::st_zm(obj) structure( sf_coords(do.call("rbind", obj)), @@ -38,6 +41,9 @@ pointData.sfc_POINT <- function(obj) { #' @export pointData.POINT <- function(obj) { check_crs(obj) + + # Remove Z and M dimensions if present + obj <- sf::st_zm(obj) bbox <- sf_bbox(obj) @@ -81,6 +87,9 @@ polygonData.sf <- function(obj) { #' @export polygonData.sfc <- function(obj) { check_crs(obj) + + # Remove Z and M dimensions if present + obj <- sf::st_zm(obj) structure( to_multipolygon_list(obj), @@ -90,6 +99,9 @@ polygonData.sfc <- function(obj) { #' @export polygonData.sfg <- function(obj) { + # Remove Z and M dimensions if present + obj <- sf::st_zm(obj) + structure( to_multipolygon_list(obj), bbox = sf_bbox(obj) From c76efa09b8339e6c8ca76cedf343316a7cb95b1a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 20:50:28 +0000 Subject: [PATCH 4/4] Add test for sfc with Z dimension to match issue example Co-authored-by: jcheng5 <129551+jcheng5@users.noreply.github.com> --- tests/testthat/test-normalize.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/testthat/test-normalize.R b/tests/testthat/test-normalize.R index 3bbb80655..3b788fd89 100644 --- a/tests/testthat/test-normalize.R +++ b/tests/testthat/test-normalize.R @@ -220,3 +220,19 @@ test_that("derivePoints handles sf object with Z dimension", { expect_equal(result$lng, c(1, 4)) expect_equal(result$lat, c(2, 5)) }) + +test_that("derivePolygons handles sfc with Z dimension", { + # Test with sfc_LINESTRING directly (like in the issue example) + s1 <- sf::st_linestring(matrix(c(0, 1, 0, 1, 5, 6), ncol = 3)) + sfc <- sf::st_sfc(s1) + + # Should work without error + result <- derivePolygons(sfc) + verifyPolygonData(result) + + # Check that we get 2D coordinates (lng, lat only) + coords <- result[[1]][[1]][[1]] + expect_named(coords, c("lng", "lat")) + expect_equal(coords$lng, c(0, 1)) + expect_equal(coords$lat, c(0, 1)) +})