@@ -365,6 +365,25 @@ def test_filter_spatial(con100: Connection):
365365 }
366366
367367
368+ @pytest .mark .parametrize ("path_factory" , [str , pathlib .Path ])
369+ def test_filter_spatial_local_path (con100 : Connection , path_factory , test_data ):
370+ path = path_factory (test_data .get_path ("geojson/polygon02.json" ))
371+ cube = con100 .load_collection ("S2" )
372+ masked = cube .filter_spatial (geometries = path )
373+ assert get_download_graph (masked , drop_save_result = True , drop_load_collection = True ) == {
374+ "filterspatial1" : {
375+ "process_id" : "filter_spatial" ,
376+ "arguments" : {
377+ "data" : {"from_node" : "loadcollection1" },
378+ "geometries" : {
379+ "type" : "Polygon" ,
380+ "coordinates" : [[[3 , 50 ], [4 , 50 ], [4 , 51 ], [3 , 50 ]]],
381+ },
382+ },
383+ }
384+ }
385+
386+
368387@pytest .mark .parametrize (
369388 ["url" , "expected_format" ],
370389 [
@@ -659,6 +678,38 @@ def test_aggregate_spatial_geometry_url(con100: Connection, url, expected_format
659678 }
660679
661680
681+ @pytest .mark .parametrize ("path_factory" , [str , pathlib .Path ])
682+ def test_aggregate_spatial_geometry_local_path (con100 : Connection , path_factory , test_data ):
683+ cube = con100 .load_collection ("S2" )
684+ path = path_factory (test_data .get_path ("geojson/polygon02.json" ))
685+ result = cube .aggregate_spatial (geometries = path , reducer = "mean" )
686+ assert get_download_graph (result , drop_save_result = True , drop_load_collection = True ) == {
687+ "aggregatespatial1" : {
688+ "process_id" : "aggregate_spatial" ,
689+ "arguments" : {
690+ "data" : {"from_node" : "loadcollection1" },
691+ "geometries" : {"type" : "Polygon" , "coordinates" : [[[3 , 50 ], [4 , 50 ], [4 , 51 ], [3 , 50 ]]]},
692+ "reducer" : {
693+ "process_graph" : {
694+ "mean1" : {
695+ "process_id" : "mean" ,
696+ "arguments" : {"data" : {"from_parameter" : "data" }},
697+ "result" : True ,
698+ }
699+ }
700+ },
701+ },
702+ },
703+ }
704+
705+
706+ def test_aggregate_spatial_geometry_local_path_invalid (con100 : Connection ):
707+ path = "nope/invalid:path%here.json"
708+ cube = con100 .load_collection ("S2" )
709+ with pytest .raises (OpenEoClientException , match = "Invalid geometry argument" ):
710+ _ = cube .aggregate_spatial (geometries = path , reducer = "mean" )
711+
712+
662713def test_aggregate_spatial_window (con100 : Connection ):
663714 img = con100 .load_collection ("S2" )
664715 size = [5 , 3 ]
@@ -827,24 +878,29 @@ def test_mask_polygon_parameter(con100: Connection):
827878 }
828879
829880
830- def test_mask_polygon_path (con100 : Connection ):
831- img = con100 .load_collection ("S2" )
832- masked = img .mask_polygon (mask = "path/to/polygon.json" )
833- assert sorted (masked .flat_graph ().keys ()) == ["loadcollection1" , "maskpolygon1" , "readvector1" ]
834- assert masked .flat_graph ()["maskpolygon1" ] == {
835- "process_id" : "mask_polygon" ,
836- "arguments" : {
837- "data" : {"from_node" : "loadcollection1" },
838- "mask" : {"from_node" : "readvector1" },
881+ @pytest .mark .parametrize ("path_factory" , [str , pathlib .Path ])
882+ def test_mask_polygon_geometry_local_path (con100 : Connection , path_factory , test_data ):
883+ path = path_factory (test_data .get_path ("geojson/polygon02.json" ))
884+ cube = con100 .load_collection ("S2" )
885+ masked = cube .mask_polygon (mask = path )
886+ assert get_download_graph (masked , drop_save_result = True , drop_load_collection = True ) == {
887+ "maskpolygon1" : {
888+ "process_id" : "mask_polygon" ,
889+ "arguments" : {
890+ "data" : {"from_node" : "loadcollection1" },
891+ "mask" : {"type" : "Polygon" , "coordinates" : [[[3 , 50 ], [4 , 50 ], [4 , 51 ], [3 , 50 ]]]},
892+ },
839893 },
840- "result" : True ,
841- }
842- assert masked .flat_graph ()["readvector1" ] == {
843- "process_id" : "read_vector" ,
844- "arguments" : {"filename" : "path/to/polygon.json" },
845894 }
846895
847896
897+ def test_mask_polygon_geometry_local_path_invalid (con100 : Connection ):
898+ path = "nope/invalid:path%here.json"
899+ cube = con100 .load_collection ("S2" )
900+ with pytest .raises (OpenEoClientException , match = "Invalid geometry argument" ):
901+ _ = cube .mask_polygon (mask = path )
902+
903+
848904@pytest .mark .parametrize ("get_geometries" , [
849905 lambda c : PGNode ("load_vector" , url = "https://geo.test/features.json" ),
850906 lambda c : openeo .processes .process ("load_vector" , url = "https://geo.test/features.json" ),
@@ -1583,18 +1639,19 @@ def test_chunk_polygon_parameter(con100: Connection):
15831639 }
15841640
15851641
1586- def test_chunk_polygon_path (con100 : Connection ):
1642+ @pytest .mark .parametrize ("path_factory" , [str , pathlib .Path ])
1643+ def test_chunk_polygon_path (con100 : Connection , test_data , path_factory ):
1644+ path = path_factory (test_data .get_path ("geojson/polygon02.json" ))
15871645 cube = con100 .load_collection ("S2" )
15881646 process = lambda data : data .run_udf (udf = "myfancycode" , runtime = "Python" )
15891647 with pytest .warns (UserDeprecationWarning , match = "Use `apply_polygon`" ):
1590- result = cube .chunk_polygon (chunks = " path/to/polygon.json" , process = process )
1648+ result = cube .chunk_polygon (chunks = path , process = process )
15911649 assert get_download_graph (result , drop_save_result = True , drop_load_collection = True ) == {
1592- "readvector1" : {"process_id" : "read_vector" , "arguments" : {"filename" : "path/to/polygon.json" }},
15931650 "chunkpolygon1" : {
15941651 "process_id" : "chunk_polygon" ,
15951652 "arguments" : {
15961653 "data" : {"from_node" : "loadcollection1" },
1597- "chunks" : {"from_node " : "readvector1" },
1654+ "chunks" : {"type " : "Polygon" , "coordinates" : [[[ 3 , 50 ], [ 4 , 50 ], [ 4 , 51 ], [ 3 , 50 ]]] },
15981655 "process" : {
15991656 "process_graph" : {
16001657 "runudf1" : {
@@ -1797,21 +1854,17 @@ def test_apply_polygon_parameter(con100: Connection, geometries_argument, geomet
17971854 ("geometries" , "geometries" ),
17981855 ],
17991856)
1800- def test_apply_polygon_path (con100 : Connection , geometries_argument , geometries_parameter ):
1857+ def test_apply_polygon_local_path (con100 : Connection , geometries_argument , geometries_parameter , test_data ):
1858+ path = test_data .get_path ("geojson/polygon02.json" )
18011859 cube = con100 .load_collection ("S2" )
18021860 process = UDF (code = "myfancycode" , runtime = "Python" )
1803- result = cube .apply_polygon (** {geometries_argument : " path/to/polygon.json" }, process = process )
1861+ result = cube .apply_polygon (** {geometries_argument : path }, process = process )
18041862 assert get_download_graph (result , drop_save_result = True , drop_load_collection = True ) == {
1805- "readvector1" : {
1806- # TODO #104 #457 get rid of non-standard read_vector
1807- "process_id" : "read_vector" ,
1808- "arguments" : {"filename" : "path/to/polygon.json" },
1809- },
18101863 "applypolygon1" : {
18111864 "process_id" : "apply_polygon" ,
18121865 "arguments" : {
18131866 "data" : {"from_node" : "loadcollection1" },
1814- geometries_parameter : {"from_node " : "readvector1" },
1867+ geometries_parameter : {"type " : "Polygon" , "coordinates" : [[[ 3 , 50 ], [ 4 , 50 ], [ 4 , 51 ], [ 3 , 50 ]]] },
18151868 "process" : {
18161869 "process_graph" : {
18171870 "runudf1" : {
@@ -1830,6 +1883,14 @@ def test_apply_polygon_path(con100: Connection, geometries_argument, geometries_
18301883 }
18311884
18321885
1886+ def test_apply_polygon_local_path_invalid (con100 : Connection ):
1887+ path = "nope/invalid:path%here.json"
1888+ cube = con100 .load_collection ("S2" )
1889+ process = UDF (code = "myfancycode" , runtime = "Python" )
1890+ with pytest .raises (OpenEoClientException , match = "Invalid geometry argument" ):
1891+ _ = cube .apply_polygon (geometries = path , process = process )
1892+
1893+
18331894@pytest .mark .parametrize (
18341895 ["geometries_argument" , "geometries_parameter" ],
18351896 [
0 commit comments