|
37 | 37 | from unittest import mock |
38 | 38 |
|
39 | 39 | import pytest |
| 40 | +from shapely import from_geojson |
40 | 41 | from shapely.wkt import loads |
41 | 42 |
|
42 | 43 | from pycsw.core import util |
@@ -386,3 +387,53 @@ def test_str2bool(): |
386 | 387 | assert not util.str2bool(False) |
387 | 388 | assert not util.str2bool('off') |
388 | 389 | assert not util.str2bool('no') |
| 390 | + |
| 391 | + |
| 392 | +@pytest.mark.parametrize("geometry,expected", [ |
| 393 | + ({ |
| 394 | + 'type': 'Point', |
| 395 | + 'coordinates': [102.0, 0.5] |
| 396 | + }, '102.0,0.5,102.0,0.5'), ({ |
| 397 | + 'type': 'LineString', |
| 398 | + 'coordinates': [ |
| 399 | + [102.0, 0.0], |
| 400 | + [103.0, 1.0], |
| 401 | + [104.0, 0.0], |
| 402 | + [105.0, 1.0] |
| 403 | + ] |
| 404 | + }, '102.0,0.0,105.0,1.0'), ({ |
| 405 | + 'type': 'Polygon', |
| 406 | + 'coordinates': [[ |
| 407 | + [100.0, 0.0], |
| 408 | + [101.0, 0.0], |
| 409 | + [101.0, 1.0], |
| 410 | + [100.0, 1.0], |
| 411 | + [100.0, 0.0] |
| 412 | + ]] |
| 413 | + }, '100.0,0.0,101.0,1.0'), ({ |
| 414 | + 'type': 'MultiPolygon', |
| 415 | + 'coordinates': [[[ |
| 416 | + [30.0, 20.0], |
| 417 | + [45.0, 40.0], |
| 418 | + [10.0, 40.0], |
| 419 | + [30.0, 20.0] |
| 420 | + ]], [[ |
| 421 | + [15.0, 5.0], |
| 422 | + [40.0, 10.0], |
| 423 | + [10.0, 20.0], |
| 424 | + [5.0, 10.0], |
| 425 | + [15.0, 5.0] |
| 426 | + ]]] |
| 427 | + }, '5.0,5.0,45.0,40.0'), ({ |
| 428 | + 'type': 'MultiPoint', |
| 429 | + 'coordinates': [ |
| 430 | + [10.0, 40.0], |
| 431 | + [40.0, 30.0], |
| 432 | + [20.0, 20.0], |
| 433 | + [30.0, 10.0] |
| 434 | + ] |
| 435 | + }, '10.0,10.0,40.0,40.0') |
| 436 | +]) |
| 437 | +def test_geojson_geometry2bbox(geometry, expected): |
| 438 | + bounds = util.geojson_geometry2bbox(geometry) |
| 439 | + assert bounds == expected |
0 commit comments