Skip to content

Geometry Corrections

julia
export fix

This file simply defines the GeometryCorrection abstract type, and the interface that any GeometryCorrection must implement.

A geometry correction is a transformation that is applied to a geometry to correct it in some way.

For example, a ClosedRing correction might be applied to a Polygon to ensure that its exterior ring is closed.

Interface

All GeometryCorrections are callable structs which, when called, apply the correction to the given geometry, and return either a copy or the original geometry (if nothing needed to be corrected).

See below for the full interface specification.

GeometryOps.GeometryCorrection Type
julia
abstract type GeometryCorrection

This abstract type represents a geometry correction.

Interface

Any GeometryCorrection must implement two functions: * 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. * (::GeometryCorrection)(::AbstractGeometryTrait, geometry)::(some_geometry): This function should apply the correction to the given geometry, and return a new geometry.

source

Any geometry correction must implement the interface as given above.

julia
"""
    abstract type GeometryCorrection

This abstract type represents a geometry correction.

# Interface

Any `GeometryCorrection` must implement two functions:
    * `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`.
    * `(::GeometryCorrection)(::AbstractGeometryTrait, geometry)::(some_geometry)`: This function should apply the correction to the given geometry, and return a new geometry.
"""
abstract type GeometryCorrection end

application_level(gc::GeometryCorrection) = error("Not implemented yet for $(gc)")

(gc::GeometryCorrection)(geometry) = gc(GI.trait(geometry), geometry)

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

function fix(geometry; corrections = GeometryCorrection[ClosedRing(),], kwargs...)
    traits = application_level.(corrections)
    final_geometry = geometry
    for Trait in (GI.PointTrait, GI.MultiPointTrait, GI.LineStringTrait, GI.LinearRingTrait, GI.MultiLineStringTrait, GI.PolygonTrait, GI.MultiPolygonTrait)
        available_corrections = findall(x -> x == Trait, traits)
        isempty(available_corrections) && continue
        @debug "Correcting for $(Trait)"
        net_function = reduce(, corrections[available_corrections])
        final_geometry = apply(net_function, Trait, final_geometry; kwargs...)
    end
    return final_geometry
end

Available corrections

GeometryOps.ClosedRing Type
julia
ClosedRing() <: GeometryCorrection

This correction ensures that a polygon's exterior and interior rings are closed.

It can be called on any geometry correction as usual.

See also GeometryCorrection.

source

GeometryOps.DiffIntersectingPolygons Type
julia
DiffIntersectingPolygons() <: GeometryCorrection

This correction ensures that the polygons included in a multipolygon aren't intersecting. If any polygon's are intersecting, they will be made nonintersecting through the difference operation to create a unique set of disjoint (other than potentially connections by a single point) polygons covering the same area. See also GeometryCorrection, UnionIntersectingPolygons.

source

GeometryOps.GeometryCorrection Type
julia
abstract type GeometryCorrection

This abstract type represents a geometry correction.

Interface

Any GeometryCorrection must implement two functions: * 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. * (::GeometryCorrection)(::AbstractGeometryTrait, geometry)::(some_geometry): This function should apply the correction to the given geometry, and return a new geometry.

source

GeometryOps.UnionIntersectingPolygons Type
julia
UnionIntersectingPolygons() <: GeometryCorrection

This correction ensures that the polygon's included in a multipolygon aren't intersecting. If any polygon's are intersecting, they will be combined through the union operation to create a unique set of disjoint (other than potentially connections by a single point) polygons covering the same area.

See also GeometryCorrection.

source


This page was generated using Literate.jl.