sun-horizon
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

sun-horizon 🌄

License Version Build Status

🌄 Get Horizon profile based on topography from a (latitude, longitude) point.

🙌🏻 This module is heavily based on node-hgt.

☕️ Support

Buy Me A Coffee PayPal

🏁 Install

npm install sun-horizon

🏃‍♂️ Usage

✅ Call init() function before any other operations.

🗄 sun-horizon uses a cache directory of HGT files (default sun-horizon-data/).

💻 This module supports javascript or typescirpt.

const sunHorizon = require('sun-horizon');
 
sunHorizon.init();
const horizon = await sunHorizon.getHorizon({"lat": 45, "lng": 5});

or

import { getHorizon, init } from 'sun-horizon';
 
init();
const horizon = await getHorizon({lat: 45, lng: 5});

Types

LatLng

{
  latnumber;
  lngnumber;
}

HorizonOptions

{
  azimuthOptions?: AzimuthOptions;
  highestPointOptions?: HighestPointOptions;
}

AzimuthOptions

{
  azimuthStart?: number; // degree, 0 is North, 90 Eeast
  azimuthEnd?: number; // degree
  azimuthTick?: number; // degree
}

HighestPointOptions

{
  distanceMax?: number; // meter
  distanceTick?: number; // meter
}

HorizonPoint

{
  azimuthnumber; // degree
  anglenumber; // degree, 0 is same elevation as origin
  altitudenumber; // meter
 
  latLng?: LatLng;
}

Horizon

{
  originLatLng;
  elevationProfileHorizonPoint[];
}

CacheData

{
  bytesnumber;
  filesnumber;
}

Functions

init

init(cacheDirectory?: string)void

Initialize module and create the required cache directory (default is sun-horizon-data/) + populate with a .gitignore file.

getHorizon

getHorizon(originLatLng, options?: HorizonOptions)Promise<Horizon>
const grenoble: LatLng = {
  lat: 45.185739,
  lng: 5.736236
}
const horizon = await getHorizon(grenoble);
console.log(horizon.elevationProfile.map(point => point.altitude));

highestPointInAzimuth

highestPointInAzimuth(originLatLng, azimuthnumber, options?: HighestPointOptions)Promise<HorizonPoint>
const origin: LatLng = {
  lat: 45.185739,
  lng: 5.736236
}
const azimuth = 90; // East
const point = await highestPointInAzimuth(origin, azimuth);

getAltitude

getAltitude(latLngLatLng)Promise<number>
const origin: LatLng = {
  lat: 45.185739,
  lng: 5.736236
}
const altitude = await getAltitude(origin); // in meter

getCacheData

Return number of files and total size in bytes. (See CacheData)

getCacheData()Promise<CacheData>
const cache = await getCacheData();

cleanCache

Delete all .hgt cache files and return number of deleted files.

cleanCache()Promise<number>
const deletedFiles = await cleanCache();

Package Sidebar

Install

npm i sun-horizon

Weekly Downloads

1

Version

1.1.4

License

MIT

Unpacked Size

17.8 kB

Total Files

17

Last publish

Collaborators

  • jeremy38100