@dataforsyningen/saul 3.1.1 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/modules/saul-core.js +31 -6
- package/modules/saul-elevation.js +3 -3
- package/package.json +1 -1
package/modules/saul-core.js
CHANGED
|
@@ -118,7 +118,7 @@ function radians(degrees) {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
121
|
+
* Fetches a single elevation value based on X,Y coordinates using DHM/Koter endpoint
|
|
122
122
|
* @param {number} xcoor - EPSG:25832 X coordinate
|
|
123
123
|
* @param {number} ycoor - EPSG:25832 Y coordinate
|
|
124
124
|
* @param {{API_DHM_BASEURL: string, API_DHM_USERNAME: string, API_DHM_PASSWORD: string}} auth - API autentication data. See ../config.js.example for reference.
|
|
@@ -173,6 +173,26 @@ function iterate(image_data, col, row, auth, limit = 1) {
|
|
|
173
173
|
return iterateRecursive(image_data, col, row, 0.5, 0, limit, auth, i)
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
async function compareZ(options) {
|
|
177
|
+
|
|
178
|
+
// Get coordinates based on current z value
|
|
179
|
+
const world_xyz = image2world(options.image, options.xy[0], options.xy[1], options.z)
|
|
180
|
+
// Get new z value from coordinates
|
|
181
|
+
world_xyz[2] = await getElevation(world_xyz[0], world_xyz[1], options.terrain)
|
|
182
|
+
// How big is the different between z and new z?
|
|
183
|
+
const delta = Math.abs(world_xyz[2] - options.z)
|
|
184
|
+
|
|
185
|
+
// Check delta vs. limit. If the difference is too big, try building coordinates with the new z
|
|
186
|
+
// Make sure the recursive loop ends at some point (iteration = 50) even if no precise z is found
|
|
187
|
+
if (options.iteration < 50 && delta > options.limit) {
|
|
188
|
+
options.iteration++
|
|
189
|
+
options.z = world_xyz[2]
|
|
190
|
+
return compareZ(options)
|
|
191
|
+
} else {
|
|
192
|
+
return world_xyz
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
176
196
|
/** Find world coordinate and elevation that correspond to image x,y. Uses image item information from STAC API and a GeoTIFF terrain model from Datafordeler.
|
|
177
197
|
* @param {object} options
|
|
178
198
|
* @param {array} options.xy - image coordinates
|
|
@@ -181,12 +201,17 @@ function iterate(image_data, col, row, auth, limit = 1) {
|
|
|
181
201
|
* @returns {array} Array with world coordinates (indexes 0 and 1) and elevation (index 2). Coordinates are EPSG:25832 format.
|
|
182
202
|
*/
|
|
183
203
|
async function getWorldXYZ(options) {
|
|
184
|
-
|
|
185
|
-
const world_xyz = image2world(options.image, options.xy[0], options.xy[1], 0)
|
|
186
|
-
world_xyz[2] = await getElevation(world_xyz[0], world_xyz[1], options.terrain)
|
|
187
|
-
const better_world_xyz = image2world(options.image, options.xy[0], options.xy[1], world_xyz[2])
|
|
188
204
|
|
|
189
|
-
|
|
205
|
+
const best_world_xyz = compareZ({
|
|
206
|
+
image: options.image,
|
|
207
|
+
terrain: options.terrain,
|
|
208
|
+
xy: options.xy,
|
|
209
|
+
z: 0,
|
|
210
|
+
limit: 0.5,
|
|
211
|
+
iteration: 1
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
return best_world_xyz
|
|
190
215
|
}
|
|
191
216
|
|
|
192
217
|
export {
|
|
@@ -3,7 +3,7 @@ import { get } from './api.js'
|
|
|
3
3
|
|
|
4
4
|
/** Fetches a GeoTIFF with elevation data matching the bounding box of a STAC API item (image)
|
|
5
5
|
* @param {object} stac_item - STAC API item from a featureCollection request
|
|
6
|
-
* @param {{
|
|
6
|
+
* @param {{API_DHM_WCS_BASEURL: string, API_DHM_USERNAME: string, API_DHM_PASSWORD: string}} auth - API autentication data. See ../config.js.example for reference.
|
|
7
7
|
* @param {number} [fidelity] - Resolution fidelity. Higher number means more pixels and better precision. Between 1 and 0.01.
|
|
8
8
|
* @returns {object} GeoTiff data
|
|
9
9
|
*/
|
|
@@ -13,8 +13,8 @@ function getTerrainGeoTIFF(stac_item, auth, fidelity = 0.05) {
|
|
|
13
13
|
const width = Math.round( stac_item.properties['proj:shape'][0] * fidelity )
|
|
14
14
|
const height = Math.round( stac_item.properties['proj:shape'][1] * fidelity )
|
|
15
15
|
|
|
16
|
-
// DHM data
|
|
17
|
-
let url =
|
|
16
|
+
// GET request for DHM WCS data
|
|
17
|
+
let url = auth.API_DHM_WCS_BASEURL
|
|
18
18
|
url += '?SERVICE=WCS&COVERAGE=dhm_terraen&RESPONSE_CRS=epsg:25832&CRS=epsg:25832&FORMAT=GTiff&REQUEST=GetCoverage&VERSION=1.0.0'
|
|
19
19
|
url += `&username=${ auth.API_DHM_USERNAME }&password=${ auth.API_DHM_PASSWORD }` // TODO: Should be auth stuff
|
|
20
20
|
url += `&height=${ height }`
|
package/package.json
CHANGED