From b614376252165bf66b7bbf89f2935ebf069322be Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Fri, 10 Jan 2025 09:45:32 -0100 Subject: [PATCH] add super basic tests --- test/geometry_lookup.jl | 31 +++++++++++++++++++++++++++++++ test/runtests.jl | 1 + 2 files changed, 32 insertions(+) create mode 100644 test/geometry_lookup.jl diff --git a/test/geometry_lookup.jl b/test/geometry_lookup.jl new file mode 100644 index 000000000..0107e54b0 --- /dev/null +++ b/test/geometry_lookup.jl @@ -0,0 +1,31 @@ +using NaturalEarth +using Test + +using Rasters, DimensionalData +import Proj + +@testset "construction" begin + # fetch land polygons from Natural Earth + land_polygons = NaturalEarth.naturalearth("admin_0_countries", 110).geometry + # create a DimVector from the land polygons + gl = GeometryLookup(land_polygons) + @test crs(gl) == EPSG(4326) + @test all(GO.equals, zip(val(gl), land_polygons)) +end + +@testset "reprojecting a GeometryLookup" begin + # fetch land polygons from Natural Earth + land_polygons = NaturalEarth.naturalearth("admin_0_countries", 110).geometry + # create a DimVector from the land polygons + dv = Raster(rand(Dim{:Geometry}(GeometryLookup(land_polygons)))) + # reproject the full vector data cube (vector data vector, in this case :D) + target_crs = ProjString("+proj=wintri +type=crs") + reprojected_via_rasters = val(dims(reproject(target_crs, dv), Dim{:Geometry})) + reprojected_via_geometryops = GO.reproject(land_polygons; source_crs = EPSG(4326), target_crs = target_crs) + # test that the reprojected geometries are the same + @test all(splat(GO.equals), zip( + reprojected_via_rasters, # reproject the vdc, get the geometries from it + reprojected_via_geometryops # reproject the geometries directly + ) + ) +end diff --git a/test/runtests.jl b/test/runtests.jl index e4337545c..9f9dfe266 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -22,6 +22,7 @@ end @time @safetestset "reproject" begin include("reproject.jl") end @time @safetestset "warp" begin include("warp.jl") end @time @safetestset "cellarea" begin include("cellarea.jl") end +@time @safetestset "geometrylookups" begin include("geometry_lookups.jl") end # CommondataModel sources @time @safetestset "commondatamodel" begin include("sources/commondatamodel.jl") end