-
Notifications
You must be signed in to change notification settings - Fork 0
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
Make EPSG
a subset of some AgencyCode
abstract type
#35
Comments
One problem is printing will be ugly Can we just add OGC ? |
You mean as another type? Sure, but we would have to implement all the converts in ArchGDAL too. An abstract supertype seems easier to extend, but the risk of typos also increases. In terms of printing I think it should just print the alias? |
Sorry guess I don't totally get your example, your EPSG is not concrete... |
Ah, I guess the struct AuthorityCRS{Authority, N} <: GFT.CoordinateReferenceSystemFormat
val::NTuple{N,Int}
function AuthorityCRS{Authority, N}(input::NTuple{N, Integer}) where {Authority, N}
@assert Authority isa Symbol
# maybe @assert Authority in (:EPSG, :OGC, :ESRI)
return new{Authority, N}(input)
end
end
AuthorityCRS{Authority}(input::NTuple{N,Integer}) where {Authority, N} = AuthorityCRS{Authority, N}(convert(NTuple{N,Int}, input))
AuthorityCRS{Authority}(input::Vararg{Integer}) where {Authority} = AuthorityCRS{Authority}(input)
AuthorityCRS(input::Vararg{Integer}) = AuthorityCRS{:EPSG}(input) # assume EPSG as the default
AuthorityCRS(authority::Symbol, input::NTuple{N,Integer}) where {N} = AuthorityCRS{authority, N}(convert(NTuple{N,Int}, input))
function AuthorityCRS{Authority}(input::AbstractString) where Authority
startswith(input, String(Authority)) || throw(ArgumentError("String $(input) does not start with $(Authority)"))
code = Tuple(parse.(Int, split(input[findlast(String(Authority), input).stop+2:end], "+")))
AuthorityCRS{Authority}(code)
end
const EPSG{N} = AuthorityCRS{:EPSG, N}
const OGC{N} = AuthorityCRS{:OGC, N}
const ESRI{N} = AuthorityCRS{:ESRI, N} With these definitions, julia> EPSG(4326)
EPSG{1}((4326,))
julia> GFT.EPSG(4326)
GeoFormatTypes.EPSG{1}((4326,)) which is basically the same to me, just a bit more flexible maybe. Dispatch also works since the types are separated by a parameter. |
Just edited that comment - this now has functionality fully equivalent to |
I still prefer |
I'll check but I think that the alias should work there too. |
Injecting an error() at the last line of the string parsing function, julia> EPSG("EPSG:4321")
ERROR:
Stacktrace:
[1] error()
@ Base ./error.jl:44
[2] (EPSG)(input::String)
@ Main ~/.julia/dev/GeoMakie/examples/specialized/tyler_noninteractive.jl:50
[3] top-level scope
@ REPL[94]:1 and julia> _beer(x::EPSG) = error()
julia> _beer(EPSG(1234))
ERROR:
Stacktrace:
[1] error()
@ Base ./error.jl:44
[2] _beer(x::EPSG{1})
@ Main ~/.julia/dev/GeoMakie/examples/specialized/tyler_noninteractive.jl:54
[3] top-level scope
@ REPL[95]:1 |
Right. But I'm pretty sure there are places the alias fails |
Can we revisit this? I just ran into https://rdrr.io/cran/spData/man/hawaii.html for which there seems to be no way to load the CRS as stated into a GFT type... |
Can we make an abstract type, move all the methods to that, and add the other 2 structs? You can even share constructors on the abstract type |
Motivation:
CRS can be addressed as eg
ESRI:xyz
orOGC:xyz
as well, and such definitions exist online and in datasets. It would be useful to allow supporting arbitrary agencies (maybe with an error for unknown agencies) such that:or something.
The text was updated successfully, but these errors were encountered: