-
Notifications
You must be signed in to change notification settings - Fork 2
/
calculateIdw.ts
66 lines (60 loc) · 1.73 KB
/
calculateIdw.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import axios from 'axios';
import { Exposure } from '../box/_boxModels';
import { RFC3339Date, WGS84Coordinates } from '../globalTypes';
/**
* @see https://docs.opensensemap.org/#api-Interpolation-calculateIdw
*/
export async function calculateIdw(phenomenon: string, bbox: WGS84Coordinates, options?: CalculateIdwOptions): Promise<CalculateIdwResult> {
if (options?.['from-date'] && options['from-date'] instanceof Date) {
options['from-date'] = options['from-date'].toISOString();
}
if (options?.['to-date'] && options['to-date'] instanceof Date) {
options['to-date'] = options['to-date'].toISOString();
}
if (options?.exposure && Array.isArray(options.exposure)) {
options.exposure = options.exposure.join();
}
return (
await axios.get('https://api.opensensemap.org/statistics/idw', {
params: Object.assign({ phenomenon, bbox }, options)
})
).data;
}
export type CalculateIdwOptions = {
'from-date'?: RFC3339Date | Date;
'to-date'?: RFC3339Date | Date;
gridType?: 'hex' | 'square' | 'triangle';
cellWidth?: number;
power?: number;
numTimeSteps?: number;
numClasses?: number;
exposure?: string | Exposure[];
};
/**
* @linkcode https://github.com/sensebox/openSenseMap-API/blob/2e645bdc4c80e668720b5eaaf384a35d2909569e/packages/api/lib/controllers/statisticsController.js#L112C7-L112C7
*/
export type CalculateIdwResult =
| {
code: 'NotFound';
message: 'no measurements found';
}
| {
code: 'Ok';
data: {
breaks: number[];
featureCollection: {
type: 'FeatureCollection';
features: {
type: string;
properties?: {
idwValues: number[];
};
geometry: {
type: string;
coordinates: number[][][];
};
};
}[];
timesteps: RFC3339Date[];
};
};