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

Add support for COG and STAC #3

Open
giswqs opened this issue Mar 21, 2023 · 8 comments
Open

Add support for COG and STAC #3

giswqs opened this issue Mar 21, 2023 · 8 comments

Comments

@artttt
Copy link

artttt commented Sep 13, 2023

I had a quick go at modifying your code for openlayers to open a COG.

I've been waiting for years for a tool like ipyleaflet that can display large raster without having to run a tile server. Seems like it is finally not too far fetched an idea.

function loadScript(src) {
    return new Promise((resolve, reject) => {
        let script = Object.assign(document.createElement("script"), {
            type: "text/javascript",
            async: true,
            src: src,
        });
        script.addEventListener("load", resolve);
        script.addEventListener("error", reject);
        document.body.appendChild(script);
    });
}
 await loadScript("https://cdn.jsdelivr.net/npm/[email protected]/dist/ol.js");
 await loadScript("https://cdn.jsdelivr.net/npm/[email protected]/dist-browser/geotiff.js");


export function render(view) {
    // Header
    let center = view.model.get("center");
    center.reverse();
    let zoom = view.model.get("zoom");
    let width = view.model.get("width");
    let height = view.model.get("height");

    const div = document.createElement("div");
    div.style.width = width;
    div.style.height = height;

    const source = new ol.source.GeoTIFF({
      sources: [
        {
          url: 'https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/36/Q/WD/2020/7/S2A_36QWD_20200701_0_L2A/TCI.tif',
        },
      ],
    });
    
    // Map content
    var map = new ol.Map({
        target: div,
        layers: [
        new ol.layer.WebGLTile({
          source: source,
        }),
        ],
        view: source.getView(),
    });
    view.el.appendChild(div);
}

@giswqs
Copy link
Member Author

giswqs commented Sep 13, 2023

Nice! Can you submit a pull request for this?

@artttt
Copy link

artttt commented Sep 13, 2023

Maybe if i take it further.
This is pretty hacky as i'm not experienced with javascript. It's a fairly basic mix of your code and this openlayers example.

https://openlayers.org/en/latest/examples/cog.html

@giswqs
Copy link
Member Author

giswqs commented Sep 13, 2023

Another postential solution
https://github.com/stac-utils/stac-layer

@artttt
Copy link

artttt commented Sep 13, 2023

The readme of that makes it sound like it can only show a cog overview. I may have mis understood.
This makes sense as all the cog implementations for leaflet I've found have that limitation.

OpenLayers seems to have very good cog handling.

@giswqs
Copy link
Member Author

giswqs commented Sep 13, 2023

I have been using the TiTiler demo endpoint (https://titiler.xyz) for rendering COG/STAC. It incurres charges on their end. I would like to avoid using it if possible. We need a solution for rendering COG/STAC without a server.

@artttt
Copy link

artttt commented Sep 13, 2023

I'm aware of that service.
I use
https://github.com/banesullivan/localtileserver
Which works ok.
I wrote (badly) a similar tool way back in 2017, and was wishing for a better way to view rasters in Jupyter for a few years before that. I'm obviously patient. 😃

@giswqs
Copy link
Member Author

giswqs commented Sep 13, 2023

Leafmap supports both TiTiler (for remote COG) and localtileserver (for local COG).

import leafmap
url = 'https://opendata.digitalglobe.com/events/california-fire-2020/pre-event/2018-02-16/pine-gulch-fire20/1030010076004E00.tif'
m = leafmap.Map()
m.add_cog_layer(url)
m

It seems the localtileserver remote COG is not working at the moment. I am considering switch from the TiTiler demo point to localtileserver once the issue is fixed. However, we still need TiTiler to render STAC assets. I am not aware any other python package that can render STAC assets without a tile server.
banesullivan/localtileserver#172

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

No branches or pull requests

2 participants