question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support loading geotiff image from blob

See original GitHub issue

My app supports users dragging a geo-referenced image onto the map, which will then display it at the right location.

This cannot currently be ported to the new openlayers GeoTIFF source, because that can only load an image from a url, while an image that is dragged into the browser becomes available as a Blob.

Normally, one would call URL.createObjectURL(blob) and pass the resulting URL, but that does not work for the GeoTIFF source (at least not in the browsers I’ve tried, such as Firefox 100), because the geotiff.js function fromUrl needs to be able to read ranges from the file, and the browser does not support the range api for that data url.

It would therefore be nice if GeoTIFF exposed access to the fromBlob function in geotiff.js.

Here is a simple suggestion how this could be implemented:

diff --git a/src/ol/source/GeoTIFF.js b/src/ol/source/GeoTIFF.js
index 2188a297b..545182ed3 100644
--- a/src/ol/source/GeoTIFF.js
+++ b/src/ol/source/GeoTIFF.js
@@ -4,7 +4,7 @@
 import DataTile from './DataTile.js';
 import State from './State.js';
 import TileGrid from '../tilegrid/TileGrid.js';
-import {Pool, fromUrl as tiffFromUrl, fromUrls as tiffFromUrls} from 'geotiff';
+import {Pool, fromUrl as tiffFromUrl, fromUrls as tiffFromUrls, fromBlob as tiffFromBlob} from 'geotiff';
 import {
   Projection,
   get as getCachedProjection,
@@ -19,6 +19,7 @@ import {fromCode as unitsFromCode} from '../proj/Units.js';
  * @typedef {Object} SourceInfo
  * @property {string} url URL for the source GeoTIFF.
  * @property {Array<string>} [overviews] List of any overview URLs.
+ * @property {Blob} blob Source GeoTIFF is provided as a blob.  Overrides url and overviews.
  * @property {number} [min=0] The minimum source data value.  Rendered values are scaled from 0 to 1 based on
  * the configured min and max.  If not provided and raster statistics are available, those will be used instead.
  * If neither are available, the minimum for the data type will be used.  To disable this behavior, set
@@ -189,7 +190,9 @@ function getImagesForTIFF(tiff) {
  */
 function getImagesForSource(source, options) {
   let request;
-  if (source.overviews) {
+  if (source.blob) {
+    request = tiffFromBlob(source.blob);
+  } else if (source.overviews) {
     request = tiffFromUrls(source.url, source.overviews, options);
   } else {
     request = tiffFromUrl(source.url, options);

With this small patch I have successfully displayed images dragged into the browser using openlayers.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
ahocevarcommented, May 25, 2022

@m-mohr Yes, please revive it. I have already added a review comment to #13191.

0reactions
ahocevarcommented, Jul 19, 2022

Yes, thanks, @m-mohr. Fixed with #13724.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading and Visualizing GeoTiff | Satellite Images with Python
This article discusses different ways of reading and visualizing these images with python using a jupyter notebook. The libraries used are GDAL, rasterio, ......
Read more >
Loading GeoTiff in Oracle
Hi, I am trying to load a Raster GeoTiff (has location tags, but extension is .tif) in Oracle Spatial 11.2 version. The things...
Read more >
ee.Image.loadGeoTIFF - Earth Engine - Google Developers
Stay organized with collections Save and categorize content based on your preferences. Loads a GeoTIFF as an Image. The Cloud Storage URI of ......
Read more >
Solved: insert (raster,images) into blob in arcgis desktop...
Click View to open the raster in a larger window. · Click Load to load a different image as the raster attribute. ·...
Read more >
How to visualize GeoTIFF images - Luciad Developer Platform
This article describes how to load and visualize GeoTIFF data in LuciadRIA. Because LuciadRIA doesn't come with built-in GeoTIFF support, this article shows ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found