From 225997c65df50a86655d3da57ae43e0816f5e66d Mon Sep 17 00:00:00 2001 From: rafaqz Date: Fri, 12 Apr 2024 19:06:05 +0200 Subject: [PATCH 1/5] add prepared geometry wrapper --- src/GeometryOps.jl | 1 + src/prepared.jl | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/prepared.jl diff --git a/src/GeometryOps.jl b/src/GeometryOps.jl index dc52c7d17..97aba6d66 100644 --- a/src/GeometryOps.jl +++ b/src/GeometryOps.jl @@ -19,6 +19,7 @@ const Edge{T} = Tuple{TuplePoint{T},TuplePoint{T}} where T include("primitives.jl") include("utils.jl") +include("prepared.jl") include("methods/angles.jl") include("methods/area.jl") diff --git a/src/prepared.jl b/src/prepared.jl new file mode 100644 index 000000000..b3d2f011f --- /dev/null +++ b/src/prepared.jl @@ -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) = getpropery(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, 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 From e75e738eaeb490bcab9bf454c82f435e2d6f6d5a Mon Sep 17 00:00:00 2001 From: rafaqz Date: Fri, 12 Apr 2024 19:16:29 +0200 Subject: [PATCH 2/5] uncomment --- src/prepared.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/prepared.jl b/src/prepared.jl index b3d2f011f..9607cefe7 100644 --- a/src/prepared.jl +++ b/src/prepared.jl @@ -43,9 +43,9 @@ 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 +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) From 5caaff77b1e98d79800207af24c5132cb88c9e58 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Fri, 12 Apr 2024 20:03:21 +0200 Subject: [PATCH 3/5] Update src/prepared.jl Co-authored-by: Anshul Singhvi --- src/prepared.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prepared.jl b/src/prepared.jl index 9607cefe7..77b7ea81a 100644 --- a/src/prepared.jl +++ b/src/prepared.jl @@ -20,7 +20,7 @@ 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, geom, args...) + @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) From e80ed60f08d3b10d5a47850999a2d2f60af05ab1 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Fri, 12 Apr 2024 18:29:18 -0400 Subject: [PATCH 4/5] Update src/prepared.jl --- src/prepared.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prepared.jl b/src/prepared.jl index 77b7ea81a..45633c82c 100644 --- a/src/prepared.jl +++ b/src/prepared.jl @@ -4,7 +4,7 @@ struct Prepared{Pa,Pr} end Base.parent(x::Prepared) = x.parent -@inline getprep(p::Prepared, x::Symbol) = getpropery(p.preparations, x) +@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)) From 7bf15dbe2c3253eadf398adecd7fcb427d7259cf Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 25 Apr 2024 06:48:04 -0400 Subject: [PATCH 5/5] Structure a `prepared` folder --- src/GeometryOps.jl | 6 +++++- src/preparations/monotone_chain.jl | 10 ++++++++++ .../prepared_geometries.jl} | 0 src/preparations/rtree.jl | 7 +++++++ src/preparations/sorted_edge_list.jl | 7 +++++++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/preparations/monotone_chain.jl rename src/{prepared.jl => preparations/prepared_geometries.jl} (100%) create mode 100644 src/preparations/rtree.jl create mode 100644 src/preparations/sorted_edge_list.jl diff --git a/src/GeometryOps.jl b/src/GeometryOps.jl index 97aba6d66..40d26349d 100644 --- a/src/GeometryOps.jl +++ b/src/GeometryOps.jl @@ -19,7 +19,11 @@ const Edge{T} = Tuple{TuplePoint{T},TuplePoint{T}} where T include("primitives.jl") include("utils.jl") -include("prepared.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") diff --git a/src/preparations/monotone_chain.jl b/src/preparations/monotone_chain.jl new file mode 100644 index 000000000..9499e85e7 --- /dev/null +++ b/src/preparations/monotone_chain.jl @@ -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 +=# + diff --git a/src/prepared.jl b/src/preparations/prepared_geometries.jl similarity index 100% rename from src/prepared.jl rename to src/preparations/prepared_geometries.jl diff --git a/src/preparations/rtree.jl b/src/preparations/rtree.jl new file mode 100644 index 000000000..3325b5b4a --- /dev/null +++ b/src/preparations/rtree.jl @@ -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. +=# \ No newline at end of file diff --git a/src/preparations/sorted_edge_list.jl b/src/preparations/sorted_edge_list.jl new file mode 100644 index 000000000..69ec7a447 --- /dev/null +++ b/src/preparations/sorted_edge_list.jl @@ -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 +=# \ No newline at end of file