paleolimbot commented on code in PR #475: URL: https://github.com/apache/sedona-db/pull/475#discussion_r2705124200
########## r/sedonadb/tests/testthat/test-crs.R: ########## @@ -0,0 +1,270 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +test_that("sd_parse_crs works for GeoArrow metadata with EPSG", { + meta <- '{"crs": {"id": {"authority": "EPSG", "code": 5070}, "name": "NAD83 / Conus Albers"}}' + expect_snapshot(sedonadb:::sd_parse_crs(meta)) +}) + +test_that("sd_parse_crs works for Engineering CRS (no EPSG ID)", { + # A realistic example of a local engineering CRS that wouldn't have an EPSG code + meta <- '{ + "crs": { + "type": "EngineeringCRS", + "name": "Construction Site Local Grid", + "datum": { + "type": "EngineeringDatum", + "name": "Local Datum" + }, + "coordinate_system": { + "subtype": "Cartesian", + "axis": [ + {"name": "Northing", "abbreviation": "N", "direction": "north", "unit": "metre"}, + {"name": "Easting", "abbreviation": "E", "direction": "east", "unit": "metre"} + ] + } + } + }' + expect_snapshot(sedonadb:::sd_parse_crs(meta)) +}) + +test_that("sd_parse_crs returns NULL if crs field is missing", { + expect_snapshot(sedonadb:::sd_parse_crs('{"something_else": 123}')) + expect_snapshot(sedonadb:::sd_parse_crs('{}')) +}) + +test_that("sd_parse_crs handles invalid JSON gracefully", { + expect_snapshot( + sedonadb:::sd_parse_crs('invalid json'), + error = TRUE + ) +}) + +test_that("sd_parse_crs works with plain strings if that's what's in 'crs'", { + meta <- '{"crs": "EPSG:4326"}' + expect_snapshot(sedonadb:::sd_parse_crs(meta)) +}) + +# Tests for CRS display in print.sedonadb_dataframe Review Comment: Got it! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
