-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deployed 5f4c5d0 with MkDocs version: 1.5.3
- Loading branch information
Unknown
committed
Sep 28, 2023
0 parents
commit bf7c949
Showing
172 changed files
with
158,311 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
advanced/APIRoute_and_environment_variables/APIRoute_and_environment_variables.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
!!! important | ||
This has been deprecated. You can now pass `environment_dependency=lambda: {"GDAL_DISABLE_READDIR_ON_OPEN":"FALSE"}` to the Tiler Factory. This will be passed to a `rasterio.Env()` context manager on top of all gdal related blocks. | ||
|
||
```python | ||
from titiler.core.factory import TilerFactory | ||
cog = TilerFactory( | ||
reader=COGReader, | ||
router_prefix="cog", | ||
environment_dependency=lambda: {"GDAL_DISABLE_READDIR_ON_OPEN":"FALSE"}, | ||
) | ||
``` | ||
|
||
Sometimes, specifically when using GDAL, it can be useful to have environment variables set for certain endpoints | ||
(e.g. when using Landsat data on AWS you need `GDAL_DISABLE_READDIR_ON_OPEN=FALSE` but you don't want this environment variable set for other endpoints). To be able to do this | ||
we created a *custom* APIRoute class which wraps classic fastapi APIRoute with a `rasterio.Env()` block: https://github.com/developmentseed/titiler/blob/8a7127ca56631c2c327713d99e80285048c3aa6c/titiler/custom/routing.py#L13-L41 | ||
|
||
Example: | ||
```python | ||
from fastapi import FastAPI, APIRouter | ||
from rasterio._env import get_gdal_config | ||
from titiler.core.routing import apiroute_factory | ||
from titiler.core.factory import TilerFactory | ||
|
||
app = FastAPI() | ||
route_class = apiroute_factory({"GDAL_DISABLE_READDIR_ON_OPEN": "FALSE"}) | ||
router = APIRouter(route_class=route_class) | ||
|
||
tiler = TilerFactory(router=router) | ||
|
||
@router.get("/simple") | ||
def simple(): | ||
"""should return FALSE.""" | ||
res = get_gdal_config("GDAL_DISABLE_READDIR_ON_OPEN") | ||
return {"env": res} | ||
|
||
app.include_router(router) | ||
``` | ||
|
||
!!! important | ||
This has only be tested for python 3.6 and 3.7. |
Oops, something went wrong.