Skip to content

Commit 1295643

Browse files
committed
use traittarget in application_level for fix
1 parent f7170d0 commit 1295643

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

src/transformations/correction/closed_ring.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ See also [`GeometryCorrection`](@ref).
4646
"""
4747
struct ClosedRing <: GeometryCorrection end
4848

49-
application_level(::ClosedRing) = GI.PolygonTrait
49+
application_level(::ClosedRing) = TraitTarget(GI.PolygonTrait())
5050

5151
function (::ClosedRing)(::GI.PolygonTrait, polygon)
5252
exterior = _close_linear_ring(GI.getexterior(polygon))

src/transformations/correction/cut_at_antimeridian.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function Base.show(io::IO, cut::CutAtAntimeridian)
4444
end
4545
Base.show(io::IO, ::MIME"text/plain", cut::CutAtAntimeridian) = Base.show(io, cut)
4646

47-
application_level(::CutAtAntimeridian) = Union{GI.PolygonTrait, GI.LineStringTrait, GI.MultiLineStringTrait, GI.MultiPolygonTrait}
47+
application_level(::CutAtAntimeridian) = TraitTarget(GI.PolygonTrait(), GI.LineStringTrait(), GI.MultiLineStringTrait(), GI.MultiPolygonTrait())
4848

4949
function (c::CutAtAntimeridianAndPoles)(trait::GI.AbstractTrait, geom)
5050
return _AntimeridianHelpers.cut_at_antimeridian(trait, geom)

src/transformations/correction/geometry_correction.jl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ This abstract type represents a geometry correction.
3333
## Interface
3434
3535
Any `GeometryCorrection` must implement two functions:
36-
* `application_level(::GeometryCorrection)::AbstractGeometryTrait`: This function should return the `GeoInterface` trait that the correction is intended to be applied to, like `PointTrait` or `LineStringTrait` or `PolygonTrait`.
37-
* `(::GeometryCorrection)(::AbstractGeometryTrait, geometry)::(some_geometry)`: This function should apply the correction to the given geometry, and return a new geometry.
36+
- `application_level(::GeometryCorrection)::TraitTarget`: This function should
37+
return the `GeoInterface` trait that the correction is intended to be applied to,
38+
like `PointTrait` or `LineStringTrait` or `PolygonTrait`. It can also return a
39+
union of traits via `TraitTarget`, but that behaviour is a bit tricky...
40+
- `(::GeometryCorrection)(::AbstractGeometryTrait, geometry)::(some_geometry)`:
41+
This function should apply the correction to the given geometry, and return a new
42+
geometry.
3843
"""
3944
abstract type GeometryCorrection end
4045

@@ -44,15 +49,17 @@ application_level(gc::GeometryCorrection) = error("Not implemented yet for $(gc)
4449

4550
(gc::GeometryCorrection)(trait::GI.AbstractGeometryTrait, geometry) = error("Not implemented yet for $(gc) and $(trait).")
4651

47-
function fix(geometry; corrections = GeometryCorrection[ClosedRing(),], kwargs...)
48-
traits = application_level.(corrections)
52+
function fix(geometry; corrections = GeometryCorrection[ClosedRing(), CutAtAntimeridianAndPoles()], kwargs...)
53+
application_levels = application_level.(corrections)
4954
final_geometry = geometry
50-
for Trait in (GI.PointTrait, GI.MultiPointTrait, GI.LineStringTrait, GI.LinearRingTrait, GI.MultiLineStringTrait, GI.PolygonTrait, GI.MultiPolygonTrait)
51-
available_corrections = findall(x -> x == Trait, traits)
55+
for trait in (GI.PointTrait(), GI.MultiPointTrait(), GI.LineStringTrait(), GI.LinearRingTrait(), GI.MultiLineStringTrait(), GI.PolygonTrait(), GI.MultiPolygonTrait())
56+
available_corrections = findall(x -> trait in x, application_levels)
5257
isempty(available_corrections) && continue
53-
@debug "Correcting for $(Trait)"
58+
@debug "Correcting for $(trait), with corrections: " available_corrections
5459
net_function = reduce(, corrections[available_corrections])
55-
final_geometry = apply(net_function, Trait, final_geometry; kwargs...)
60+
# TODO: this allocates too much, because it keeps reconstructing higher level geoms.
61+
# We might want some way to embed the fixes in reconstruct/rebuild, which would imply a modified apply pipeline...
62+
final_geometry = apply(net_function, trait, final_geometry; kwargs...)
5663
end
5764
return final_geometry
5865
end

src/transformations/correction/intersecting_polygons.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ See also [`GeometryCorrection`](@ref).
5656
"""
5757
struct UnionIntersectingPolygons <: GeometryCorrection end
5858

59-
application_level(::UnionIntersectingPolygons) = GI.MultiPolygonTrait
59+
application_level(::UnionIntersectingPolygons) = TraitTarget(GI.MultiPolygonTrait())
6060

6161
function (::UnionIntersectingPolygons)(::GI.MultiPolygonTrait, multipoly)
6262
union_multipoly = tuples(multipoly)
@@ -99,7 +99,7 @@ See also [`GeometryCorrection`](@ref), [`UnionIntersectingPolygons`](@ref).
9999
"""
100100
struct DiffIntersectingPolygons <: GeometryCorrection end
101101

102-
application_level(::DiffIntersectingPolygons) = GI.MultiPolygonTrait
102+
application_level(::DiffIntersectingPolygons) = TraitTarget(GI.MultiPolygonTrait())
103103

104104
function (::DiffIntersectingPolygons)(::GI.MultiPolygonTrait, multipoly)
105105
diff_multipoly = tuples(multipoly)

0 commit comments

Comments
 (0)