Open kandersolar opened 8 months ago
hey, @kandersolar . Great question! I'll think on your proposal in the coming weeks, but wanted to let you know quick that you can access the geotiff via a "private" undocumented property on the GeoRaster object called "_geotiff", like
const georaster = parseGeoRaster(url);
const tiff = georaster._geotifff;
const img = await tiff.getImage();
img.getGDALMetadata();
I'd recommend locking your georaster version if you take this approach. I can't say if this property will exist on the next major release of georaster because it's an undocumented non-public property subject to change.
Thanks for pointing that out! I was loading from a pre-fetched ArrayBuffer, which I guess is why I didn't notice the _geotiff
attribute (seems like it is only populated when parsing from URL?).
Using that approach does indeed work to get me the metadata I'm after. However, I then ran into other problems where the georaster
object no longer had mins
, maxs
etc attributes, nor was I able to figure out how to calculate them myself with geoblaze. I also ran into trouble with using geoblaze.identify
to extract pixel values.
Here is a slimmed-down version of what I am trying to run:
const url = window.location.origin + "/geotiffs/" + filename;
const georaster = await parseGeoraster(url, {}, true);
const tiff = georaster._geotiff;
const img = await tiff.getImage();
console.log(img.getGDALMetadata()); // works
console.log(georaster.mins); // undefined
console.log(georaster.maxs); // undefined
console.log(georaster.ranges); // undefined
Any hints what I am doing wrong?
Hey, that's a good catch. You're not doing anything wrong per se. It's just that the API for GeoRaster definitely needs a refresh with more customizability. I'm working on a new major version, but can't say when that would be done.
The original logic behind not calculating stats when loaded from a url was to avoid situations where we tried to calculate stats on really large geotiffs, potentially fetching hundreds of megabytes.
If you want to calculate stats, you could use geoblaze like:
import geoblaze from "geoblaze";
const stats = await geoblaze.stats("https://example.org/imagery.tif", undefined, { stats: ["max", "min", "range"] });
Feel free to create an issue on https://github.com/GeoTIFF/geoblaze/issues regarding the identify problem.
I should mention that if you prefer not to use geoblaze, you could use: https://github.com/geotiff/geotiff-stats
Lastly, I don't think we have any test data on https://github.com/geotiff/test-data where the gdal metadata includes AUTHOR and CREATION_DATE. Would you be open to contributing your geotiff to https://github.com/geotiff/test-data? That'll help increase the visibility of your test case in the ecosystem of libraries that use this test data.
Is your feature request related to a problem? Please describe.
I am using code like this to construct Leaflet layers from GeoTIFF files:
This works well. However, in addition to the raster data itself, I now want to access the metadata/tag key-value pairs embedded within GeoTIFF files. As far as I can tell, there is no way to access that information from the
georaster
object returned byparseGeoraster
, except by re-parsing the original array buffer usinggeotiff.js
. I'd rather not do that, to keep my code simpler and more efficient. It would be nice if I could just access it from whatparseGeoraster
returns instead.Describe the solution you'd like Add a call to
image.getGDALMetadata()
somewhere in here: https://github.com/GeoTIFF/georaster/blob/master/src/parseData.js#L65getGDALMetadata returns exactly the metadata I am trying to access, so I propose calling it and storing the value as a new field on
parseData
'sresult
object.I think the new field would then propagate out and be included in the object returned from
parseGeoraster
.Describe alternatives you've considered I suppose instead of storing the results of
image.getGDALMetadata()
, theimage
itself could be stored, which might be more generally useful (all of its methods would then be available, instead of justgetGDALMetadata
).Additional context In case I'm not using the correct terminology (I am new to GeoTIFFs), the key-value pairs I am talking about are shown in the
Metadata
section ofgdalinfo
's output. Here's an example, where I want to access theCREATION_DATE
,AUTHOR
etc fields: