Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for GFT.ProjJSON. #458

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading