Extents.jl is a small package that defines an Extent object that can be used by the
different Julia spatial data packages. Extent is a wrapper for a NamedTuple of tuples
holding the lower and upper bounds for each dimension of an object. It is used in
GeoInterface.jl, as the required return type
for the extent function, and in DimensionalData.jl
and Rasters.jl to subset arrays with named dimensions.
Install the package:
]
add ExtentsThen to use it:
using ExtentsCreate Extents:
extent1 = Extent(X = (1.0, 2.0), Y = (3.0, 4.0));
extent2 = Extent(X = (1.5, 2.5), Y = (3.0, 4.0));
extent3 = Extent(X = (-1.0, 5.0), Y = (2.0, 5.0));Find dimensions:
keys(extent1)(:X, :Y)
Get extent for a single dimension by name:
extent1.X(1.0, 2.0)Get underlying NamedTuple:
bounds(extent1)(X = (1.0, 2.0), Y = (3.0, 4.0))Get intersection of two extents:
Extents.intersection(extent1, extent2)Extent(X = (1.5, 2.0), Y = (3.0, 4.0))Get union of two extents:
Extents.union(extent1, extent2)Extent(X = (1.0, 2.5), Y = (3.0, 4.0))Use reduce() to operate over collections:
extents = [extent1, extent2, extent3]3-element Vector{Extent{(:X, :Y), Tuple{Tuple{Float64, Float64}, Tuple{Float64, Float64}}}}:
Extent(X = (1.0, 2.0), Y = (3.0, 4.0))
Extent(X = (1.5, 2.5), Y = (3.0, 4.0))
Extent(X = (-1.0, 5.0), Y = (2.0, 5.0))reduce(Extents.intersection, extents)
Extent(X = (1.5, 2.0), Y = (3.0, 4.0))reduce(Extents.union, extents)
Extent(X = (-1.0, 5.0), Y = (2.0, 5.0))Extents.jl also defines spatial predicates following the DE-9IM standard.
Extents.intersects(extent1, extent2)
trueExtents.disjoint(extent1, extent2)
falseExtents.touches(extent1, extent2)
falseExtents.overlaps(extent1, extent2)
trueSee the docs for all available methods.