Skip to content

Commit

Permalink
Add geometric transforms to extension
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Nov 30, 2023
1 parent 4885963 commit dd38887
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
29 changes: 28 additions & 1 deletion ext/GeoTablesTableTransformsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ using TableTransforms

import TableTransforms: divide, attach
import TableTransforms: applymeta, revertmeta
import TableTransforms: apply, revert, reapply

# table traits
# -----------------------
# TABLE TRANSFORM TRAITS
# -----------------------

divide(geotable::AbstractGeoTable) = values(geotable), domain(geotable)
attach(table, dom::Domain) = georef(table, dom)

# -------------------
# FEATURE TRANSFORMS
# -------------------

# transforms that change the order or number of
# rows in the table need a special treatment

Expand Down Expand Up @@ -108,4 +115,24 @@ function revertmeta(::Sample, newdom::Domain, mcache)
GeometrySet(ugeoms)
end

# ---------------------
# GEOMETRIC TRANSFORMS
# ---------------------

function apply(transform::GeometricTransform, geotable::AbstractGeoTable)
newdom, cache = apply(transform, domain(geotable))
newdata = georef(values(geotable), newdom)
newdata, cache
end

function revert(transform::GeometricTransform, newdata::AbstractGeoTable, cache)
dom = revert(transform, domain(newdata), cache)
georef(values(newdata), dom)
end

function reapply(transform::GeometricTransform, geotable::AbstractGeoTable, cache)
newdom = reapply(transform, domain(geotable), cache)
georef(values(geotable), newdom)
end

end
10 changes: 10 additions & 0 deletions test/geometric.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@testset "Geometric transforms" begin
d = georef((z=rand(100), w=rand(100)))
p = StdCoords()
n, c = apply(p, d)
dom = domain(n)
cen = centroid.(dom)
xs = first.(coordinates.(cen))
@test dom isa CartesianGrid
@test all(x -> -0.5 x 0.5, xs)
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ testfiles = [
"indices.jl",
"operations.jl",
"feature.jl",
"geometric.jl",
"shows.jl"
]

Expand Down

0 comments on commit dd38887

Please sign in to comment.