webdggrid 1.0.3 → 1.0.5
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/dist/webdggrid.js +1 -1
- package/dist/webdggrid.js.map +1 -1
- package/dist/webdggrid.umd.js +1 -1
- package/dist/webdggrid.umd.js.map +1 -1
- package/lib-esm/libdggrid.wasm.js +1 -1
- package/lib-esm/webdggrid.js +57 -25
- package/lib-esm/webdggrid.js.map +1 -1
- package/lib-wasm/libdggrid.js +1 -1
- package/lib-wasm/libdggrid.wasm +0 -0
- package/package.json +4 -2
- package/readme.md +95 -1
- package/src-ts/webdggrid.ts +111 -36
- package/types/webdggrid.d.ts +27 -6
- package/types/webdggrid.d.ts.map +1 -1
package/src-ts/webdggrid.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
2
|
import { loadWasm, unloadWasm } from './libdggrid.wasm.js';
|
|
3
|
-
|
|
3
|
+
import { Feature, FeatureCollection, GeoJsonProperties, Polygon, Position } from 'geojson';
|
|
4
4
|
/**
|
|
5
5
|
* Cell Topology
|
|
6
6
|
*
|
|
@@ -24,11 +24,27 @@ export enum Projection {
|
|
|
24
24
|
'FULLER' = 'FULLER',
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* A geographic coordinate
|
|
29
|
+
*/
|
|
27
30
|
export interface Coordinate {
|
|
28
31
|
lat: number;
|
|
29
32
|
lng: number;
|
|
30
33
|
}
|
|
31
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Geojson properties type.
|
|
37
|
+
* TODO: Better handeling the types
|
|
38
|
+
*/
|
|
39
|
+
export type DGGSGeoJsonProperty = GeoJsonProperties & {
|
|
40
|
+
/**
|
|
41
|
+
* It stores the seq number if exists
|
|
42
|
+
*/
|
|
43
|
+
id?: BigInt;
|
|
44
|
+
i?: BigInt;
|
|
45
|
+
j?: BigInt;
|
|
46
|
+
}
|
|
47
|
+
|
|
32
48
|
export interface IDGGSProps {
|
|
33
49
|
poleCoordinates: Coordinate;
|
|
34
50
|
azimuth: number;
|
|
@@ -259,7 +275,7 @@ export class Webdggrid {
|
|
|
259
275
|
sequenceNumToGeo(
|
|
260
276
|
sequenceNum: bigint[],
|
|
261
277
|
resolution: number = DEFAULT_RESOLUTION
|
|
262
|
-
):
|
|
278
|
+
): Position[] {
|
|
263
279
|
const {
|
|
264
280
|
poleCoordinates: { lat, lng },
|
|
265
281
|
azimuth,
|
|
@@ -279,10 +295,10 @@ export class Webdggrid {
|
|
|
279
295
|
sequenceNum
|
|
280
296
|
);
|
|
281
297
|
|
|
282
|
-
const size = resultArray.length/2;
|
|
283
|
-
const arrayOfArrays:number[][] = [];
|
|
298
|
+
const size = resultArray.length / 2;
|
|
299
|
+
const arrayOfArrays: number[][] = [];
|
|
284
300
|
for (let i = 0; i < size; i += 1) {
|
|
285
|
-
arrayOfArrays.push([resultArray[i], resultArray[i+size]]);
|
|
301
|
+
arrayOfArrays.push([resultArray[i], resultArray[i + size]]);
|
|
286
302
|
}
|
|
287
303
|
|
|
288
304
|
return arrayOfArrays;
|
|
@@ -296,7 +312,7 @@ export class Webdggrid {
|
|
|
296
312
|
geoToGeo(
|
|
297
313
|
coordinates: number[][],
|
|
298
314
|
resolution: number = DEFAULT_RESOLUTION
|
|
299
|
-
):
|
|
315
|
+
): Position[] {
|
|
300
316
|
const {
|
|
301
317
|
poleCoordinates: { lat, lng },
|
|
302
318
|
azimuth,
|
|
@@ -320,47 +336,106 @@ export class Webdggrid {
|
|
|
320
336
|
yCoords
|
|
321
337
|
);
|
|
322
338
|
|
|
323
|
-
const size = resultArray.length/2;
|
|
324
|
-
const arrayOfArrays:number[][] = [];
|
|
339
|
+
const size = resultArray.length / 2;
|
|
340
|
+
const arrayOfArrays: number[][] = [];
|
|
325
341
|
for (let i = 0; i < size; i += 1) {
|
|
326
|
-
arrayOfArrays.push([resultArray[i], resultArray[i+size]]);
|
|
342
|
+
arrayOfArrays.push([resultArray[i], resultArray[i + size]]);
|
|
327
343
|
}
|
|
328
344
|
|
|
329
345
|
return arrayOfArrays;
|
|
330
346
|
}
|
|
331
347
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
+
/**
|
|
349
|
+
* Convert an array of sequence numbers to the grid coordinates with format of `[lng,lat]`. The output is an array with the same
|
|
350
|
+
* size as input `sequenceNum` and it includes an array of `CoordinateLike` objects.
|
|
351
|
+
* @param sequenceNum
|
|
352
|
+
* @param resolution [resolution=DEFAULT_RESOLUTION]
|
|
353
|
+
* @returns An array of [lng,lat]
|
|
354
|
+
*/
|
|
355
|
+
sequenceNumToGrid(
|
|
356
|
+
sequenceNum: bigint[],
|
|
357
|
+
resolution: number = DEFAULT_RESOLUTION
|
|
358
|
+
): Position[][] {
|
|
359
|
+
const {
|
|
360
|
+
poleCoordinates: { lat, lng },
|
|
361
|
+
azimuth,
|
|
362
|
+
topology,
|
|
363
|
+
projection,
|
|
364
|
+
aperture,
|
|
365
|
+
} = this.dggs;
|
|
348
366
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
367
|
+
let resultArray = [];
|
|
368
|
+
try {
|
|
369
|
+
resultArray = this._module.SeqNumGrid(
|
|
370
|
+
lat,
|
|
371
|
+
lng,
|
|
372
|
+
azimuth,
|
|
373
|
+
aperture,
|
|
374
|
+
resolution,
|
|
375
|
+
topology,
|
|
376
|
+
projection,
|
|
377
|
+
sequenceNum
|
|
378
|
+
);
|
|
379
|
+
} catch (e) {
|
|
380
|
+
console.error(this._module.getExceptionMessage(e).toString());
|
|
381
|
+
throw(e);
|
|
352
382
|
}
|
|
353
383
|
|
|
354
|
-
const
|
|
384
|
+
const inputSize = sequenceNum.length;
|
|
385
|
+
|
|
386
|
+
const allShapeVertexes = resultArray.slice(0, inputSize);
|
|
355
387
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
388
|
+
const sumVertexes = allShapeVertexes.reduce((accumulator, currentValue) => {
|
|
389
|
+
return accumulator + currentValue;
|
|
390
|
+
}, 0);
|
|
359
391
|
|
|
360
|
-
|
|
361
|
-
|
|
392
|
+
const featureSet: Position[][] = [];
|
|
393
|
+
|
|
394
|
+
let xOffset = inputSize;
|
|
395
|
+
let yOffset = inputSize + sumVertexes;
|
|
396
|
+
for (let i = 0; i < allShapeVertexes.length; i += 1) {
|
|
397
|
+
const numVertexes = allShapeVertexes[i];
|
|
398
|
+
|
|
399
|
+
const currentShapeXVertexes = resultArray.slice(xOffset, xOffset + numVertexes);
|
|
400
|
+
const currentShapeYVertexes = resultArray.slice(yOffset, yOffset + numVertexes);
|
|
401
|
+
|
|
402
|
+
const coordinates: Position[] = [];
|
|
403
|
+
for (let i = 0; i < numVertexes; i += 1) {
|
|
404
|
+
coordinates.push([currentShapeXVertexes[i], currentShapeYVertexes[i]]);
|
|
405
|
+
}
|
|
406
|
+
featureSet.push(coordinates);
|
|
407
|
+
xOffset += numVertexes;
|
|
408
|
+
yOffset += numVertexes;
|
|
362
409
|
}
|
|
363
|
-
};
|
|
364
410
|
|
|
365
|
-
|
|
411
|
+
return featureSet;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
sequenceNumToGridFeatureCollection(
|
|
415
|
+
sequenceNum: bigint[],
|
|
416
|
+
resolution: number = DEFAULT_RESOLUTION
|
|
417
|
+
): FeatureCollection<Polygon, DGGSGeoJsonProperty> {
|
|
418
|
+
|
|
419
|
+
const coordinatesArray = this.sequenceNumToGrid(sequenceNum, resolution);
|
|
420
|
+
|
|
421
|
+
const features = coordinatesArray.map((coordinates, index) => {
|
|
422
|
+
const seqNum = sequenceNum[index];
|
|
423
|
+
return {
|
|
424
|
+
type: 'Feature',
|
|
425
|
+
geometry: {
|
|
426
|
+
type: 'Polygon',
|
|
427
|
+
coordinates: [coordinates]
|
|
428
|
+
},
|
|
429
|
+
id: seqNum as unknown as number,
|
|
430
|
+
properties: {
|
|
431
|
+
id: seqNum
|
|
432
|
+
} as DGGSGeoJsonProperty
|
|
433
|
+
} as Feature<Polygon, DGGSGeoJsonProperty>;
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
return {
|
|
437
|
+
type: 'FeatureCollection',
|
|
438
|
+
features,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
366
441
|
}
|
package/types/webdggrid.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FeatureCollection, GeoJsonProperties, Polygon, Position } from 'geojson';
|
|
1
2
|
/**
|
|
2
3
|
* Cell Topology
|
|
3
4
|
*
|
|
@@ -20,10 +21,25 @@ export declare enum Projection {
|
|
|
20
21
|
'ISEA' = "ISEA",
|
|
21
22
|
'FULLER' = "FULLER"
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* A geographic coordinate
|
|
26
|
+
*/
|
|
23
27
|
export interface Coordinate {
|
|
24
28
|
lat: number;
|
|
25
29
|
lng: number;
|
|
26
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Geojson properties type.
|
|
33
|
+
* TODO: Better handeling the types
|
|
34
|
+
*/
|
|
35
|
+
export type DGGSGeoJsonProperty = GeoJsonProperties & {
|
|
36
|
+
/**
|
|
37
|
+
* It stores the seq number if exists
|
|
38
|
+
*/
|
|
39
|
+
id?: BigInt;
|
|
40
|
+
i?: BigInt;
|
|
41
|
+
j?: BigInt;
|
|
42
|
+
};
|
|
27
43
|
export interface IDGGSProps {
|
|
28
44
|
poleCoordinates: Coordinate;
|
|
29
45
|
azimuth: number;
|
|
@@ -102,17 +118,22 @@ export declare class Webdggrid {
|
|
|
102
118
|
* @param resolution [resolution=DEFAULT_RESOLUTION]
|
|
103
119
|
* @returns An array of [lng,lat]
|
|
104
120
|
*/
|
|
105
|
-
sequenceNumToGeo(sequenceNum: bigint[], resolution?: number):
|
|
121
|
+
sequenceNumToGeo(sequenceNum: bigint[], resolution?: number): Position[];
|
|
106
122
|
/**
|
|
107
123
|
* Converts a set of coordinates to the cell centroid values
|
|
108
124
|
* @param coordinates A 2d array of lng and lat values
|
|
109
125
|
* @param resolution [resolution=DEFAULT_RESOLUTION] The resolution of the dggs
|
|
110
126
|
* @returns An array of dggs cell centroid coordinates
|
|
111
127
|
*/
|
|
112
|
-
geoToGeo(coordinates: number[][], resolution?: number):
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
128
|
+
geoToGeo(coordinates: number[][], resolution?: number): Position[];
|
|
129
|
+
/**
|
|
130
|
+
* Convert an array of sequence numbers to the grid coordinates with format of `[lng,lat]`. The output is an array with the same
|
|
131
|
+
* size as input `sequenceNum` and it includes an array of `CoordinateLike` objects.
|
|
132
|
+
* @param sequenceNum
|
|
133
|
+
* @param resolution [resolution=DEFAULT_RESOLUTION]
|
|
134
|
+
* @returns An array of [lng,lat]
|
|
135
|
+
*/
|
|
136
|
+
sequenceNumToGrid(sequenceNum: bigint[], resolution?: number): Position[][];
|
|
137
|
+
sequenceNumToGridFeatureCollection(sequenceNum: bigint[], resolution?: number): FeatureCollection<Polygon, DGGSGeoJsonProperty>;
|
|
117
138
|
}
|
|
118
139
|
//# sourceMappingURL=webdggrid.d.ts.map
|
package/types/webdggrid.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webdggrid.d.ts","sourceRoot":"","sources":["../src-ts/webdggrid.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webdggrid.d.ts","sourceRoot":"","sources":["../src-ts/webdggrid.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,iBAAiB,EAAE,iBAAiB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC3F;;;;;GAKG;AACH,oBAAY,QAAQ;IAChB,SAAS,YAAY;IACrB,U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