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