@dataforsyningen/saul 5.0.0-alpha → 5.0.1-alpha
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/README.md +1 -1
- package/modules/elevation.js +5 -14
- package/package.json +3 -2
- package/test/saul-core.test.js +13 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# SAUL
|
|
2
2
|
|
|
3
|
-
This is a collection of stand-alone methods for photogrammetry calculations and API interactions that are primarily used by https://github.com/
|
|
3
|
+
This is a collection of stand-alone methods for photogrammetry calculations and API interactions that are primarily used by https://github.com/Klimadatastyrelsen/skraafoto_frontend
|
|
4
4
|
|
|
5
5
|
You can use these as building blocks for your own web application that wants to interface with STAC API for Danske Skråfotos.
|
|
6
6
|
|
package/modules/elevation.js
CHANGED
|
@@ -152,16 +152,12 @@ function zeroPadNumber(input) {
|
|
|
152
152
|
/**
|
|
153
153
|
* Exception thrown, when the response from DHM cannot be parsed.
|
|
154
154
|
* @extends Error
|
|
155
|
-
* @property {string} [response] The given response text from DHM.
|
|
156
|
-
* @property {RexExp} [pattern] The given pattern used to parse the response text.
|
|
157
155
|
*/
|
|
158
156
|
class DHMParseError extends Error {
|
|
159
157
|
/**
|
|
160
158
|
* Create a parse exception. All arguments are forwarded to Error.
|
|
161
159
|
* @param {string} message Description of exception.
|
|
162
160
|
* @param {object} [options] Standard options parameter to Error, may contain a cause, see Error.
|
|
163
|
-
* @param {string} [options.response] Response text from DHM, that could not be parsed with pattern.
|
|
164
|
-
* @param {RegExp} [options.pattern] The pattern, that did not parse the Response text well.
|
|
165
161
|
*/
|
|
166
162
|
constructor(...params) {
|
|
167
163
|
super(...params);
|
|
@@ -169,12 +165,6 @@ class DHMParseError extends Error {
|
|
|
169
165
|
Error.captureStackTrace(this, DHMParseError);
|
|
170
166
|
}
|
|
171
167
|
this.name = "DHMParseError";
|
|
172
|
-
if (params.length > 1 && typeof params[1] == 'object') {
|
|
173
|
-
if (params[1].response)
|
|
174
|
-
this.response = params[1].response;
|
|
175
|
-
if (params[1].pattern)
|
|
176
|
-
this.pattern = params[1].pattern;
|
|
177
|
-
}
|
|
178
168
|
}
|
|
179
169
|
}
|
|
180
170
|
|
|
@@ -186,7 +176,7 @@ class DHMParseError extends Error {
|
|
|
186
176
|
* @param {string} auth.API_DHM_WMS_BASEURL The base URL of the DHM WMS endpoint.
|
|
187
177
|
* @param {string} auth.API_DHM_KEY Your API key to access services on Datafordeler.
|
|
188
178
|
* @returns {number} Eventually returns the elevation in meters.
|
|
189
|
-
* @throws {DHMParseError} When unable to parse response from DHM WMS.
|
|
179
|
+
* @throws {DHMParseError} When unable to parse response from DHM WMS. Includes response and some other data in the cause property.
|
|
190
180
|
*/
|
|
191
181
|
async function getZ(xcoor, ycoor, auth) {
|
|
192
182
|
const request = '&request=GetFeatureInfo&styles=&layers=dhm_terraen&query_layers=dhm_terraen&info_format=text/plain&i=175&j=175&width=351&height=351'
|
|
@@ -195,11 +185,12 @@ async function getZ(xcoor, ycoor, auth) {
|
|
|
195
185
|
const dhm_text = await getDHM(request + coords, auth)
|
|
196
186
|
const text_begin = /GetFeatureInfo\s+results:\s*Layer\s+'dhm_terraen'\s+Feature\s*0:\s*value_0\s*=\s*'/y
|
|
197
187
|
if (text_begin.test(dhm_text)) {
|
|
198
|
-
const
|
|
188
|
+
const zsubstr = dhm_text.slice(text_begin.lastIndex)
|
|
189
|
+
const z = parseFloat(zsubstr)
|
|
199
190
|
if (z) return z
|
|
200
|
-
throw new DHMParseError('Cannot parse float value in response text from DHM GetFeatureInfo after pattern.', { response: dhm_text,
|
|
191
|
+
throw new DHMParseError('Cannot parse float value in response text from DHM GetFeatureInfo after pattern.', { cause: { response: dhm_text, index: text_begin.lastIndex, slice: zsubstr, x: xcoor, y: ycoor, coords: coords } })
|
|
201
192
|
}
|
|
202
|
-
throw new DHMParseError('Cannot match response text from DHM GetFeatureInfo with pattern.', { response: dhm_text, pattern: text_begin })
|
|
193
|
+
throw new DHMParseError('Cannot match response text from DHM GetFeatureInfo with pattern.', { cause: { response: dhm_text, pattern: text_begin, x: xcoor, y: ycoor, coords: coords } })
|
|
203
194
|
}
|
|
204
195
|
|
|
205
196
|
/** Fetches a GeoTIFF with elevation data matching a bounding box of EPSG:25832 coordinates
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dataforsyningen/saul",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1-alpha",
|
|
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",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"skråfoto",
|
|
17
|
-
"SDFI",
|
|
17
|
+
"SDFI",
|
|
18
|
+
"KDS",
|
|
18
19
|
"saul"
|
|
19
20
|
],
|
|
20
21
|
"author": {
|
package/test/saul-core.test.js
CHANGED
|
@@ -44,6 +44,19 @@ try {
|
|
|
44
44
|
console.error(error)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// Test getZ 0
|
|
48
|
+
try {
|
|
49
|
+
|
|
50
|
+
let elevation = await getZ(535022.36, 6173550.97, auth)
|
|
51
|
+
|
|
52
|
+
assert.almostEqual(elevation, 0, deviation, 'getZ 0 fail: Elevation is way apart from expected:')
|
|
53
|
+
|
|
54
|
+
console.log("Test getZ 0 OK")
|
|
55
|
+
|
|
56
|
+
} catch(error) {
|
|
57
|
+
console.error("Test getZ 0", error)
|
|
58
|
+
}
|
|
59
|
+
|
|
47
60
|
// Test iterate
|
|
48
61
|
try {
|
|
49
62
|
|