diff --git a/src/transforms.jl b/src/transforms.jl index be49b250a..5613b9b0e 100644 --- a/src/transforms.jl +++ b/src/transforms.jl @@ -94,6 +94,7 @@ include("transforms/affine.jl") include("transforms/stretch.jl") include("transforms/stdcoords.jl") include("transforms/proj.jl") +include("transforms/indomain.jl") include("transforms/morphological.jl") include("transforms/lengthunit.jl") include("transforms/shadow.jl") diff --git a/src/transforms/indomain.jl b/src/transforms/indomain.jl new file mode 100644 index 000000000..60f188511 --- /dev/null +++ b/src/transforms/indomain.jl @@ -0,0 +1,41 @@ +# ------------------------------------------------------------------ +# Licensed under the MIT License. See LICENSE in the project root. +# ------------------------------------------------------------------ + +struct InDomain{CRS} <: CoordinateTransform end + +InDomain(CRS) = InDomain{CRS}() + +InDomain(code::Type{<:EPSG}) = InDomain(CoordRefSystems.get(code)) + +InDomain(code::Type{<:ESRI}) = InDomain(CoordRefSystems.get(code)) + +parameters(::InDomain{CRS}) where {CRS} = (; CRS) + +function preprocess(::InDomain{CRS}, d::Domain) where {CRS} + findall(d) do g + all(pointify(g)) do p + indomain(CRS, coords(p)) + end + end +end + +function preprocess(::InDomain{CRS}, d::Mesh) where {CRS} + findall(d) do g + all(eachvertex(g)) do p + indomain(CRS, coords(p)) + end + end +end + +function preprocess(::InDomain{CRS}, d::GeometrySet{<:Any,<:Any,<:Union{Polytope,MultiPolytope}}) where {CRS} + findall(d) do g + all(eachvertex(g)) do p + indomain(CRS, coords(p)) + end + end +end + +preprocess(::InDomain{CRS}, d::PointSet) where {CRS} = findall(p -> indomain(CRS, coords(p)), d) + +apply(t::InDomain, d::Domain) = view(d, preprocess(t, d)), nothing