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

Implement the AbstractTrees interface #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

asinghvi17
Copy link

@asinghvi17 asinghvi17 commented Oct 25, 2024

This is currently in an extension, but we could also move it into the package proper. AbstractTrees is a zero-dependency, super lightweight package.

The code here simply implements the AbstractTrees.jl interface for STRtree, STRNode, and STRLeafNode. This allows you to use AbstractTrees iterators on STRtree structures without any fuss, like AbstractTrees.Leaves, AbstractTrees.PreOrderDFS, etc.

I personally use this to extract all tiles below a certain size (or leaf nodes), and then extract the indices they contain. Such nodes might be close to or far away from the root node.

Some example code:

"""
    extract_idxs(node)

Extract the indices of the geometries that an `STRNode` covers.

Returns a vector of integers that are indices of the geometries that made the tree.
"""
function extract_idxs(node::Union{STRtree, STRNode, STRLeafNode})::Vector{Int}
    return mapreduce(Base.Fix2(getproperty, :indices), vcat, AbstractTrees.Leaves(node))
end

@maxfreu
Copy link
Owner

maxfreu commented Oct 29, 2024

Hey! I currently don't have the time to give things an in-depth look. As AbstractTrees looks pretty generic I suggest to include it in the package properly, not as extension. If you want, I invite you to co-maintain the STRTree package - then you can merge it yourself ;-)

@maxfreu
Copy link
Owner

maxfreu commented Oct 29, 2024

Oh and tests would be cool, as always.

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

Successfully merging this pull request may close these issues.

2 participants