npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

srtm-elevation

v2.1.2

Published

Read and query HGT files from SRTM, for elevation data with high performance. This module use cached and automatically download HGT files as required.

Downloads

493

Readme

srtm-elevation

This node module is based on node-hgt so thank you perliedman!

This module read and query HGT files after cache them from the provider specified, for elevation data with high performance.

Usage

const tileset = new SyncTileSet('./data/', [57, 11], [58, 12], function(err) {
    ...
}, options);

Default options


{
  provider: "https://srtm.fasma.org/{lat}{lng}.SRTMGL3S.hgt.zip",
  username: null,
  password: null
}

The provider option it's the url where the library will get the HGT files (1 arcsecond and 3 arcsecond supported) compressed in ZIP format. The url supports two dynamic values, {lat} and {lng} matching the Latitude/Longitude needed to get elevations of coordinates inside the specified bounds.

The default value is https://srtm.fasma.org/{lat}{lng}.SRTMGL3S.hgt.zip but you can specify other providers such as:

Bailu

https://bailu.ch/dem3/{lat}/{lat}{lng}.hgt.zip

Nasa (EarthData)

https://e4ftl01.cr.usgs.gov/MEASURES/SRTMGL3.003/2000.02.11/{lat}{lng}.SRTMGL3.hgt.zip

Since January 2021, you must authenticate in order to access the EarthData NASA elevation data.

So in this case, we must specify two more options, username and password, otherwise the options will be ignored.

From mid-2022 this server is down frecuently so it's not recommended, anyway if you want to use it, you will need Earthdata Login credentials. If you do not have a Earthdata Login, create one at https://urs.earthdata.nasa.gov//users/new"

After activate the account you must specify your username and password when you instantiate the class SyncTileSet by this way:

const tileset = new SyncTileSet('./data/', [57, 11], [58, 12], function(err) {
  ...
}, {
  provider: "https://e4ftl01.cr.usgs.gov/MEASURES/SRTMGL3.003/2000.02.11/{lat}{lng}.SRTMGL3.hgt.zip",
  username: "XXX", // Earthdata username
  password: "XXX", // Earthdata password
});

Install

npm install --save srtm-elevation

Usage

Load and query a HGT file:

const hgt = new Hgt(__dirname + '/data/N57E011.hgt', [57, 11]);

// Return elevation in meters above sea level.
// By default, elevation is interpolated bilinearly.
hgt.getElevation([57, 11]);

Use a cache directory of HGT files for querying. Missing data will be downloaded using the elevation data from the provider specified:

const tileset = new TileSet('./data/');
tileset.getElevation([57.7, 11.9], function(err, elevation) {
  if (err) {
    console.log('getElevation failed: ' + err.message);
  } else {
    console.log(elevation);
  }
});

There's also a synchronous tile set, if you know before hand which area you will query:

const tileset = new SyncTileSet('./data/', [57, 11], [58, 12], function(err) {
  if (err) {
    console.log(err);
    return;
  }

  // All tiles are loaded (or downloaded, if they were not already on disk)
  // and queries can be made synchronous.

  const elevation = tileset.getElevation([57.7, 11.9]);
  console.log(elevation);
});

Full example

In this example, we have an array of locations with a route from Madrid to Paris. We determine the bounds by calculating the minimum and maximum latitude and longitude. The SyncTileSet function will retrieve the necessary hgt files from the specified provider and will cache it. In the callback we calculate the elevation of each point.

The first call will take longer because we have to download and unzip the .hgt.zip files, the following calls will be faster because the files have been cached.

const SyncTileSet = require('srtm-elevation').SyncTileSet;

// From Madrid to Paris [ latitude, longitude ]
const locations = [
  [ 40.396764305572056, -3.7408447265625004  ],
  [ 44.465151013519645,  2.2467041015625004  ],
  [ 43.23319741022136 , -2.9278564453125     ],
  [ 43.337164854911094, -1.4337158203125     ],
  [ 44.84418558537004 , -0.6207275390625001  ],
  [ 46.5739667965278  ,  0.36254882812500006 ],
  [ 47.87214396888731 ,  1.9006347656250002  ],
  [ 48.850258199721495,  2.3291015625000004  ]
];

// Calculate bounds (min and max values from lats/lngs)
const lats = locations.map(l => l[0]);
const lngs = locations.map(l => l[1]);
const minLat = Math.min.apply(null, lats);
const maxLat = Math.max.apply(null, lats);
const minLng = Math.min.apply(null, lngs);
const maxLng = Math.max.apply(null, lngs);

const tileset = new SyncTileSet('./data/', [minLat, minLng], [maxLat, maxLng], function(err) {
  if (err) {
    console.log(err);
    return;
  }

  // All tiles are loaded (or downloaded, if they were not already on disk)
  // and queries can be made synchronous.
  locations.forEach(l => {
    console.log(tileset.getElevation([l[0], l[1]]));
  });
});