This library can be used for extracting elevation data from a local GeoTIFF file.
You can install it with NPM (npm install bojko108/dem-reader
) or Yarn (yarn add bojko108/dem-reader
) and then:
import DemReader from 'dem-reader';
You can calculate elevation values for single points or GeoJSON geometries. Geometries are modified in place, meaning that the elevation value is appended to coordinates array as third element! Following GeoJSON geometries are supported:
Coordinates must be either geographical or in GeoTIFF file's coordinate system. If you pass geographical coordinates, the DEM file must be in UTM35
projection (or in WGS84
) as the library supports only this projection for now.
import DemReader from 'dem-reader';
const file = 'path/to/GeoTIFF/file';
const point = [42.60788543745605, 23.35463742347579];
const dem = await DemReader.fromFile(file);
const elevation = await dem.getElevationForPoint(point, 'EPSG:4326');
// elevation is: 812.4079 meters
import DemReader from 'dem-reader';
const file = 'path/to/GeoTIFF/file';
const point = {
type: 'Point',
coordinates: [23.237647338683313, 42.658865111793808]
};
const dem = await DemReader.fromFile(file);
await dem.calculateElevationForGeometry(point, 'EPSG:4326');
// point is now:
// {
// type: 'Point',
// coordinates: [23.237647338683313, 42.658865111793808, 664.9458]
// }
import DemReader from 'dem-reader';
const file = 'path/to/GeoTIFF/file';
const line = {
type: 'LineString',
coordinates: [...]
};
const dem = await DemReader.fromFile(file);
await dem.calculateElevationForGeometry(line, 'EPSG:4326');
// line now has elevation values
import DemReader from 'dem-reader';
const file = 'path/to/GeoTIFF/file';
const multiLine = {
type: 'MultiLineString',
coordinates: [...]
};
const dem = await DemReader.fromFile(file);
await dem.calculateElevationForGeometry(multiLine, 'EPSG:4326');
// multiLine now has elevation values
dem-reader is MIT License @ bojko108