forked from JuliaGeo/GeometryOps.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
actually test embed_extent (JuliaGeo#29)
* actually test embed_extent * fix Extents dep * document transformation keywords * bugfix keyword formatting
- Loading branch information
Showing
9 changed files
with
71 additions
and
26 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
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 |
---|---|---|
@@ -1,24 +1,17 @@ | ||
""" | ||
embed_extent(obj) | ||
Recursively wrap the object with a `GeoInterface.Wrappers` geometry, | ||
Recursively wrap the object with a GeoInterface.jl geometry, | ||
calculating and adding an `Extents.Extent` to all objects. | ||
This can improve performance when extents need to be checked multiple times. | ||
""" | ||
embed_extent(x; kw...) = apply(AbstractTrait, x; kw...) | ||
This can improve performance when extents need to be checked multiple times, | ||
such when needing to check if many points are in geometries, and using their extents | ||
as a quick filter for obviously exterior points. | ||
# Keywords | ||
extent_applicator(x) = extent_applicator(trait(x), x) | ||
extent_applicator(::Nothing, xs::AbstractArray) = embed_extent.(xs) | ||
extent_applicator(::Union{AbstractCurveTrait,MultiPointTrait}, point) = point | ||
|
||
function extent_applicator(trait::AbstractGeometryTrait, geom) | ||
children_with_extents = map(GI.getgeom(geom)) do g | ||
embed_extent(g) | ||
end | ||
wrapper_type = GI.geointerface_geomtype(trait) | ||
extent = GI.extent(wrapper_type(children_with_extents)) | ||
return wrapper_type(children_with_extents, extent) | ||
end | ||
extent_applicator(::PointTrait, point) = point | ||
extent_applicator(::PointTrait, point) = point | ||
$THREADED_KEYWORD | ||
$CRS_KEYWORD | ||
""" | ||
embed_extent(x; threaded=false, crs=nothing) = | ||
apply(identity, GI.PointTrait, x; calc_extent=true, threaded, crs) |
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
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
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,16 @@ | ||
using Test | ||
|
||
import GeoInterface as GI | ||
import GeometryOps as GO | ||
using GeoInterface: Extents | ||
|
||
@testset "embed_extent" begin | ||
poly = GI.Polygon([GI.LinearRing([(1, 2), (3, 4), (5, 6), (1, 2)]), | ||
GI.LinearRing([(3, 4), (5, 6), (6, 7), (3, 4)])]) | ||
|
||
ext_poly = GO.embed_extent(poly) | ||
lr1, lr2 = GI.getgeom(ext_poly) | ||
@test ext_poly.extent == Extents.Extent(X=(1, 6), Y=(2, 7)) | ||
@test lr1.extent == Extents.Extent(X=(1, 5), Y=(2, 6)) | ||
@test lr2.extent == Extents.Extent(X=(3, 6), Y=(4, 7)) | ||
end |