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