|
10 | 10 |
|
11 | 11 | from openeo_driver.errors import OpenEOApiException
|
12 | 12 | from openeo_driver.datacube import DriverVectorCube
|
13 |
| -from openeo_driver.testing import DictSubSet, ApproxGeometry |
| 13 | +from openeo_driver.testing import DictSubSet, ApproxGeometry, IsNan |
14 | 14 | from openeo_driver.util.geometry import as_geojson_feature_collection
|
15 | 15 | from openeo_driver.utils import EvalEnv
|
16 | 16 |
|
@@ -83,6 +83,144 @@ def test_to_wkt(self, gdf):
|
83 | 83 | ['POLYGON ((1 1, 3 1, 2 3, 1 1))', 'POLYGON ((4 2, 5 4, 3 4, 4 2))']
|
84 | 84 | )
|
85 | 85 |
|
| 86 | + def test_to_internal_json_defaults(self, gdf): |
| 87 | + vc = DriverVectorCube(gdf) |
| 88 | + assert vc.to_internal_json() == { |
| 89 | + "geometries": DictSubSet( |
| 90 | + { |
| 91 | + "type": "FeatureCollection", |
| 92 | + "features": [ |
| 93 | + DictSubSet( |
| 94 | + { |
| 95 | + "type": "Feature", |
| 96 | + "geometry": { |
| 97 | + "type": "Polygon", |
| 98 | + "coordinates": (((1.0, 1.0), (3.0, 1.0), (2.0, 3.0), (1.0, 1.0)),), |
| 99 | + }, |
| 100 | + "properties": {"id": "first", "pop": 1234}, |
| 101 | + } |
| 102 | + ), |
| 103 | + DictSubSet( |
| 104 | + { |
| 105 | + "type": "Feature", |
| 106 | + "geometry": { |
| 107 | + "type": "Polygon", |
| 108 | + "coordinates": (((4.0, 2.0), (5.0, 4.0), (3.0, 4.0), (4.0, 2.0)),), |
| 109 | + }, |
| 110 | + "properties": {"id": "second", "pop": 5678}, |
| 111 | + } |
| 112 | + ), |
| 113 | + ], |
| 114 | + } |
| 115 | + ), |
| 116 | + "cube": None, |
| 117 | + } |
| 118 | + |
| 119 | + @pytest.mark.parametrize( |
| 120 | + ["columns_for_cube", "expected_cube"], |
| 121 | + [ |
| 122 | + ( |
| 123 | + "numerical", |
| 124 | + { |
| 125 | + "name": None, |
| 126 | + "dims": ("geometries", "properties"), |
| 127 | + "coords": { |
| 128 | + "geometries": {"attrs": {}, "data": [0, 1], "dims": ("geometries",)}, |
| 129 | + "properties": {"attrs": {}, "data": ["pop"], "dims": ("properties",)}, |
| 130 | + }, |
| 131 | + "data": [[1234], [5678]], |
| 132 | + "attrs": {}, |
| 133 | + }, |
| 134 | + ), |
| 135 | + ( |
| 136 | + "all", |
| 137 | + { |
| 138 | + "name": None, |
| 139 | + "dims": ("geometries", "properties"), |
| 140 | + "coords": { |
| 141 | + "geometries": {"attrs": {}, "data": [0, 1], "dims": ("geometries",)}, |
| 142 | + "properties": {"attrs": {}, "data": ["id", "pop"], "dims": ("properties",)}, |
| 143 | + }, |
| 144 | + "data": [["first", 1234], ["second", 5678]], |
| 145 | + "attrs": {}, |
| 146 | + }, |
| 147 | + ), |
| 148 | + ([], None), |
| 149 | + ( |
| 150 | + ["pop", "id"], |
| 151 | + { |
| 152 | + "name": None, |
| 153 | + "dims": ("geometries", "properties"), |
| 154 | + "coords": { |
| 155 | + "geometries": {"attrs": {}, "data": [0, 1], "dims": ("geometries",)}, |
| 156 | + "properties": {"attrs": {}, "data": ["pop", "id"], "dims": ("properties",)}, |
| 157 | + }, |
| 158 | + "data": [[1234, "first"], [5678, "second"]], |
| 159 | + "attrs": {}, |
| 160 | + }, |
| 161 | + ), |
| 162 | + ( |
| 163 | + ["pop", "color"], |
| 164 | + { |
| 165 | + "name": None, |
| 166 | + "dims": ("geometries", "properties"), |
| 167 | + "coords": { |
| 168 | + "geometries": {"attrs": {}, "data": [0, 1], "dims": ("geometries",)}, |
| 169 | + "properties": {"attrs": {}, "data": ["pop", "color"], "dims": ("properties",)}, |
| 170 | + }, |
| 171 | + "data": [[1234.0, IsNan()], [5678.0, IsNan()]], |
| 172 | + "attrs": {}, |
| 173 | + }, |
| 174 | + ), |
| 175 | + ( |
| 176 | + ["color"], |
| 177 | + { |
| 178 | + "name": None, |
| 179 | + "dims": ("geometries", "properties"), |
| 180 | + "coords": { |
| 181 | + "geometries": {"attrs": {}, "data": [0, 1], "dims": ("geometries",)}, |
| 182 | + "properties": {"attrs": {}, "data": ["color"], "dims": ("properties",)}, |
| 183 | + }, |
| 184 | + "data": [[IsNan()], [IsNan()]], |
| 185 | + "attrs": {}, |
| 186 | + }, |
| 187 | + ), |
| 188 | + ], |
| 189 | + ) |
| 190 | + def test_to_internal_json_columns_for_cube(self, gdf, columns_for_cube, expected_cube): |
| 191 | + vc = DriverVectorCube.from_geodataframe(gdf, columns_for_cube=columns_for_cube) |
| 192 | + internal = vc.to_internal_json() |
| 193 | + assert internal == { |
| 194 | + "geometries": DictSubSet( |
| 195 | + { |
| 196 | + "type": "FeatureCollection", |
| 197 | + "features": [ |
| 198 | + DictSubSet( |
| 199 | + { |
| 200 | + "type": "Feature", |
| 201 | + "geometry": { |
| 202 | + "type": "Polygon", |
| 203 | + "coordinates": (((1.0, 1.0), (3.0, 1.0), (2.0, 3.0), (1.0, 1.0)),), |
| 204 | + }, |
| 205 | + "properties": {"id": "first", "pop": 1234}, |
| 206 | + } |
| 207 | + ), |
| 208 | + DictSubSet( |
| 209 | + { |
| 210 | + "type": "Feature", |
| 211 | + "geometry": { |
| 212 | + "type": "Polygon", |
| 213 | + "coordinates": (((4.0, 2.0), (5.0, 4.0), (3.0, 4.0), (4.0, 2.0)),), |
| 214 | + }, |
| 215 | + "properties": {"id": "second", "pop": 5678}, |
| 216 | + } |
| 217 | + ), |
| 218 | + ], |
| 219 | + } |
| 220 | + ), |
| 221 | + "cube": expected_cube, |
| 222 | + } |
| 223 | + |
86 | 224 | def test_get_crs(self, gdf):
|
87 | 225 | vc = DriverVectorCube(gdf)
|
88 | 226 | assert vc.get_crs() == pyproj.CRS.from_epsg(4326)
|
|
0 commit comments