Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: STAC Render Extension support #1038

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

alekzvik
Copy link

@alekzvik alekzvik commented Nov 26, 2024

What I am changing

  • Adding support of STAC render extension to titiler. This is a continuation of work started at satsummit stac sprint.

How I did it

  • Adding two endpoints:
    • /renders/ lists all renders
    • /renders/<render_id> returns a specific render with its metadata and template links to tilejson.json and WMTS

How you can test it

Related Issues

Example responses

Those are generated based on this STAC item
Request: http://127.0.0.1:8000/stac/renders/sir?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json
Response:

{
  "params": {
    "assets": [
      "B12",
      "B08",
      "B04"
    ],
    "title": "Shortwave Infra-red",
    "rescale": [
      [
        0,
        5000
      ],
      [
        0,
        7000
      ],
      [
        0,
        9000
      ]
    ],
    "resampling": "nearest"
  },
  "links": [
    {
      "href": "http://127.0.0.1:8000/stac/renders/sir?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json",
      "rel": "self",
      "type": "application/json",
      "title": "sir render item"
    },
    {
      "href": "http://127.0.0.1:8000/stac/{tileMatrixSetId}/tilejson.json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json&assets=B12&assets=B08&assets=B04&resampling_method=nearest",
      "rel": "tilesets-map",
      "templated": true,
      "title": "tilejson file for sir"
    },
    {
      "href": "http://127.0.0.1:8000/stac/{tileMatrixSetId}/WMTSCapabilities.xml?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json&assets=B12&assets=B08&assets=B04&resampling_method=nearest",
      "rel": "tilesets-map",
      "templated": true,
      "title": "WMTS service for sir"
    }
  ]
}

Request: http://127.0.0.1:8000/stac/renders?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json
Response:

{
  "renders": {
    "sir": {
      "params": {
        "assets": [
          "B12",
          "B08",
          "B04"
        ],
        "title": "Shortwave Infra-red",
        "rescale": [
          [
            0,
            5000
          ],
          [
            0,
            7000
          ],
          [
            0,
            9000
          ]
        ],
        "resampling": "nearest"
      },
      "links": [
        {
          "href": "http://127.0.0.1:8000/stac/renders/sir?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json",
          "rel": "self",
          "type": "application/json",
          "title": "sir render item"
        },
        {
          "href": "http://127.0.0.1:8000/stac/{tileMatrixSetId}/tilejson.json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json&assets=B12&assets=B08&assets=B04&resampling_method=nearest",
          "rel": "tilesets-map",
          "templated": true,
          "title": "tilejson file for sir"
        },
        {
          "href": "http://127.0.0.1:8000/stac/{tileMatrixSetId}/WMTSCapabilities.xml?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json&assets=B12&assets=B08&assets=B04&resampling_method=nearest",
          "rel": "tilesets-map",
          "templated": true,
          "title": "WMTS service for sir"
        }
      ]
    }
  },
  "links": [
    {
      "href": "http://127.0.0.1:8000/stac/renders?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json",
      "rel": "self",
      "type": "application/json",
      "title": "List Render Items"
    }
  ]
}

emmanuelmathot and others added 3 commits November 19, 2024 17:45
Render extension started during STAC render sprint in SatSummit Lisbon 2024.

- listing (or showing to please Vincent)

Please contribute to complete the feature to

- generate the final XYZ link for rendering following the rules in STAC extensions
- add a dedicated endpoint for render XYZ
@@ -122,6 +123,7 @@ def validate_access_token(access_token: str = Security(api_key_query)):
router_prefix="/stac",
extensions=[
stacViewerExtension(),
renderExtension(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rename it stacRenderExtension

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I submitted it 3 minutes ago, how are you so fast? 🙃

Makes perfect sense, I will rename it

color_formula: Optional[str] = None
resampling: Optional[str] = None
expression: Optional[str] = None
minmax_zoom: Optional[Annotated[List[int], 2]] = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might want to allow more keys event if they are not supported directly by titiler

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the list of keys from the extension specification here: https://github.com/stac-extensions/render/tree/65edf9bcc7dfe0a02e0191a277c1ac81d86b698e?tab=readme-ov-file#render-object

We can allow the model to validate clearly defined fields but allow extra fields to be read from the render object in STAC and returned by the endpoint. This way we are not overly restrictive but still maintain a defined standard. What do you think?

with factory.reader(src_path) as src:
renders = src.item.properties.get("renders", {})
pprint(renders)
return renders
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe return a response in form of

{
    "{renderId}": {
        "params": {render info},
        "links": [
            {
                "rel": "self",
                "title": "{renderId}",
                "type": "application/json",
                "templated": true,
                "href": "/renders/{renderId} href"
            },
            {
                "title": "{renderId} tilejson",
                "type": "application/json",
                "templated": true,
                "href": "titiler tilejson href"
            },
            {
                "title": "{renderId} wmtsa",
                "type": "application/json",
                "templated": true,
                "href": "titiler wmts href"
            },
            
        ]
    },
    "links": [
        {
          "rel": "self",
          "type": "application/json",
          "href": "https://titiler.api/renders"
        },
        
      ],
}

@alekzvik
Copy link
Author

alekzvik commented Nov 26, 2024

Latest changes:

  • fix typing import that did not work on python 3.8
  • rename renderExtention -> stacRenderExtension
  • new response structure, examples below

Both are based on item-steninel2.json
Request: http://127.0.0.1:8000/stac/renders/sir?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json
Response:

{
  "params": {
    "assets": [
      "B12",
      "B08",
      "B04"
    ],
    "title": "Shortwave Infra-red",
    "rescale": [
      [
        0,
        5000
      ],
      [
        0,
        7000
      ],
      [
        0,
        9000
      ]
    ],
    "resampling": "nearest"
  },
  "links": [
    {
      "href": "http://127.0.0.1:8000/stac/renders/sir?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json",
      "rel": "self",
      "type": "application/json",
      "title": "sir render item"
    },
    {
      "href": "http://127.0.0.1:8000/stac/{tileMatrixSetId}/tilejson.json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json&assets=B12&assets=B08&assets=B04&resampling_method=nearest",
      "rel": "tilesets-map",
      "templated": true,
      "title": "tilejson file for sir"
    },
    {
      "href": "http://127.0.0.1:8000/stac/{tileMatrixSetId}/WMTSCapabilities.xml?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json&assets=B12&assets=B08&assets=B04&resampling_method=nearest",
      "rel": "tilesets-map",
      "templated": true,
      "title": "WMTS service for sir"
    }
  ]
}

Request: http://127.0.0.1:8000/stac/renders?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json
Response:

{
  "renders": {
    "sir": {
      "params": {
        "assets": [
          "B12",
          "B08",
          "B04"
        ],
        "title": "Shortwave Infra-red",
        "rescale": [
          [
            0,
            5000
          ],
          [
            0,
            7000
          ],
          [
            0,
            9000
          ]
        ],
        "resampling": "nearest"
      },
      "links": [
        {
          "href": "http://127.0.0.1:8000/stac/renders/sir?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json",
          "rel": "self",
          "type": "application/json",
          "title": "sir render item"
        },
        {
          "href": "http://127.0.0.1:8000/stac/{tileMatrixSetId}/tilejson.json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json&assets=B12&assets=B08&assets=B04&resampling_method=nearest",
          "rel": "tilesets-map",
          "templated": true,
          "title": "tilejson file for sir"
        },
        {
          "href": "http://127.0.0.1:8000/stac/{tileMatrixSetId}/WMTSCapabilities.xml?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json&assets=B12&assets=B08&assets=B04&resampling_method=nearest",
          "rel": "tilesets-map",
          "templated": true,
          "title": "WMTS service for sir"
        }
      ]
    }
  },
  "links": [
    {
      "href": "http://127.0.0.1:8000/stac/renders?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstac-extensions%2Frender%2F65edf9bcc7dfe0a02e0191a277c1ac81d86b698e%2Fexamples%2Fitem-sentinel2.json",
      "rel": "self",
      "type": "application/json",
      "title": "List Render Items"
    }
  ]
}

For the /renders/ endpoint, I have not yet figured out how to deal with the response model and put renders in additional field renders.

@alekzvik alekzvik changed the title WIP: stac render extension support feat: STAC Render Extension support Nov 26, 2024
@alekzvik alekzvik marked this pull request as ready for review November 26, 2024 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add support for the STAC Render extension
3 participants