|
| 1 | +test_that("get_parquet_crs handles column names with dots and special characters", { |
| 2 | + skip_if_not_installed("sf") |
| 3 | + skip_if_not_installed("duckdb") |
| 4 | + |
| 5 | + # Create a simple sf dataframe with a geometry column containing a dot |
| 6 | + # Use a non-4326 CRS (like 3857) so GDAL explicitly writes the PROJJSON crs property |
| 7 | + df <- data.frame(id = 1L) |
| 8 | + df[["geom.1"]] <- sf::st_sfc(sf::st_point(c(0, 0)), crs = 3857) |
| 9 | + df_sf <- sf::st_sf(df, sf_column_name = "geom.1") |
| 10 | + |
| 11 | + tmp_pq <- tempfile(fileext = ".parquet") |
| 12 | + # Use layer_options to force GDAL to keep the geometry column name |
| 13 | + sf::st_write(df_sf, tmp_pq, driver = "Parquet", layer_options = "GEOMETRY_NAME=geom.1", quiet = TRUE) |
| 14 | + on.exit(unlink(tmp_pq), add = TRUE) |
| 15 | + |
| 16 | + conn <- tryCatch(ddbs_default_conn(), error = function(e) DBI::dbConnect(duckdb::duckdb())) |
| 17 | + on.exit(DBI::dbDisconnect(conn, shutdown = TRUE), add = TRUE) |
| 18 | + |
| 19 | + duckspatial::ddbs_install(conn, extension = "json", quiet = TRUE) |
| 20 | + duckspatial::ddbs_load(conn, extension = "json", quiet = TRUE) |
| 21 | + |
| 22 | + # Call the unexported function |
| 23 | + crs <- duckspatial:::get_parquet_crs(tmp_pq, conn) |
| 24 | + |
| 25 | + expect_false(is.null(crs)) |
| 26 | + expect_equal(crs$epsg, 3857) |
| 27 | +}) |
| 28 | + |
| 29 | +test_that("get_parquet_crs handles column names with spaces", { |
| 30 | + skip_if_not_installed("sf") |
| 31 | + skip_if_not_installed("duckdb") |
| 32 | + |
| 33 | + # Create a simple sf dataframe with a geometry column containing a space |
| 34 | + df <- data.frame(id = 1L) |
| 35 | + df[["my geom"]] <- sf::st_sfc(sf::st_point(c(0, 0)), crs = 3857) |
| 36 | + df_sf <- sf::st_sf(df, sf_column_name = "my geom") |
| 37 | + |
| 38 | + tmp_pq <- tempfile(fileext = ".parquet") |
| 39 | + sf::st_write(df_sf, tmp_pq, driver = "Parquet", layer_options = "GEOMETRY_NAME=my geom", quiet = TRUE) |
| 40 | + on.exit(unlink(tmp_pq), add = TRUE) |
| 41 | + |
| 42 | + conn <- tryCatch(ddbs_default_conn(), error = function(e) DBI::dbConnect(duckdb::duckdb())) |
| 43 | + on.exit(DBI::dbDisconnect(conn, shutdown = TRUE), add = TRUE) |
| 44 | + |
| 45 | + duckspatial::ddbs_install(conn, extension = "json", quiet = TRUE) |
| 46 | + duckspatial::ddbs_load(conn, extension = "json", quiet = TRUE) |
| 47 | + |
| 48 | + crs <- duckspatial:::get_parquet_crs(tmp_pq, conn) |
| 49 | + |
| 50 | + expect_false(is.null(crs)) |
| 51 | + expect_equal(crs$epsg, 3857) |
| 52 | +}) |
0 commit comments