Skip to content

Conversation

@rafaqz
Copy link
Member

@rafaqz rafaqz commented Sep 25, 2024

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 rafaqz changed the title add coordtype add coordtype Sep 25, 2024
Comment on lines +321 to +323
coordtype(::Point{<:Any,<:Any,<:AbstractArray{T}}) where T = T
coordtype(::Point{<:Any,<:Any,<:NTuple{<:Any,T}}) where T = T
coordtype(::Point{<:Any,<:Any,<:NamedTuple{<:Any,<:NTuple{<:Any,T}}}) where T = T
Copy link
Member

Choose a reason for hiding this comment

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

Should we remove the Point from here, so that the dispatch with parent(p) for Point feeds into these?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that will hit the fallback method in fallbacks.jl. It just get the X coord type

Copy link
Member

Choose a reason for hiding this comment

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

should we also add some @test_inferred? Or is it too early for that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good idea

@asinghvi17
Copy link
Member

asinghvi17 commented Sep 26, 2024

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.

@rafaqz rafaqz requested review from evetion and visr September 28, 2024 16:56
@evetion
Copy link
Member

evetion commented Sep 28, 2024

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.

@rafaqz
Copy link
Member Author

rafaqz commented Sep 28, 2024

Yeah, we could use it for coordinates in some cases

(Answered the rest in the issue thread)

@kylebarron kylebarron mentioned this pull request Oct 17, 2024
2 tasks
@asinghvi17
Copy link
Member

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
Copy link
Member

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

@evetion
Copy link
Member

evetion commented Sep 9, 2025

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.

@asinghvi17 asinghvi17 moved this to In progress in SDSL 25 planning Sep 9, 2025
@rafaqz
Copy link
Member Author

rafaqz commented Sep 10, 2025

Is there anything required or can we just merge?

@asinghvi17 asinghvi17 merged commit 1844202 into main Sep 10, 2025
5 of 7 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in SDSL 25 planning Sep 10, 2025
@asinghvi17
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add a coordtype method

4 participants