@@ -2055,3 +2055,166 @@ def test_colormap_factory():
20552055 assert meta ["count" ] == 4
20562056 assert meta ["width" ] == 20
20572057 assert meta ["height" ] == 256
2058+
2059+
2060+ def test_ogc_maps_cog ():
2061+ """Test TilerFactory class."""
2062+ cog_path = f"{ DATA_DIR } /cog.tif"
2063+
2064+ cog = TilerFactory (add_ogc_maps = True )
2065+ assert len (cog .router .routes ) == 24
2066+
2067+ assert "https://www.opengis.net/spec/ogcapi-maps-1/1.0/conf/core" in cog .conforms_to
2068+
2069+ app = FastAPI ()
2070+ app .include_router (cog .router )
2071+ with TestClient (app ) as client :
2072+ # Conformance Class “Core”
2073+ response = client .get (
2074+ "/map" ,
2075+ params = {
2076+ "url" : cog_path ,
2077+ },
2078+ )
2079+ assert response .status_code == 200
2080+ headers = response .headers
2081+ assert (
2082+ headers ["Content-Bbox" ]
2083+ == "373185.0,8019284.949381611,639014.9492102272,8286015.0"
2084+ )
2085+ assert headers ["Content-Crs" ] == "<http://www.opengis.net/def/crs/EPSG/0/32621>"
2086+ assert headers ["content-type" ] == "image/png"
2087+ meta = parse_img (response .content )
2088+ assert meta ["width" ] == 1021
2089+ assert meta ["height" ] == 1024 # default max size
2090+
2091+ response = client .get (
2092+ "/map" ,
2093+ params = {
2094+ "url" : cog_path ,
2095+ },
2096+ headers = {"Accept" : "image/jpeg" },
2097+ )
2098+ assert response .status_code == 200
2099+ headers = response .headers
2100+ assert "Content-Bbox" in headers
2101+ assert "Content-Crs" in headers
2102+ assert headers ["content-type" ] == "image/jpeg"
2103+
2104+ response = client .get ("/map" , params = {"url" : cog_path , "f" : "tiff" })
2105+ assert response .status_code == 200
2106+ headers = response .headers
2107+ assert "Content-Bbox" in headers
2108+ assert "Content-Crs" in headers
2109+ assert headers ["content-type" ] == "image/tiff; application=geotiff"
2110+
2111+ # Conformance Class “Scaling”
2112+ # /req/scaling/width-definition
2113+ response = client .get (
2114+ "/map" ,
2115+ params = {
2116+ "url" : cog_path ,
2117+ "width" : 256 ,
2118+ },
2119+ )
2120+ assert response .status_code == 200
2121+ meta = parse_img (response .content )
2122+ assert meta ["width" ] == 256
2123+ assert meta ["height" ] == 257
2124+
2125+ response = client .get (
2126+ "/map" ,
2127+ params = {
2128+ "url" : cog_path ,
2129+ "width" : - 256 ,
2130+ },
2131+ )
2132+ assert response .status_code == 422
2133+
2134+ # /req/scaling/height-definition
2135+ response = client .get (
2136+ "/map" ,
2137+ params = {
2138+ "url" : cog_path ,
2139+ "height" : 256 ,
2140+ },
2141+ )
2142+ assert response .status_code == 200
2143+ meta = parse_img (response .content )
2144+ assert meta ["height" ] == 256
2145+
2146+ response = client .get (
2147+ "/map" ,
2148+ params = {
2149+ "url" : cog_path ,
2150+ "height" : - 256 ,
2151+ },
2152+ )
2153+ assert response .status_code == 422
2154+
2155+ # Conformance Class “Spatial Subsetting”
2156+ # /conf/spatial-subsetting/bbox-crs
2157+ response = client .get (
2158+ "/map" ,
2159+ params = {
2160+ "url" : cog_path ,
2161+ "bbox" : "-56.228,72.715,-54.547,73.188" ,
2162+ },
2163+ )
2164+ headers = response .headers
2165+ assert headers ["Content-Crs" ] == "<http://www.opengis.net/def/crs/EPSG/0/32621>"
2166+ assert (
2167+ headers ["Content-Bbox" ]
2168+ == "524922.2217886819,8068852.367048624,581330.6416587981,8123074.564952523"
2169+ )
2170+ assert headers ["content-type" ] == "image/png"
2171+ meta = parse_img (response .content )
2172+
2173+ response = client .get (
2174+ "/map" ,
2175+ params = {
2176+ "url" : cog_path ,
2177+ "bbox" : "-56.228,72.715,-54.547,73.188" ,
2178+ "bbox-crs" : "http://www.opengis.net/def/crs/OGC/0/CRS84" ,
2179+ },
2180+ )
2181+ headers = response .headers
2182+ assert headers ["Content-Crs" ] == "<http://www.opengis.net/def/crs/EPSG/0/32621>"
2183+ assert (
2184+ headers ["Content-Bbox" ]
2185+ == "524922.2217886819,8068852.367048624,581330.6416587981,8123074.564952523"
2186+ )
2187+ assert headers ["content-type" ] == "image/png"
2188+
2189+ response = client .get (
2190+ "/map" ,
2191+ params = {
2192+ "url" : cog_path ,
2193+ "bbox" : "-6259272.328324187,12015838.020930404,-6072144.264300693,12195445.265479913" ,
2194+ "bbox-crs" : "[EPSG:3857]" ,
2195+ },
2196+ )
2197+ assert response .status_code == 200
2198+ headers = response .headers
2199+ assert headers ["Content-Crs" ] == "<http://www.opengis.net/def/crs/EPSG/0/32621>"
2200+ assert (
2201+ headers ["Content-Bbox" ]
2202+ == "524922.2217886819,8068852.367048624,581330.6416587983,8123074.564952523"
2203+ )
2204+ assert headers ["content-type" ] == "image/png"
2205+
2206+ # Abstract Test for Requirement crs parameter definition
2207+ response = client .get (
2208+ "/map" ,
2209+ params = {
2210+ "url" : cog_path ,
2211+ "bbox" : "-6259272.328324187,12015838.020930404,-6072144.264300693,12195445.265479913" ,
2212+ "bbox-crs" : "[EPSG:3857]" ,
2213+ "crs" : "[EPSG:4326]" ,
2214+ },
2215+ )
2216+ assert response .status_code == 200
2217+ headers = response .headers
2218+ assert headers ["Content-Crs" ] == "<http://www.opengis.net/def/crs/EPSG/0/4326>"
2219+ assert headers ["Content-Bbox" ] == "-56.228,72.715,-54.54699999999999,73.188"
2220+ assert headers ["content-type" ] == "image/png"
0 commit comments