|
19 | 19 | from starlette.testclient import TestClient |
20 | 20 |
|
21 | 21 | from titiler.core.dependencies import DefaultDependency |
| 22 | +from titiler.core.errors import add_exception_handlers |
22 | 23 | from titiler.core.resources.enums import OptionalHeader |
| 24 | +from titiler.mosaic.errors import MOSAIC_STATUS_CODES |
23 | 25 | from titiler.mosaic.extensions.mosaicjson import MosaicJSONExtension |
24 | 26 | from titiler.mosaic.extensions.wmts import wmtsExtension |
25 | 27 | from titiler.mosaic.factory import MosaicTilerFactory |
@@ -608,3 +610,189 @@ def test_MosaicTilerFactory_asset_accessor(): |
608 | 610 | ) |
609 | 611 | assert response.status_code == 200 |
610 | 612 | assert len(response.json()) == 1 |
| 613 | + |
| 614 | + |
| 615 | +def test_ogc_maps_mosaic(): |
| 616 | + """Test TilerFactory class.""" |
| 617 | + mosaic = MosaicTilerFactory( |
| 618 | + backend=MosaicJSONBackend, |
| 619 | + add_ogc_maps=True, |
| 620 | + ) |
| 621 | + app = FastAPI() |
| 622 | + app.include_router(mosaic.router) |
| 623 | + add_exception_handlers(app, MOSAIC_STATUS_CODES) |
| 624 | + |
| 625 | + assert ( |
| 626 | + "https://www.opengis.net/spec/ogcapi-maps-1/1.0/conf/core" in mosaic.conforms_to |
| 627 | + ) |
| 628 | + |
| 629 | + with TestClient(app) as client: |
| 630 | + with tmpmosaic() as mosaic_file: |
| 631 | + # Conformance Class “Core” |
| 632 | + response = client.get("/map", params={"url": mosaic_file}) |
| 633 | + assert response.status_code == 501 |
| 634 | + |
| 635 | + # Conformance Class “Spatial Subsetting” |
| 636 | + # /conf/spatial-subsetting/bbox-crs |
| 637 | + response = client.get( |
| 638 | + "/map", |
| 639 | + params={ |
| 640 | + "url": mosaic_file, |
| 641 | + "bbox": "-74,45,-73,46", |
| 642 | + }, |
| 643 | + ) |
| 644 | + headers = response.headers |
| 645 | + # Default CRS for Mosaic is EPSG:4326 |
| 646 | + assert ( |
| 647 | + headers["Content-Crs"] == "<http://www.opengis.net/def/crs/EPSG/0/4326>" |
| 648 | + ) |
| 649 | + assert headers["Content-Bbox"] == "-74.0,45.0,-73.0,46.0" |
| 650 | + assert headers["content-type"] == "image/png" |
| 651 | + |
| 652 | + response = client.get( |
| 653 | + "/map", |
| 654 | + params={ |
| 655 | + "url": mosaic_file, |
| 656 | + # tile 9-151-184 |
| 657 | + "bbox": "-8218509.281222152,5557277.704445455,-8140237.7642581295,5635549.221409475", |
| 658 | + "bbox-crs": "http://www.opengis.net/def/crs/EPSG/0/3857", |
| 659 | + }, |
| 660 | + ) |
| 661 | + headers = response.headers |
| 662 | + assert headers["Content-Crs"] == "<http://www.opengis.net/def/crs/EPSG/0/4326>" |
| 663 | + assert ( |
| 664 | + headers["Content-Bbox"] |
| 665 | + == "-73.828125,44.590467181308846,-73.125,45.08903556483102" |
| 666 | + ) |
| 667 | + assert headers["content-type"] == "image/png" |
| 668 | + |
| 669 | + response = client.get( |
| 670 | + "/map", |
| 671 | + params={ |
| 672 | + "url": mosaic_file, |
| 673 | + # tile 9-151-184 |
| 674 | + "bbox": "-8218509.281222152,5557277.704445455,-8140237.7642581295,5635549.221409475", |
| 675 | + "bbox-crs": "[EPSG:3857]", |
| 676 | + }, |
| 677 | + ) |
| 678 | + headers = response.headers |
| 679 | + assert headers["Content-Crs"] == "<http://www.opengis.net/def/crs/EPSG/0/4326>" |
| 680 | + assert ( |
| 681 | + headers["Content-Bbox"] |
| 682 | + == "-73.828125,44.590467181308846,-73.125,45.08903556483102" |
| 683 | + ) |
| 684 | + assert headers["content-type"] == "image/png" |
| 685 | + |
| 686 | + response = client.get( |
| 687 | + "/map", |
| 688 | + params={ |
| 689 | + "url": mosaic_file, |
| 690 | + # tile 9-151-184 |
| 691 | + "bbox": "-8218509.281222152,5557277.704445455,-8140237.7642581295,5635549.221409475", |
| 692 | + "bbox-crs": "[EPSG:3857]", |
| 693 | + "crs": "[EPSG:3857]", |
| 694 | + }, |
| 695 | + ) |
| 696 | + assert response.status_code == 200 |
| 697 | + headers = response.headers |
| 698 | + assert headers["Content-Crs"] == "<http://www.opengis.net/def/crs/EPSG/0/3857>" |
| 699 | + assert ( |
| 700 | + headers["Content-Bbox"] |
| 701 | + == "-8218509.281222152,5557277.704445455,-8140237.7642581295,5635549.221409475" |
| 702 | + ) |
| 703 | + assert headers["content-type"] == "image/png" |
| 704 | + |
| 705 | + response = client.get( |
| 706 | + "/map", |
| 707 | + params={ |
| 708 | + "url": mosaic_file, |
| 709 | + # tile 4-4-5 |
| 710 | + "bbox": "-10018754.171394622,5009377.085697312,-7514065.628545966,7514065.628545966", |
| 711 | + "bbox-crs": "[EPSG:3857]", |
| 712 | + "crs": "[EPSG:3857]", |
| 713 | + }, |
| 714 | + ) |
| 715 | + assert response.status_code == 200 |
| 716 | + headers = response.headers |
| 717 | + assert headers["Content-Crs"] == "<http://www.opengis.net/def/crs/EPSG/0/3857>" |
| 718 | + assert ( |
| 719 | + headers["Content-Bbox"] |
| 720 | + == "-10018754.171394622,5009377.085697312,-7514065.628545966,7514065.628545966" |
| 721 | + ) |
| 722 | + assert headers["content-type"] == "image/png" |
| 723 | + meta = parse_img(response.content) |
| 724 | + assert meta["width"] == 1024 # default max size |
| 725 | + assert meta["height"] == 1024 |
| 726 | + |
| 727 | + response = client.get( |
| 728 | + "/map", |
| 729 | + params={ |
| 730 | + "url": mosaic_file, |
| 731 | + "bbox": "-74,45,-73,46", |
| 732 | + }, |
| 733 | + headers={"Accept": "image/jpeg"}, |
| 734 | + ) |
| 735 | + headers = response.headers |
| 736 | + assert headers["content-type"] == "image/jpeg" |
| 737 | + |
| 738 | + response = client.get( |
| 739 | + "/map", |
| 740 | + params={ |
| 741 | + "url": mosaic_file, |
| 742 | + "bbox": "-74,45,-73,46", |
| 743 | + "f": "tiff", |
| 744 | + }, |
| 745 | + ) |
| 746 | + headers = response.headers |
| 747 | + assert headers["content-type"] == "image/tiff; application=geotiff" |
| 748 | + |
| 749 | + # Conformance Class “Scaling” |
| 750 | + response = client.get( |
| 751 | + "/map", |
| 752 | + params={ |
| 753 | + "url": mosaic_file, |
| 754 | + "bbox": "-74,45,-73,46", |
| 755 | + "width": 256, |
| 756 | + }, |
| 757 | + ) |
| 758 | + assert response.status_code == 200 |
| 759 | + headers = response.headers |
| 760 | + assert headers["content-type"] == "image/png" |
| 761 | + meta = parse_img(response.content) |
| 762 | + assert meta["width"] == 256 |
| 763 | + assert meta["height"] == 256 |
| 764 | + |
| 765 | + response = client.get( |
| 766 | + "/map", |
| 767 | + params={ |
| 768 | + "url": mosaic_file, |
| 769 | + "bbox": "-74,45,-73,46", |
| 770 | + "width": -256, |
| 771 | + }, |
| 772 | + ) |
| 773 | + assert response.status_code == 422 |
| 774 | + |
| 775 | + # /req/scaling/height-definition |
| 776 | + response = client.get( |
| 777 | + "/map", |
| 778 | + params={ |
| 779 | + "url": mosaic_file, |
| 780 | + "bbox": "-74,45,-73,46", |
| 781 | + "height": 256, |
| 782 | + }, |
| 783 | + ) |
| 784 | + assert response.status_code == 200 |
| 785 | + headers = response.headers |
| 786 | + assert headers["content-type"] == "image/png" |
| 787 | + meta = parse_img(response.content) |
| 788 | + assert meta["width"] == 256 |
| 789 | + assert meta["height"] == 256 |
| 790 | + |
| 791 | + response = client.get( |
| 792 | + "/map", |
| 793 | + params={ |
| 794 | + "url": mosaic_file, |
| 795 | + "height": -256, |
| 796 | + }, |
| 797 | + ) |
| 798 | + assert response.status_code == 422 |
0 commit comments