https://github.com/maptiler/dem-elevation-profiler
Convert a geojson LineString to a elevation profile.
https://github.com/maptiler/dem-elevation-profiler
Last synced: 9 months ago
JSON representation
Convert a geojson LineString to a elevation profile.
- Host: GitHub
- URL: https://github.com/maptiler/dem-elevation-profiler
- Owner: maptiler
- License: mit
- Archived: true
- Created: 2023-10-01T17:01:56.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-10T15:38:10.000Z (over 2 years ago)
- Last Synced: 2024-12-22T11:40:42.551Z (over 1 year ago)
- Language: TypeScript
- Size: 1.29 MB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dem-elevation-profiler
## About
Convert a geojson LineString to a elevation profile.
## Install
```bash
# NPM
npm install dem-elevation-profiler
# PNPM
pnpm add dem-elevation-profiler
# Yarn
yarn add dem-elevation-profiler
# Bun
bun add dem-elevation-profiler
```
## Usage
```ts
import profile from 'dem-elevation-profiler'
// if nodejs or bun the tileRequest can be local using sharp
import sharp from 'sharp'
// create a geojson LineString
const path = {
type: 'Feature' as const,
properties: {},
geometry: {
type: 'LineString' as const,
coordinates: GeoJSON.Position[] = [...]
}
}
// OR create the LineString geometry directly
const path = {
type: 'LineString' as const,
coordinates: GeoJSON.Position[] = [...]
}
// build the options
const options = {
metric: 'm' as 'm' | 'ft',
zoom: 13,
tileSize: 512,
tileRequest: async (x: number, y: number, z: number) => {
const buf = await sharp(`test/fixtures/${z}-${x}-${y}.webp`)
.raw()
.toBuffer({ resolveWithObject: true })
return {
channels: buf.info.channels,
image: new Uint8ClampedArray(buf.data)
}
},
elevationParser: (r: number, g: number, b: number, _a: number) => {
return -10000 + ((r * 256 * 256 + g * 256 + b) * 0.1)
}
}
// profile the geometry
await profile(path, options)
```