Skip to content

Prepared geometry #278

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

Open
wants to merge 4 commits into
base: as/trees
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
11 changes: 8 additions & 3 deletions src/GeometryOps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ using .LoopStateMachine, .SpatialTreeInterface
include("utils/NaturalIndexing.jl")
using .NaturalIndexing

# Preparations and prepared geometry
include("preparations/preparations.jl")
include("preparations/prepared_geometry.jl")
include("preparations/monotone_chain.jl")

# Load utility modules in
using .NaturalIndexing, .SpatialTreeInterface, .LoopStateMachine

# Methods - things that don't change the contents
# of the geometry
include("methods/angles.jl")
include("methods/area.jl")
include("methods/barycentric.jl")
Expand Down Expand Up @@ -82,6 +85,8 @@ include("methods/geom_relations/within.jl")
include("methods/orientation.jl")
include("methods/polygonize.jl")

# Transformations - things that return a copy of the input geometry,
# but transformed in some way.
include("transformations/extent.jl")
include("transformations/flip.jl")
include("transformations/reproject.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
=#

16 changes: 16 additions & 0 deletions src/preparations/preparations.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
abstract type AbstractPreparation end

abstract type AbstractPreparationTrait end

function preptrait end

const PrepTuple = Tuple{Vararg{<: AbstractPreparation}}

struct SpatialIndex{IndexType} <: AbstractPreparation
index::IndexType
end

struct SpatialEdgeIndex{IndexType} <: AbstractPreparation
index::IndexType
end

56 changes: 56 additions & 0 deletions src/preparations/prepared_geometry.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