-
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 1 commit
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 |
---|---|---|
|
@@ -6,19 +6,24 @@ 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...) | ||
embed_extent(x; kw...) = apply(extent_applicator, GI.AbstractTrait, x; kw...) | ||
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. We also might want to specify here what keywords are possible. Cross-referencing with the with 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. Ahh probably this can all be written just using one line -
And then the lol |
||
|
||
# We recursively run `embed_extent` so the lowest level | ||
# extent is calculated first and bubbles back up. | ||
# This means we touch each point only once. | ||
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) | ||
function extent_applicator(trait::GI.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) | ||
return wrapper_type(children_with_extents; extent, crs=GI.crs(geom)) | ||
end | ||
extent_applicator(::PointTrait, point) = point | ||
extent_applicator(::PointTrait, point) = point | ||
function extent_applicator(trait::Union{GI.AbstractCurveTrait,GI.MultiPointTrait}, geom) | ||
rafaqz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
wrapper_type = GI.geointerface_geomtype(trait) | ||
extent = GI.extent(geom) | ||
return wrapper_type(geom; extent, crs=GI.crs(geom)) | ||
end | ||
extent_applicator(::GI.PointTrait, point) = point |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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 |
||
import Extents | ||
using GeoInterface.Wrappers | ||
|
||
@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.
I think this could use a bit more comments. I wasn't familiar with this concept and it took a good few minutes to understand what was going on. Maybe a brief description of what extents are and how to access them after running.
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.
Ahh right, I'm assuming a lot of knowledge here. Definately more docs could help!
The ideas is you can use the extent as e.g. a fast
pointinpolygon
proxy. If its in the extent you need to actually check the polygon, if its not you know in a few ns.