Skip to content

addCOG(): stream the COG again; use colorOptions - #110

Open
eliotmcintire wants to merge 1 commit into
r-spatial:masterfrom
eliotmcintire:cog-streaming
Open

eliotmcintire wants to merge 1 commit into
r-spatial:masterfrom
eliotmcintire:cog-streaming

Conversation

@eliotmcintire

@eliotmcintire eliotmcintire commented Nov 17, 2026 •

Copy link
Copy Markdown

Thanks for leafem; I am a heavy user of it, through the map viewer in our SpaDES.shiny package. I only work in R, so I used Claude (an AI assistant) to find the cause and write the fix. This is a person and an AI working on it together.

Closes #109.

addCOG() once again reads only the tiles and overview needed for the view, not the whole file. The mouse readout still works: it now reads just the pixel under the cursor. colorOptions is now applied.

Technical details
  • georaster-binding.js: addCOG calls parseGeorasterCOG(url) instead of fetch(url) + arrayBuffer().
  • New cogColorFn(): same palette/breaks/na.color handling as addGeotiff(). A streamed georaster has no mins/maxs, so when domain is NULL it is read from a 256×256 overview. An explicit pixelValuesToColorFn still wins.
  • New cogMouseHandler(): like mouseHandler(), but does a 1×1 getValues() at the cursor and fires the same control text and Shiny events. Cursor → pixel supports EPSG:4326 and EPSG:3857, which proj4 knows without a definition; for other CRSs the layer draws but has no readout.
  • New georaster-keep.js, loaded between georaster.min.js and geoblaze.js: var parseGeorasterCOG = parseGeoraster;. geoblaze.js replaces the global parseGeoraster with its bundled older georaster, which throws "No image at index n" when reading overviews. addGeotiff() and other callers are unchanged.
  • The layer is added with category "image", as in addGeotiff(), so removeImage()/clearImages() work on it.
  • Docs for colorOptions and pixelValuesToColorFn updated; NEWS entry.

Tested in headless Chromium:

  • A 7 MB Float32 EPSG:4326 COG: first draw 4.3 s / 7 MB before, 1.5–1.8 s / 0.2–0.6 MB after. The readout value equals gdallocationinfo at the same point.
  • The addCOG() example (Sentinel-2 RGB preview, UTM) renders the same as before.
  • addGeotiff() is unchanged.

No tests added: the package has no JS tests, and this needs a browser plus a range-request server. Happy to add something if you have a pattern you prefer.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Lx3DXeXwtafUJiXgqLqcTv

addCOG() downloaded the whole file (fetch + arrayBuffer) since mouse events
were added in 2b75a37, because geoblaze.identify() needs the values in
memory. Now the url is passed to parseGeoraster(), so only the tiles and
overview level needed for the view are read, and the value under the mouse
is read as a single pixel (cogMouseHandler). colorOptions is applied; with
no domain, it is taken from the smallest overview.

georaster-keep.js keeps georaster.min.js's parseGeoraster: geoblaze.js,
loaded after it, replaces the global with an older georaster that fails on
overview reads ("No image at index n").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lx3DXeXwtafUJiXgqLqcTv
@tim-salabim

Copy link
Copy Markdown
Member

Sounds good!

This branch has not been deployed

No deployments
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.

addCOG() downloads the whole file instead of streaming the COG

2 participants