-
Notifications
You must be signed in to change notification settings - Fork 17
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
New (breaking) Traits based release #33
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome interface. Thank you for the effort again.
What is the status of this PR? It would be good to build GeoData.jl polygon operations off this rather than master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thrown off by the [WIP] in the title, but the implementation is great! Sorry for my slowness in reviewing this PR!
I've been reading over this too now I'm using GeoInterface more. It seems like a real improvement, I'm keen to help getting it merged. My comments so far are:
|
src/interface.jl
Outdated
getpolygon(geom, i::Integer) = getpolygon(geomtype(geom), geom, i) | ||
|
||
# Other methods | ||
crs(geom) = missing # or conforming to <:CoordinateReferenceSystemFormat in GeoFormatTypes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crs(geom) = missing # or conforming to <:CoordinateReferenceSystemFormat in GeoFormatTypes | |
crs(geom) = nothing # or conforming to <:CoordinateReferenceSystemFormat in GeoFormatTypes |
README.md
Outdated
There are also optional generic methods that could help or speed up operations: | ||
```julia | ||
GeoInterface.crs(geom)::Union{Missing, GeoFormatTypes.CoordinateReferenceSystemFormat} | ||
GeoInterface.extent(geom) # geomtype -> GeoInterface.Rectangle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extent
needs to be implemented.
Could it hold/be a NamedTuple
? Like extent(obj) = Extent((X=(xmin, xmax), Y=(ymin, ymax)))
etc for how many dimensions there are, using the :X, :Y, :Z, :M
names from the interface.
I find this organisation is easier to use than the xmin, ymin, xmax, ymax
style bbox
usually uses.
(but somehow I missed that its meant to return a Rectangle
. I guess that makes sense in a different way.)
I would like to propose an struct Extent{T<:NamedTuple}
bounds::T
end
Extent(; kw...) = Extent(values(kw))
Base.getproperty(ext::Extent, x::Symbol) = getproperty(getfield(ext, :bounds), x)
ext = Extent(X=(0.0, 10.0), Y=(0.0, 10.0))
ext.X Giving it a specific type means we can dispatch on it, and including the dimension names means we know their order in the object. |
Ah yes, I agree that we need some sort of bounds object. I've had issues finding a generic one, hence the default to a @visr Do you remember my magical bbox code that you reviewed and we shelved for it being too complex? I can't seem to find it. edit: Found it here JuliaGeo/GeoInterfaceRFC.jl@527198b#diff-64b0c51af7618fbd8cd973bf88690c8b22c309f9b718e4fdd41b7555769f23fdR25 |
Yeah, a With the |
Better implementation including struct Extent{T<:NamedTuple}
bounds::T
end
Extent(; kw...) = Extent(values(kw))
bounds(ext::Extent) = getfield(ext, :bounds)
Base.getproperty(ext::Extent, x::Symbol) = getproperty(bounds(ext), x)
Base.getindex(ext::Extent, x::Symbol) = getindex(bounds(ext), x)
import Base: ==
function (==)(a::Extent{<:NamedTuple{K1}}, b::Extent{<:NamedTuple{K2}}) where {K1, K2}
length(K1) == length(K2) || return false
all(map(k -> k in K1, K2)) || return false
return all(map((k -> a[k] == b[k]), K1))
end And the order doesn't matter for julia> Extent(X=(0, 1), Y=(3.0, 4.0)) == Extent(Y=(3.0, 4.0), X=(0, 1))
true
julia> @btime Extent(X=(0, 1), Y=(3.0, 4.0)) == Extent(Y=(3.0, 4.0), X=(0, 1))
4.004 ns (0 allocations: 0 bytes)
true |
Cautionary tale against using |
Thanks, that's good to know when updating this PR. |
Some updates:
Will now use Extents.jl once registered.
Done TODO
And
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking pretty solid to me. I probably have to see it in PRs to give more extensive feedback.
Co-authored-by: Rafael Schouten <rafaelschouten@gmail.com>
I just hit a const default_coord_names = (:X, :Y, :Z, :M)
x(::AbstractPointTrait, geom) = getcoord(geom, findfirst(coordnames(geom), :X))
y(::AbstractPointTrait, geom) = getcoord(geom, findfirst(coordnames(geom), :Y))
z(::AbstractPointTrait, geom) = getcoord(geom, findfirst(coordnames(geom), :Z))
m(::AbstractPointTrait, geom) = getcoord(geom, findfirst(coordnames(geom), :M)) And |
My bad, I've fixed it and added a test for it. Will add some more tests on the defaults, and enable coverage to prevent this. |
standardise trait arg passing
This fits the header description better, and is the same filename as used for Tables.jl
This makes it more clear what the unused argument is supposed to be.
export the traits
Co-authored-by: Rafael Schouten <rafaelschouten@gmail.com>
some editing of #33
Based on https://github.com/JuliaGeo/GeoInterfaceRFC.jl
primitives.jl
(removed it)getGeometry
andgetGeometries
in geos operations LibGEOS.jl#101 andnumGeometries
in geos operations LibGEOS.jl#96)@visr @yeesian @juliohm