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

allow MixedFormat in CRS #97

Merged
merged 4 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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/crs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
return CRS(crs)
end

function CRS(crs::GFT.CoordinateReferenceSystemFormat, ctx::Ptr{PJ_CONTEXT} = C_NULL)
const MaybeGFTCRS = Union{GFT.CRS,GFT.Unknown,GFT.Extended}

function CRS(
crs::Union{GFT.CoordinateReferenceSystemFormat,GFT.MixedFormat{<:MaybeGFTCRS}},
ctx::Ptr{PJ_CONTEXT} = C_NULL
)
crs = proj_create(convert(String, crs), ctx)
return CRS(crs)
end
Expand Down Expand Up @@ -134,6 +139,8 @@

Base.convert(T::Type{<:GFT.CoordinateReferenceSystemFormat}, crs::CRS) = T(crs)
Base.convert(::Type{CRS}, crs::GFT.CoordinateReferenceSystemFormat) = CRS(crs)
Base.convert(T::Type{<:GFT.MixedFormat}, crs::CRS) = T(crs)
Base.convert(::Type{CRS}, crs::GFT.MixedFormat{<:MaybeGFTCRS}) = CRS(crs)

Check warning on line 143 in src/crs.jl

View check run for this annotation

Codecov / codecov/patch

src/crs.jl#L143

Added line #L143 was not covered by tests

# Maybe enable later, based on https://github.com/JuliaGeo/GeoFormatTypes.jl/issues/21
# Base.convert(T::Type{<:GFT.CoordinateReferenceSystemFormat}, crs::GFT.CoordinateReferenceSystemFormat) = T(CRS(crs))
Expand Down
8 changes: 8 additions & 0 deletions test/libproj.jl
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,19 @@ end
@test GFT.EPSG(crs) == GFT.EPSG("EPSG:4326")

@test convert(GFT.EPSG, crs) == GFT.EPSG("EPSG:4326")
@test convert(GFT.WellKnownText2, crs) == GFT.WellKnownText2(crs)
@test Proj.proj_get_id_code(convert(Proj.CRS, GFT.EPSG("EPSG:4326"))) ==
Proj.proj_get_id_code(crs)

# Maybe enable later, based on https://github.com/JuliaGeo/GeoFormatTypes.jl/issues/21
# @test convert(GFT.ProjString, gftcrs) == GFT.ProjString("+proj=longlat +datum=WGS84 +no_defs +type=crs")

# Check that we can round trip CRS/wkt without errors
@test GFT.EPSG(Proj.CRS(GFT.WellKnownText(crs))) ==
GFT.EPSG(Proj.CRS(GFT.WellKnownText2(crs)))

# This runs but we lose the EPSG number for testing
Proj.CRS(GFT.ESRIWellKnownText(crs))
end

@testset "Geodesics" begin
Expand Down