-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add 'InDomain' transform * Add docstring * Add to documentation && Add to exports * Add tests * Update docstring * Update example * Add more tests * More adjustments * Rename InDomain to ValidCoords * Rename helper * Apply suggestions * Apply suggestions * Apply suggestions from code review Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com> * Use the correct parent type * Apply suggestions from code review Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com> * Apply suggestions * Add more tests * Adjust code order --------- Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
- Loading branch information
Showing
5 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -542,6 +542,7 @@ export | |
Proj, | ||
Morphological, | ||
LengthUnit, | ||
ValidCoords, | ||
Shadow, | ||
Slice, | ||
Repair, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# ------------------------------------------------------------------ | ||
# Licensed under the MIT License. See LICENSE in the project root. | ||
# ------------------------------------------------------------------ | ||
|
||
""" | ||
ValidCoords(CRS) | ||
ValidCoords(code) | ||
Retain the geometries within the domain of the | ||
projection of type `CRS` or with EPSG/ESRI `code`. | ||
""" | ||
struct ValidCoords{CRS} <: GeometricTransform end | ||
|
||
ValidCoords(CRS) = ValidCoords{CRS}() | ||
|
||
ValidCoords(code::Type{<:EPSG}) = ValidCoords(CoordRefSystems.get(code)) | ||
|
||
ValidCoords(code::Type{<:ESRI}) = ValidCoords(CoordRefSystems.get(code)) | ||
|
||
parameters(::ValidCoords{CRS}) where {CRS} = (; CRS) | ||
|
||
preprocess(t::ValidCoords, d::Domain) = findall(g -> _isvalid(t, g), d) | ||
|
||
function preprocess(t::ValidCoords, d::Mesh) | ||
points = vertices(d) | ||
topo = topology(d) | ||
findall(elements(topo)) do elem | ||
is = indices(elem) | ||
all(_isvalid(t, points[i]) for i in is) | ||
end | ||
end | ||
|
||
apply(t::ValidCoords, d::Domain) = view(d, preprocess(t, d)), nothing | ||
|
||
# ----------- | ||
# IO METHODS | ||
# ----------- | ||
|
||
Base.show(io::IO, ::ValidCoords{CRS}) where {CRS} = print(io, "ValidCoords(CRS: $CRS)") | ||
|
||
function Base.show(io::IO, ::MIME"text/plain", t::ValidCoords{CRS}) where {CRS} | ||
summary(io, t) | ||
println(io) | ||
print(io, "└─ CRS: $CRS") | ||
end | ||
|
||
# ----------------- | ||
# HELPER FUNCTIONS | ||
# ----------------- | ||
|
||
_isvalid(::ValidCoords{CRS}, p::Point) where {CRS} = indomain(CRS, coords(p)) | ||
_isvalid(t::ValidCoords, g::Polytope) = all(p -> _isvalid(t, p), eachvertex(g)) | ||
_isvalid(t::ValidCoords, g::MultiPolytope) = all(p -> _isvalid(t, p), eachvertex(g)) | ||
_isvalid(t::ValidCoords, g::Geometry) = all(p -> _isvalid(t, p), pointify(g)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters