@dataforsyningen/saul 3.1.1 → 3.1.2

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.
@@ -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
- return better_world_xyz
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataforsyningen/saul",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "description": "This is a collection of stand-alone methods for photogrammetry calculations and API interactions for 'Danske Skråfotos'.",
5
5
  "main": "index.js",
6
6
  "type": "module",