Skip to content

Commit e6d32f8

Browse files
committed
Test table to IFeatureLayer conversion with amissing, mixed geometries, mixed float/int
Test with `nothing` skipped until PR yeesian#238 [Breaking] Return missing if the field is set but null. is merged
1 parent 996dc1b commit e6d32f8

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

test/test_tables.jl

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,5 +793,93 @@ using Tables
793793

794794
clean_test_dataset_files()
795795
end
796+
797+
@testset "Table to layer conversion" begin
798+
# Helper functions
799+
function toWKT_withmissings(x)
800+
if ismissing(x)
801+
return missing
802+
elseif typeof(x) <: AG.AbstractGeometry
803+
return AG.toWKT(x)
804+
else
805+
return x
806+
end
807+
end
808+
function columntablevalues_toWKT(x)
809+
return Tuple(toWKT_withmissings.(x[i]) for i in 1:length(x))
810+
end
811+
function nt2layer2nt_equals_nt(nt::NamedTuple)::Bool
812+
(ct_in, ct_out) = Tables.columntable.((nt_without_nothing, AG.IFeatureLayer(nt_without_nothing)))
813+
(ctv_in, ctv_out) = columntablevalues_toWKT.(values.((ct_in, ct_out)))
814+
(spidx_in, spidx_out) = sortperm.(([keys(ct_in)...], [keys(ct_out)...]))
815+
return all([
816+
sort([keys(ct_in)...]) == sort([keys(ct_out)...]),
817+
all(all.([ctv_in[spidx_in[i]] .=== ctv_out[spidx_out[i]] for i in 1:length(ct_in)])),
818+
])
819+
end
820+
821+
nt_with_missing = NamedTuple([
822+
:point => [
823+
AG.createpoint(30, 10),
824+
nothing,
825+
AG.createpoint(35, 15),
826+
],
827+
:linestring => [
828+
AG.createlinestring([(30., 10.), (10., 30.), (40., 40.)]),
829+
AG.createlinestring([(35., 15.), (15., 35.), (45., 45.)]),
830+
missing,
831+
],
832+
:id => [nothing, "5.1", "5.2"],
833+
:zoom => [1.0, 2.0, 3],
834+
:location => ["Mumbai", missing, "New Delhi"],
835+
:mixedgeom1 => [
836+
AG.createpoint(30, 10),
837+
AG.createlinestring([(30., 10.), (10., 30.), (40., 40.)]),
838+
AG.createpoint(35, 15),
839+
],
840+
:mixedgeom2 => [
841+
AG.createpoint(30, 10),
842+
AG.createlinestring([(30., 10.), (10., 30.), (40., 40.)]),
843+
AG.createmultilinestring([
844+
[(25., 5.), (5., 25.), (35., 35.)],
845+
[(35., 15.), (15., 35.), (45., 45.)],
846+
]),
847+
],
848+
])
849+
850+
@test_skip nt2layer2nt_equals_nt(nt_with_missing)
851+
852+
nt_without_nothing = NamedTuple([
853+
:point => [
854+
AG.createpoint(30, 10),
855+
missing,
856+
AG.createpoint(35, 15),
857+
],
858+
:linestring => [
859+
AG.createlinestring([(30., 10.), (10., 30.), (40., 40.)]),
860+
AG.createlinestring([(35., 15.), (15., 35.), (45., 45.)]),
861+
missing,
862+
],
863+
:id => [missing, "5.1", "5.2"],
864+
:zoom => [1.0, 2.0, 3],
865+
:location => ["Mumbai", missing, "New Delhi"],
866+
:mixedgeom1 => [
867+
AG.createpoint(30, 10),
868+
AG.createlinestring([(30., 10.), (10., 30.), (40., 40.)]),
869+
AG.createpoint(35, 15),
870+
],
871+
:mixedgeom2 => [
872+
AG.createpoint(30, 10),
873+
AG.createlinestring([(30., 10.), (10., 30.), (40., 40.)]),
874+
AG.createmultilinestring([
875+
[(25., 5.), (5., 25.), (35., 35.)],
876+
[(35., 15.), (15., 35.), (45., 45.)],
877+
]),
878+
],
879+
])
880+
881+
@test nt2layer2nt_equals_nt(nt_without_nothing)
882+
end
883+
796884
end
797885
end

0 commit comments

Comments
 (0)