@@ -793,5 +793,93 @@ using Tables
793
793
794
794
clean_test_dataset_files ()
795
795
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
+
796
884
end
797
885
end
0 commit comments