Skip to content

A shared Extent object for Julia spatial data, with DE-9IM spatial predicates

License

rafaqz/Extents.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Extents

Stable Dev Build Status Coverage

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.

Quick start

Install the package:

]
add Extents

Then to use it:

using Extents

Create 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)
true
Extents.disjoint(extent1, extent2)
false
Extents.touches(extent1, extent2)
false
Extents.overlaps(extent1, extent2)
true

See the docs for all available methods.

About

A shared Extent object for Julia spatial data, with DE-9IM spatial predicates

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 8

Languages