Skip to content

Commit

Permalink
feat: allow to override dem file + concurrency level.
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbourianes-kalisio committed May 2, 2022
1 parent ee622f1 commit 8649f4f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
7 changes: 1 addition & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const { validateGeoJson } = require('./src/utils.geojson.js')
const port = process.env.PORT || 8080
const bodyLimit = process.env.BODY_LIMIT || '100kb'
const terrainFile = process.env.TERRAIN_FILEPATH || path.join('/mbtiles', 'terrain.mbtiles')
const demFile = process.env.DEM_FILEPATH || path.join('/mbtiles', 'dem.vrt')

// features validator middleware
const geoJsonValidator = function (req, res, next) {
Expand Down Expand Up @@ -53,14 +52,10 @@ new MBTiles(terrainFile, (err, mbtiles) => {
})
})

app.get('/elevationat', (req, res) => {
return res.status(200).json({ foo: false })
})

// Elevation
app.post('/elevation', [geoJsonValidator], async (req, res) => {
let start = new Date()
const result = await elevation(req.body, demFile)
const result = await elevation(req.body)
let duration = new Date() - start
console.log('<> profile computed in %dms', duration)
return res.status(200).json(result)
Expand Down
13 changes: 10 additions & 3 deletions src/elevation.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,17 @@ async function parallel_exec(tasklist, concurrency) {
}

// based on https://kokoalberti.com/articles/creating-elevation-profiles-with-gdal-and-two-point-equidistant-projection/
async function elevation(geojson, dem) {
async function elevation(geojson) {
// Extract computing parameters
const resolution = _.get(geojson, 'resolution', 30)
console.log('[K2] elevation requested with parameters: ', { resolution })
const concurrency = _.get(geojson, 'concurrency', 4)
const demOverride = _.get(geojson, 'demOverride', '')

// 1 arc sec is ~30m at the equator
// srtmv4 is 3arcsec => ~90m
// gmted2010 has 7.5, 15 and 30 arcsec => ~220m
const demFile = path.join('/mbtiles', demOverride !== '' ? demOverride : resolution < 220 ? 'srtm.vrt' : 'gmted2010.vrt')

// prepare work folder
const workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'elevation-'))
Expand Down Expand Up @@ -122,15 +129,15 @@ async function elevation(geojson, dem) {
'-t_srs', `"${projStr}"`,
'-ts', numPoints, '1',
'-r', 'max',
dem, outFile ], logFile)
demFile, outFile ], logFile)
},
success: () => {},
fail: () => {}
}
allTasks.push(task)
})

await parallel_exec(allTasks, 4)
await parallel_exec(allTasks, concurrency)

// we'll have to read each segment as tiff and generate a geojson points from data
const segments = []
Expand Down

0 comments on commit 8649f4f

Please sign in to comment.