Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
iamfrank committed Nov 3, 2022
1 parent 4eb089e commit 35d3b33
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions modules/saul-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ async function compareZ(options) {
* @param {object} options.terrain - GeoTIFF object from getTerrainGeoTIFF() output
* @returns {array} Array with world coordinates (indexes 0 and 1) and elevation (index 2). Coordinates are EPSG:25832 format.
*/
async function getWorldXYZ(options) {
async function getWorldXYZ(options, precision = 0.3) {

const best_world_xyz = compareZ({
image: options.image,
terrain: options.terrain,
xy: options.xy,
z: 0,
limit: 0.5,
limit: precision,
iteration: 1
})

Expand Down
2 changes: 2 additions & 0 deletions modules/saul-elevation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ function getTerrainGeoTIFF(stac_item, auth, fidelity = 0.05) {
})
}

/** Converts raw GeoTIFF arrayBuffer to image */
async function consumeGeoTIFF(raw_data) {
const tiff = await fromArrayBuffer(raw_data)
const image = await tiff.getImage()
return image
}

/** Constrain coordinates to be within a bounding box */
function constrainToBbox(bbox, x, y) {
let new_x = x
let new_y = y
Expand Down
10 changes: 5 additions & 5 deletions test/saul-elevation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getZ, getWorldXYZ, world2image } from '../modules/saul-core.js'

// Vars
const stac_item = '2021_83_29_2_0019_00003995'
const fidelity = 0.05 // Higher number means more points and better precision
const fidelity = 0.03 // Higher number means more points and better precision
const max_deviation = 0.5

// STAC API endpoint
Expand Down Expand Up @@ -53,10 +53,10 @@ function testGetWorldXYZAnumberOfTimes(item, terrain, times) {
image: item,
terrain: terrain
}).then(world_xy => {
compareElevations(world_xy[0], world_xy[1], terrain) // lower left corner of image
compareElevations(world_xy[0], world_xy[1], terrain)
const image_coords = world2image(item, world_xy[0], world_xy[1], world_xy[2])
assert(is_equalIsh(image_coords[0], xy[0], 0.75), `Image x coordinates ${image_coords[0]} / ${xy[0]} do not match`)
assert(is_equalIsh(image_coords[1], xy[1], 0.75), `Image y coordinates ${image_coords[1]} / ${xy[1]} do not match`)
assert(is_equalIsh(image_coords[0], xy[0], 2), `Image x coordinates ${image_coords[0]} / ${xy[0]} do not match`)
assert(is_equalIsh(image_coords[1], xy[1], 2), `Image y coordinates ${image_coords[1]} / ${xy[1]} do not match`)
console.log('getWorldXYZ => world2image OK')
})
}
Expand All @@ -67,7 +67,7 @@ function compareElevations(x,y,geotiff) {
.then(elevation => {
getZ(x, y, auth)
.then(getz_e => {
assert(is_equalIsh(getz_e, elevation), `Elevations ${elevation} / ${getz_e} at ${x} ${y} do not match`)
assert(is_equalIsh(getz_e, elevation, 0.5), `Elevations ${elevation} / ${getz_e} at ${x} ${y} do not match`)
console.log(`Elevation at ${ x } ${ y } with delta ${Math.abs(elevation - getz_e).toFixed(2)} OK`)
})
})
Expand Down

0 comments on commit 35d3b33

Please sign in to comment.