1313import textwrap
1414from typing import Optional
1515
16+ import pyproj
1617import pytest
1718import requests
1819import shapely .geometry
1920
2021import openeo .metadata
2122import openeo .processes
2223from openeo .api .process import Parameter
24+ from openeo .capabilities import ComparableVersion
2325from openeo .internal .graph_building import PGNode
2426from openeo .internal .process_graph_visitor import ProcessGraphVisitException
2527from openeo .internal .warnings import UserDeprecationWarning
182184}
183185
184186
185- CRS_VALUES_SUPPORTED_FOR_ALL_PYTHON_VERSIONS = [
186- "EPSG:32631" ,
187- "32631" ,
188- 32631 ,
189- "+proj=utm +zone=31 +datum=WGS84 +units=m +no_defs" , # is also EPSG:32631, in proj format
190- ]
187+ def _get_normalizable_crs_inputs ():
188+ """
189+ Dynamic (proj version based) generation of supported CRS inputs (to normalize).
190+ :return:
191+ """
192+ yield "EPSG:32631"
193+ yield 32631
194+ if pyproj .__version__ >= ComparableVersion ("3.3.1" ):
195+ # pyproj below 3.3.1 does not support int-like strings
196+ # TODO #460 this skip is only necessary for python 3.6 and lower
197+ yield "32631"
198+ yield "+proj=utm +zone=31 +datum=WGS84 +units=m +no_defs" # is also EPSG:32631, in proj format
199+ if pyproj .__version__ >= ComparableVersion ("3.1.0" ):
200+ # WKT2 format support requires pyproj 3.1.0 or higher
201+ yield WKT2_FOR_EPSG23631
191202
192203
193204def _get_leaf_node (cube : DataCube ) -> dict :
@@ -405,7 +416,7 @@ def test_aggregate_spatial_types(con100: Connection, polygon, expected_geometrie
405416 }
406417
407418
408- @pytest .mark .parametrize ("crs" , CRS_VALUES_SUPPORTED_FOR_ALL_PYTHON_VERSIONS )
419+ @pytest .mark .parametrize ("crs" , _get_normalizable_crs_inputs () )
409420def test_aggregate_spatial_with_crs (con100 : Connection , recwarn , crs : str ):
410421 img = con100 .load_collection ("S2" )
411422 polygon = shapely .geometry .box (0 , 0 , 1 , 1 )
@@ -430,36 +441,10 @@ def test_aggregate_spatial_with_crs(con100: Connection, recwarn, crs: str):
430441 }
431442
432443
433- @pytest .mark .skipif (sys .version_info < (3 , 7 ), reason = "WKT2 format not supported by pyproj 3.0 / python 3.6" )
434- def test_aggregate_spatial_with_crs_as_wkt (con100 : Connection , recwarn ):
435- """Separate test coverage for WKT, so we can skip it for Python3.6"""
436- crs = WKT2_FOR_EPSG23631
437- img = con100 .load_collection ("S2" )
438- polygon = shapely .geometry .box (0 , 0 , 1 , 1 )
439- masked = img .aggregate_spatial (geometries = polygon , reducer = "mean" , crs = crs )
440- warnings = [str (w .message ) for w in recwarn ]
441- assert f"Geometry with non-Lon-Lat CRS { crs !r} is only supported by specific back-ends." in warnings
442- assert sorted (masked .flat_graph ().keys ()) == ["aggregatespatial1" , "loadcollection1" ]
443- assert masked .flat_graph ()["aggregatespatial1" ] == {
444- "process_id" : "aggregate_spatial" ,
445- "arguments" : {
446- "data" : {"from_node" : "loadcollection1" },
447- "geometries" : {
448- "type" : "Polygon" ,
449- "coordinates" : (((1.0 , 0.0 ), (1.0 , 1.0 ), (0.0 , 1.0 ), (0.0 , 0.0 ), (1.0 , 0.0 )),),
450- "crs" : {"properties" : {"name" : "EPSG:32631" }, "type" : "name" },
451- },
452- "reducer" : {
453- "process_graph" : {
454- "mean1" : {"process_id" : "mean" , "arguments" : {"data" : {"from_parameter" : "data" }}, "result" : True }
455- }
456- },
457- },
458- "result" : True ,
459- }
460-
461-
462- @pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "PROJJSON format not supported by pyproj 3.2 / python < v3.8" )
444+ @pytest .mark .skipif (
445+ pyproj .__version__ < ComparableVersion ("3.3.0" ),
446+ reason = "PROJJSON format support requires pyproj 3.3.0 or higher" ,
447+ )
463448@pytest .mark .parametrize ("crs" , [PROJJSON_FOR_EPSG23631 , json .dumps (PROJJSON_FOR_EPSG23631 )])
464449def test_aggregate_spatial_with_crs_as_projjson (con100 : Connection , recwarn , crs ):
465450 """Separate test coverage for PROJJSON, so we can skip it for Python versions below 3.8"""
@@ -686,7 +671,7 @@ def test_mask_polygon_types(con100: Connection, polygon, expected_mask):
686671 }
687672
688673
689- @pytest .mark .parametrize ("crs" , CRS_VALUES_SUPPORTED_FOR_ALL_PYTHON_VERSIONS )
674+ @pytest .mark .parametrize ("crs" , _get_normalizable_crs_inputs () )
690675def test_mask_polygon_with_crs (con100 : Connection , recwarn , crs : str ):
691676 img = con100 .load_collection ("S2" )
692677 polygon = shapely .geometry .box (0 , 0 , 1 , 1 )
@@ -709,31 +694,10 @@ def test_mask_polygon_with_crs(con100: Connection, recwarn, crs: str):
709694 }
710695
711696
712- @pytest .mark .skipif (sys .version_info < (3 , 7 ), reason = "WKT2 format not supported by pyproj 3.0 / python 3.6" )
713- def test_mask_polygon_with_crs_as_wkt (con100 : Connection , recwarn ):
714- """Separate test coverage for WKT, so we can skip it for Python3.6"""
715- crs = WKT2_FOR_EPSG23631
716- img = con100 .load_collection ("S2" )
717- polygon = shapely .geometry .box (0 , 0 , 1 , 1 )
718- masked = img .mask_polygon (mask = polygon , srs = crs )
719- warnings = [str (w .message ) for w in recwarn ]
720- assert f"Geometry with non-Lon-Lat CRS { crs !r} is only supported by specific back-ends." in warnings
721- assert sorted (masked .flat_graph ().keys ()) == ["loadcollection1" , "maskpolygon1" ]
722- assert masked .flat_graph ()["maskpolygon1" ] == {
723- "process_id" : "mask_polygon" ,
724- "arguments" : {
725- "data" : {"from_node" : "loadcollection1" },
726- "mask" : {
727- "type" : "Polygon" , "coordinates" : (((1.0 , 0.0 ), (1.0 , 1.0 ), (0.0 , 1.0 ), (0.0 , 0.0 ), (1.0 , 0.0 )),),
728- # All listed test inputs for crs should be converted to "EPSG:32631"
729- "crs" : {"type" : "name" , "properties" : {"name" : "EPSG:32631" }},
730- },
731- },
732- "result" : True ,
733- }
734-
735-
736- @pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "PROJJSON format not supported by pyproj 3.2 / python < v3.8" )
697+ @pytest .mark .skipif (
698+ pyproj .__version__ < ComparableVersion ("3.3.0" ),
699+ reason = "PROJJSON format support requires pyproj 3.3.0 or higher" ,
700+ )
737701@pytest .mark .parametrize ("crs" , [PROJJSON_FOR_EPSG23631 , json .dumps (PROJJSON_FOR_EPSG23631 )])
738702def test_mask_polygon_with_crs_as_projjson (con100 : Connection , recwarn , crs ):
739703 """Separate test coverage for PROJJSON, so we can skip it for Python versions below 3.8"""
0 commit comments