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 prepared geometry wrapper #105

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/GeometryOps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const Edge{T} = Tuple{TuplePoint{T},TuplePoint{T}} where T
include("primitives.jl")
include("utils.jl")

include("preparations/prepared_geometries.jl")
include("preparations/monotone_chain.jl")
include("preparations/sorted_edge_list.jl")
include("preparations/rtree.jl")

include("methods/angles.jl")
include("methods/area.jl")
include("methods/barycentric.jl")
Expand Down
10 changes: 10 additions & 0 deletions src/preparations/monotone_chain.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#=
# Monotone chain

A monotone chain is a continuous list of edges whose slopes are _monotonic_, i.e. all oriented towards the same quadrant.

This speeds up polygon set operations and boolean ops tremendously, since it allows us to skip a lot of the expensive `O(n^2)` operations.

## Example
=#

56 changes: 56 additions & 0 deletions src/preparations/prepared_geometries.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
struct Prepared{Pa,Pr}
parent::Pa
preparations::Pr
end

Base.parent(x::Prepared) = x.parent
@inline getprep(p::Prepared, x::Symbol) = getproperty(p.preparations, x)

GI.trait(p::Prepared) = GI.trait(parent(p))
GI.geomtrait(p::Prepared) = GI.geomtrait(parent(p))

GI.isgeometry(::Type{<:Prepared{T}}) where {T} = GI.isgeometry(T)
GI.isfeature(::Type{<:Prepared{T}}) where {T} = GI.isfeature(T)
GI.isfeaturecollection(::Type{<:Prepared{T}}) where {T} = GI.isfeaturecollection(T)

GI.geometry(x::Prepared) = GI.geometry(parent(x))
GI.properties(x::Prepared) = GI.properties(parent(x))

for f in (:extent, :crs)
@eval GI.$f(t::GI.AbstractTrait, x::Prepared) = GI.$f(t, parent(x))
end
for f in (:coordnames, :is3d, :ismeasured, :isempty, :coordinates, :getgeom)
@eval GI.$f(t::GI.AbstractGeometryTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
end

for f in (:x, :y, :z, :m, :coordinates, :getcoord, :ngeom, :getgeom)
@eval GI.$f(t::GI.AbstractPointTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
end
for f in (:npoint, :getpoint, :startpoint, :endpoint, :npoint, :issimple, :isclosed, :isring)
@eval GI.$f(t::GI.AbstractCurveTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
end
for f in (:nring, :getring, :getexterior, :nhole, :gethole, :npoint, :getpoint, :startpoint, :endpoint)
@eval GI.$f(t::GI.AbstractPolygonTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
end
for f in (:npoint, :getpoint, :issimple)
@eval GI.$f(t::GI.AbstractMultiPointTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
@eval GI.$f(t::GI.AbstractMultiCurveTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
end
for f in (:nring, :getring, :npoint, :getpoint)
@eval GI.$f(t::GI.AbstractMultiPolygonTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
end

getpoint(t::GI.AbstractPolyhedralSurfaceTrait, geom::Prepared) = GI.getpoint(t, parent(geom))
isclosed(t::GI.AbstractMultiCurveTrait, geom::Prepared) = GI.isclosed(t, parent(geom))

for f in (:getfeature, :coordinates)
@eval GI.$f(t::GI.AbstractFeatureTrait, geom::Prepared, args...) = $f(t, parent(geom), args...)
end

# Ambiguity
for T in (:LineTrait, :TriangleTrait, :PentagonTrait, :HexagonTrait, :RectangleTrait, :QuadTrait)
@eval GI.npoint(t::GI.$T, geom::Prepared) = GI.npoint(t, parent(geom))
end
for T in (:RectangleTrait, :QuadTrait, :PentagonTrait, :HexagonTrait, :TriangleTrait)
@eval GI.nring(t::GI.$T, geom::Prepared) = GI.nring(t, parent(geom))
end
7 changes: 7 additions & 0 deletions src/preparations/rtree.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#=
# RTree/STRtree

An interface for any arbitrary RTree/STRtree. This should allow reconstruction from SQL like databases.

Applicable to geometrycollections, multi geometries, and feature collections.
=#
7 changes: 7 additions & 0 deletions src/preparations/sorted_edge_list.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#=
# Sorted edge list

Soted edge lists are essentially the edges of the linestring, linearring, or polygon, sorted by the initial `y` coordinate.

## Example
=#
Loading