GeoInterface.jl icon indicating copy to clipboard operation
GeoInterface.jl copied to clipboard

add `coordtype`

Open rafaqz opened this issue 1 year ago • 3 comments

Closes #128

Currently on a GI.MultiPolygon this takes 4ns. Its not a compile time operation. We could put this in the type parameters of the wrapper geometries at construction so its instant.

A lot of packages will be able to set this absolutely to a single type, e.g. Shapefile.jl, GeoJSON.jl and LibGEOS.jl can return Float64.

rafaqz avatar Sep 25 '24 23:09 rafaqz

GeoInterface implementations:

We have recently added a coordtype::Type{<: Number} function to the GeoInterface API. This needs to be implemented in all the GeoInterface packages and made fast so other people can use it.

Packages to update

  • [ ] yeesian/ArchGDAL.jl (always Float64)
  • [ ] JuliaGeo/LibGEOS.jl (always Float64)
  • [ ] JuliaGeo/GeoParquet.jl
  • [ ] JuliaGeo/GeoArrow.jl
  • [ ] JuliaGeo/GeoJSON.jl (always Float64)
  • [ ] JuliaGeo/Shapefile.jl (can have f32 or f64)
  • [ ] evetion/FlatGeobuf.jl
  • [ ] evetion/WellKnownGeometry.jl (at least for well known binary, probably also for text if we parse to float64)
  • [ ] JuliaGeo/GeometryBasics.jl (encoded in eltype)

The way you implement this is that you define the two-argument coordtype(trait, obj) function. You should do this specifically for at least FeatureTrait, FeatureCollectionTrait (if such objects exist in the package) and AbstractGeometryTrait.

GeoInterface.coordtype(::GeoInterface.FeatureCollectionTrait, featurecollection::YourAbstractFeatureCollection) = ...
GeoInterface.coordtype(::GeoInterface.FeatureTrait, feature::YourAbstractFeature) = ...
GeoInterface.coordtype(::GeoInterface.AbstractGeometryTrait, geom::YourAbstractGeometrySupertype) = ...

Only implement the feature and feature collection trait methods if those are types in the repo. For example, WellKnownGeometry, LibGEOS and GeometryBasics have no feature collection or feature types.

Clone each repo and make the change, then make a PR. For some you may have to fork.

asinghvi17 avatar Sep 26 '24 04:09 asinghvi17

I'm fine with this, but might be good to give a concrete example of what this improves. Do we also want to give some hints using coordtype for let's say GI.coordinates? That's the most type unstable thing I can think of in here.

evetion avatar Sep 28 '24 17:09 evetion

Yeah, we could use it for coordinates in some cases

(Answered the rest in the issue thread)

rafaqz avatar Sep 28 '24 17:09 rafaqz

https://gdal.org/en/stable/doxygen/classOGRPoint.html#a5170ea70ce7458059e4395f852fce687 indicates that ArchGDAL must also set this to Float64, so it's just Julia types that need to have the type statically encoded somehow.

asinghvi17 avatar Jan 13 '25 12:01 asinghvi17

bump @evetion @visr - can we get this in? I do have quite a few uses for it in GeometryOps now...

asinghvi17 avatar May 09 '25 22:05 asinghvi17

bump @evetion @visr - can we get this in? I do have quite a few uses for it in GeometryOps now...

Let's get it in.

evetion avatar Sep 09 '25 07:09 evetion

Is there anything required or can we just merge?

rafaqz avatar Sep 10 '25 01:09 rafaqz

Merged. Id like to wait for extent computation and then get a minor release out.

asinghvi17 avatar Sep 10 '25 05:09 asinghvi17