From 291a04f3a4e76b0e20565dc8bfba86e00cb4bc25 Mon Sep 17 00:00:00 2001 From: Maarten Pronk Date: Wed, 8 Jan 2025 14:23:25 -0100 Subject: [PATCH] Add support for GFT.ProjJSON. (#458) --- src/spatialref.jl | 9 ++++++- test/test_spatialref.jl | 56 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/spatialref.jl b/src/spatialref.jl index 47028583..923fe7c1 100644 --- a/src/spatialref.jl +++ b/src/spatialref.jl @@ -61,11 +61,18 @@ function importCRS!(spref::T, x::GFT.GML)::T where {T<:AbstractSpatialRef} return spref end -function importCRS!(spref::T, x::GFT.KML)::T where {T<:AbstractSpatialRef} +function importCRS!(spref::T, ::GFT.KML)::T where {T<:AbstractSpatialRef} importCRS!(spref, GFT.EPSG(4326)) return spref end +function importCRS!(spref::T, x::GFT.ProjJSON) where {T<:AbstractSpatialRef} + json = GFT.val(x) + isa(json, Dict) && error("ProjJSON must be provided as a String.") + importUserInput!(spref, json) + return spref +end + """ reproject(points, sourceproj::GeoFormat, destproj::GeoFormat; [order=:compliant]) diff --git a/test/test_spatialref.jl b/test/test_spatialref.jl index 35b21569..1c72b4d7 100644 --- a/test/test_spatialref.jl +++ b/test/test_spatialref.jl @@ -179,6 +179,55 @@ import GeoInterface """ cepsg = "EPSG:4326+3855" + projjson = """ + { + "\$schema": "https://proj.org/schemas/v0.4/projjson.schema.json", + "type": "GeographicCRS", + "name": "Monte Mario (Rome)", + "datum": { + "type": "GeodeticReferenceFrame", + "name": "Monte Mario (Rome)", + "ellipsoid": { + "name": "International 1924", + "semi_major_axis": 6378388, + "inverse_flattening": 297 + }, + "prime_meridian": { + "name": "Rome", + "longitude": 12.4523333333333 + } + }, + "coordinate_system": { + "subtype": "ellipsoidal", + "axis": [ + { + "name": "Geodetic latitude", + "abbreviation": "Lat", + "direction": "north", + "unit": "degree" + }, + { + "name": "Geodetic longitude", + "abbreviation": "Lon", + "direction": "east", + "unit": "degree" + } + ] + }, + "scope": "Geodesy, onshore minerals management.", + "area": "Italy - onshore and offshore; San Marino, Vatican City State.", + "bbox": { + "south_latitude": 34.76, + "west_longitude": 5.93, + "north_latitude": 47.1, + "east_longitude": 18.99 + }, + "id": { + "authority": "EPSG", + "code": 4806 + } + } + """ @testset "PROJ4 Format" begin AG.importPROJ4(proj4326) do spatialref @@ -271,6 +320,13 @@ import GeoInterface AG.toWKT(AG.importXML(xml4326)) @test AG.toWKT(AG.importCRS(GFT.KML(""))) == AG.toWKT(AG.importEPSG(4326)) + + # WKT is never fully identical + @test occursin("Monte Mario (Rome)", AG.toWKT(AG.importCRS(GFT.ProjJSON(projjson)))) + @test_throws ErrorException AG.importCRS( + GFT.ProjJSON(Dict("type"=>"")) + ) + @test_throws ArgumentError AG.importCRS( GFT.EPSG(4326), order = :unknown,