yeesian / ArchGDAL.jl

A high level API for GDAL - Geospatial Data Abstraction Library
https://yeesian.github.io/ArchGDAL.jl/stable/
Other
142 stars 26 forks source link

Handle non-bijective data-type conversions more robustly #240

Closed mathieu17g closed 3 years ago

mathieu17g commented 3 years ago

Fixes #232 Assert "default type comes last" for mappings that are not bijective

I have enriched the @convert macro's docstring with some explanations and added a note on "default type comes last"


Before going further, @yeesian could you elaborate on:

asserting "default type comes last" for mappings that are not bijective.

Should we enforce it with something like: 1) enhance the readability of the macro call

@convert(
    OGRFieldType::DataType,
    OFTInteger::(Bool, Int16, Int32, ) # default type comes last
    OFTInteger64::Int64,
)

and assert that all type ids of type 1 and all type ids / subtypes of type 2 are unique?

2) Or is it enough to assert that all type id <-> type id / subtype mappings are unique in args? 3) Or something else?

yeesian commented 3 years ago

I think we don't need to enhance the readability of the macro call, since the current one also works in the reverse direction.

I was thinking more about writing https://github.com/yeesian/ArchGDAL.jl/blob/18578bb0d27b3aa0db707c50dfb097aeb69f8765/src/utils.jl#L60-L75 as a loop as suggested in https://discourse.julialang.org/t/initialising-a-dictionary-with-duplicate-keys/2290/2. That way, the behavior is deterministic rather than relying on the current implementation of Dict (which could change).

yeesian commented 3 years ago

This is great! Thank you so much (as always)!