-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
actually test embed_extent #29
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Test | ||
|
||
import GeoInterface as GI | ||
import GeometryOps as GO | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to test at least one curve or something that isn't nested since that is a separate function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we use |
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this is such a good way of not having to retype the same documentation over and over. I am so stealing this for my other project 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, from Rasters.jl experience. Actually the main reason is so users see exactly the same things everywhere and it feels consistent