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 an interface for reverse lookups of package geometry types #80

Closed
rafaqz opened this issue Nov 22, 2022 · 5 comments
Closed

Add an interface for reverse lookups of package geometry types #80

rafaqz opened this issue Nov 22, 2022 · 5 comments

Comments

@rafaqz
Copy link
Member

rafaqz commented Nov 22, 2022

I'm running some code over a feature collection where I'm converting GeoJSON objects to GeometryBasics objects.

It's annoying because the collection has a mix of geometry types, so I have to check for each type and find the correct GeometryBasics.jl object to convert to.

If we had a method like GeometryBasics.geomtrait_type(PolygonTrait()) I could use that like

convert(GeometryBasics.geomtrait_type(geomtrait_type(mygeom)), mygeom)

And the code would be generic for all objects GeometryBasics.jl actually implements.

This wouldn't be an interface method, but a package method with a consistent name across all packages so users can find it. A way to make it an actual interface method could be to dispatch on the Symbol name of the package like :

# In GeoInterface.jl
geomtrait_type(mod::Module, trait) = geomtrait_type(Val{nameof(mod)}(), trait)
# In the package
GeoInterface.geomtrait_type(::Val{:GeoJSON}, trait::GeoInterface.PolygonTrait) = Polygon 

but it's a bit of a hack and ignores that package UUIDs allow multiple identical named packages.

It would also be amazing to do:

convert(GeometryBasics, mygeom)
convert(ArchGDAL, mygeom)

And it just works without knowing the package geometry type. This method would be a step in that direction.

@evetion
Copy link
Member

evetion commented Nov 22, 2022

Fully agree, I think I described it somewhere as convert(::Module, geom), although that might not be the best API.

@rafaqz
Copy link
Member Author

rafaqz commented Dec 7, 2022

Do you think that in practice we can ignore that multiple packages can have the same name and dispatch on ::Val{:ModuleName}? It's pretty unlikely there will be two of any package name, but still not strictly correct.

@evetion
Copy link
Member

evetion commented Dec 8, 2022

I'd say yeah, let's ignore it, although it would be good to check what kind of error you would get if it happens (creating a clone package locally or similar). Probably just overwrites the method definition?

@rafaqz
Copy link
Member Author

rafaqz commented Dec 8, 2022

I think whatever package is loaded last will override the method.

@rafaqz
Copy link
Member Author

rafaqz commented Oct 4, 2023

implemented

@rafaqz rafaqz closed this as completed Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants