-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
51 additions
and
29 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 |
---|---|---|
@@ -1,29 +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(extent_applicator, GI.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 | ||
# 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) | ||
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, crs=GI.crs(geom)) | ||
end | ||
function extent_applicator(trait::Union{GI.AbstractCurveTrait,GI.MultiPointTrait}, geom) | ||
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 | ||
$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