Skip to content

Commit 77bf81a

Browse files
asinghvi17Rafael Schouten
andcommitted
Structure a prepared folder
Co-authored-by: Rafael Schouten <rafael.schouten@gmail.com>
1 parent a801c2c commit 77bf81a

File tree

5 files changed

+88
-1
lines changed

5 files changed

+88
-1
lines changed

src/GeometryOps.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ include("utils/LoopStateMachine/LoopStateMachine.jl") # Utils for functions that
4646
include("utils/SpatialTreeInterface/SpatialTreeInterface.jl") # Utils for spatial trees
4747
include("utils/NaturalIndexing.jl") # Utils for natural indexing
4848
include("utils/utils.jl") # More general utility functions
49-
5049
# Load utility modules in
5150
using .NaturalIndexing, .SpatialTreeInterface, .LoopStateMachine
5251

52+
# Preparations and prepared geometry
53+
include("preparations/preparations.jl")
54+
include("preparations/monotone_chain.jl")
55+
56+
# Methods - things that don't change the contents
57+
# of the geometry
5358
include("methods/angles.jl")
5459
include("methods/area.jl")
5560
include("methods/barycentric.jl")
@@ -78,6 +83,8 @@ include("methods/geom_relations/within.jl")
7883
include("methods/orientation.jl")
7984
include("methods/polygonize.jl")
8085

86+
# Transformations - things that return a copy of the input geometry,
87+
# but transformed in some way.
8188
include("transformations/extent.jl")
8289
include("transformations/flip.jl")
8390
include("transformations/reproject.jl")

src/preparations/monotone_chain.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#=
2+
# Monotone chain
3+
4+
A monotone chain is a continuous list of edges whose slopes are _monotonic_, i.e. all oriented towards the same quadrant.
5+
6+
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.
7+
8+
## Example
9+
=#
10+

src/preparations/preparations.jl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
struct Prepared{Pa,Pr}
2+
parent::Pa
3+
preparations::Pr
4+
end
5+
6+
Base.parent(x::Prepared) = x.parent
7+
@inline getprep(p::Prepared, x::Symbol) = getproperty(p.preparations, x)
8+
9+
GI.trait(p::Prepared) = GI.trait(parent(p))
10+
GI.geomtrait(p::Prepared) = GI.geomtrait(parent(p))
11+
12+
GI.isgeometry(::Type{<:Prepared{T}}) where {T} = GI.isgeometry(T)
13+
GI.isfeature(::Type{<:Prepared{T}}) where {T} = GI.isfeature(T)
14+
GI.isfeaturecollection(::Type{<:Prepared{T}}) where {T} = GI.isfeaturecollection(T)
15+
16+
GI.geometry(x::Prepared) = GI.geometry(parent(x))
17+
GI.properties(x::Prepared) = GI.properties(parent(x))
18+
19+
for f in (:extent, :crs)
20+
@eval GI.$f(t::GI.AbstractTrait, x::Prepared) = GI.$f(t, parent(x))
21+
end
22+
for f in (:coordnames, :is3d, :ismeasured, :isempty, :coordinates, :getgeom)
23+
@eval GI.$f(t::GI.AbstractGeometryTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
24+
end
25+
26+
for f in (:x, :y, :z, :m, :coordinates, :getcoord, :ngeom, :getgeom)
27+
@eval GI.$f(t::GI.AbstractPointTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
28+
end
29+
for f in (:npoint, :getpoint, :startpoint, :endpoint, :npoint, :issimple, :isclosed, :isring)
30+
@eval GI.$f(t::GI.AbstractCurveTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
31+
end
32+
for f in (:nring, :getring, :getexterior, :nhole, :gethole, :npoint, :getpoint, :startpoint, :endpoint)
33+
@eval GI.$f(t::GI.AbstractPolygonTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
34+
end
35+
for f in (:npoint, :getpoint, :issimple)
36+
@eval GI.$f(t::GI.AbstractMultiPointTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
37+
@eval GI.$f(t::GI.AbstractMultiCurveTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
38+
end
39+
for f in (:nring, :getring, :npoint, :getpoint)
40+
@eval GI.$f(t::GI.AbstractMultiPolygonTrait, geom::Prepared, args...) = GI.$f(t, parent(geom), args...)
41+
end
42+
43+
getpoint(t::GI.AbstractPolyhedralSurfaceTrait, geom::Prepared) = GI.getpoint(t, parent(geom))
44+
isclosed(t::GI.AbstractMultiCurveTrait, geom::Prepared) = GI.isclosed(t, parent(geom))
45+
46+
for f in (:getfeature, :coordinates)
47+
@eval GI.$f(t::GI.AbstractFeatureTrait, geom::Prepared, args...) = $f(t, parent(geom), args...)
48+
end
49+
50+
# Ambiguity
51+
for T in (:LineTrait, :TriangleTrait, :PentagonTrait, :HexagonTrait, :RectangleTrait, :QuadTrait)
52+
@eval GI.npoint(t::GI.$T, geom::Prepared) = GI.npoint(t, parent(geom))
53+
end
54+
for T in (:RectangleTrait, :QuadTrait, :PentagonTrait, :HexagonTrait, :TriangleTrait)
55+
@eval GI.nring(t::GI.$T, geom::Prepared) = GI.nring(t, parent(geom))
56+
end

src/preparations/rtree.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#=
2+
# RTree/STRtree
3+
4+
An interface for any arbitrary RTree/STRtree. This should allow reconstruction from SQL like databases.
5+
6+
Applicable to geometrycollections, multi geometries, and feature collections.
7+
=#

src/preparations/sorted_edge_list.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#=
2+
# Sorted edge list
3+
4+
Soted edge lists are essentially the edges of the linestring, linearring, or polygon, sorted by the initial `y` coordinate.
5+
6+
## Example
7+
=#

0 commit comments

Comments
 (0)