Skip to content

Commit

Permalink
Add support for GFT.ProjJSON. (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
evetion authored Jan 8, 2025
1 parent 96ec0ac commit 291a04f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/spatialref.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
56 changes: 56 additions & 0 deletions test/test_spatialref.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,55 @@ import GeoInterface
</gml:ProjectedCRS>
"""
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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 291a04f

Please sign in to comment.