GeoTIFF / GeoTIFF/georaster

Extract GeoTIFF metadata/tags in parseData

Open
#86 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
96
Forks
37
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**

I am using code like this to construct Leaflet layers from GeoTIFF files:

```javascript
fetch(url)
.then(response => response.arrayBuffer())
.then(arrayBuffer => {
parseGeoraster(arrayBuffer).then(georaster => {
var layer = rasterToLayer(georaster); // creates a GeoRasterLayer with color mapping
layerControl.addOverlay(layer, name);
});
});
```
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 by `parseGeoraster`, except by re-parsing the original array buffer using `geotiff.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 what `parseGeoraster` 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#L65

[getGDALMetadata](https://geotiffjs.github.io/geotiff.js/module-geotiffimage-GeoTIFFImage.html#getGDALMetadata) returns exactly the metadata I am trying to access, so I propose calling it and storing the value as a new field on `parseData`'s `result` 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()`, the `image` itself could be stored, which might be more generally useful (all of its methods would then be available, instead of just `getGDALMetadata`).

**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 of `gdalinfo`'s output. Here's an example, where I want to access the `CREATION_DATE`, `AUTHOR` etc fields:

```
$ gdalinfo example.tiff
Driver: GTiff/GeoTIFF
Files: example.tiff
Size is 115, 48
Coordinate System is:
GEOGCRS["WGS 84",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["geodetic latitude (Lat)",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["geodetic longitude (Lon)",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
USAGE[
SCOPE["unknown"],
AREA["World"],
BBOX[-90,-180,90,180]],
ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
Origin = (-124.750000000000000,48.250000000000000)
Pixel Size = (0.500000000000000,-0.500000000000000)
Metadata:
AREA_OR_POINT=Area
CREATION_DATE=2023-12-21
DESCRIPTION=A raster file representing some nifty geospatial dataset.
AUTHOR=Abraham Lincoln
Image Structure Metadata:
INTERLEAVE=BAND
Corner Coordinates:
Upper Left (-124.7500000, 48.2500000) (124d45' 0.00"W, 48d15' 0.00"N)
Lower Left (-124.7500000, 24.2500000) (124d45' 0.00"W, 24d15' 0.00"N)
Upper Right ( -67.2500000, 48.2500000) ( 67d15' 0.00"W, 48d15' 0.00"N)
Lower Right ( -67.2500000, 24.2500000) ( 67d15' 0.00"W, 24d15' 0.00"N)
Center ( -96.0000000, 36.2500000) ( 96d 0' 0.00"W, 36d15' 0.00"N)
Band 1 Block=115x17 Type=Float32, ColorInterp=Gray
NoData Value=-9999
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.