Skip to content

Commit 6343b57

Browse files
Add test for diagonal coverage with cover_scale (#679)
* Add test for diagonal coverage * Use round to have better control on decimals * Use finer cover_scale * lint --------- Co-authored-by: vincentsarago <vincent.sarago@gmail.com>
1 parent 73175d0 commit 6343b57

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/test_models.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ def test_imagedata_coverage():
460460
coverage = im.get_coverage_array({"type": "Feature", "geometry": poly})
461461
assert numpy.unique(coverage).tolist() == [0.25]
462462

463+
# non-default CRS
463464
poly = {
464465
"type": "Polygon",
465466
"coordinates": [
@@ -480,3 +481,17 @@ def test_imagedata_coverage():
480481
{"type": "Feature", "geometry": poly}, shape_crs="epsg:3857"
481482
)
482483
assert numpy.unique(coverage).tolist() == [0.25]
484+
485+
# polygon with diagonal cut - requires higher cover_scale
486+
im = ImageData(
487+
numpy.ma.array((1, 2, 3, 4)).reshape((1, 2, 2)),
488+
crs="epsg:4326",
489+
bounds=(-180, -90, 180, 90),
490+
)
491+
poly = {
492+
"type": "Polygon",
493+
"coordinates": [[[-90.0, -45.0], [90.0, -45.0], [-90.0, 45.0], [-90.0, -45.0]]],
494+
}
495+
496+
coverage = im.get_coverage_array(poly, cover_scale=1000)
497+
assert numpy.round(numpy.unique(coverage), decimals=3).tolist() == [0, 0.125, 0.25]

0 commit comments

Comments
 (0)