Skip to content

Commit

Permalink
allow MixedFormat in CRS (#97)
Browse files Browse the repository at this point in the history
* allow MixedFormat in CRS

* test

* add convert and test

* bump minor version; format; Aqua

---------

Co-authored-by: Martijn Visser <[email protected]>
  • Loading branch information
rafaqz and visr authored Oct 2, 2023
1 parent ee9ccb5 commit 9baac70
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Proj"
uuid = "c94c279d-25a6-4763-9509-64d165bea63e"
version = "1.6.0"
version = "1.7.0"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Expand All @@ -11,6 +11,7 @@ NetworkOptions = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
PROJ_jll = "58948b4f-47e0-5654-a9ad-f609743f8632"

[compat]
Aqua = "0.7"
CEnum = "0.2, 0.3, 0.4"
CoordinateTransformations = "0.6"
GeoFormatTypes = "0.4"
Expand All @@ -19,8 +20,9 @@ PROJ_jll = "900.100, 901"
julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["StaticArrays", "Test"]
test = ["Aqua", "StaticArrays", "Test"]
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 @@ function CRS(crs::AbstractString, ctx::Ptr{PJ_CONTEXT} = C_NULL)
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 @@ end

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)

# 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
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Proj
using Test
using StaticArrays: SA
import Aqua

# Base.isapprox doesn't work on tuples
is_approx(a, b) = all(isapprox(c[1], c[2]) for c in zip(a, b))

@testset "Proj" begin
include("libproj.jl")
include("applications.jl")

Aqua.test_all(Proj; ambiguities = false)
end # testset "Proj"

2 comments on commit 9baac70

@visr
Copy link
Member

@visr visr commented on 9baac70 Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/92640

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.7.0 -m "<description of version>" 9baac703d9f954c8425e0be375433bf181c1905e
git push origin v1.7.0

Please sign in to comment.