@turf/isolines 6.4.0 → 7.0.0-alpha.0

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/js/index.js CHANGED
@@ -1,519 +1,12 @@
1
- 'use strict';
2
-
3
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
-
5
- var invariant = require('@turf/invariant');
6
- var meta = require('@turf/meta');
7
- var helpers = require('@turf/helpers');
8
- var bbox = _interopDefault(require('@turf/bbox'));
9
- var objectAssign = _interopDefault(require('object-assign'));
10
-
11
- /**
12
- * @license GNU Affero General Public License.
13
- * Copyright (c) 2015, 2015 Ronny Lorenz <ronny@tbi.univie.ac.at>
14
- * v. 1.2.0
15
- * https://github.com/RaumZeit/MarchingSquares.js
16
- *
17
- * MarchingSquaresJS is free software: you can redistribute it and/or modify
18
- * it under the terms of the GNU Affero General Public License as published by
19
- * the Free Software Foundation, either version 3 of the License, or
20
- * (at your option) any later version.
21
- *
22
- * MarchingSquaresJS is distributed in the hope that it will be useful,
23
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
- * GNU Affero General Public License for more details.
26
- *
27
- * As additional permission under GNU Affero General Public License version 3
28
- * section 7, third-party projects (personal or commercial) may distribute,
29
- * include, or link against UNMODIFIED VERSIONS of MarchingSquaresJS without the
30
- * requirement that said third-party project for that reason alone becomes
31
- * subject to any requirement of the GNU Affero General Public License version 3.
32
- * Any modifications to MarchingSquaresJS, however, must be shared with the public
33
- * and made available.
34
- *
35
- * In summary this:
36
- * - allows you to use MarchingSquaresJS at no cost
37
- * - allows you to use MarchingSquaresJS for both personal and commercial purposes
38
- * - allows you to distribute UNMODIFIED VERSIONS of MarchingSquaresJS under any
39
- * license as long as this license notice is included
40
- * - enables you to keep the source code of your program that uses MarchingSquaresJS
41
- * undisclosed
42
- * - forces you to share any modifications you have made to MarchingSquaresJS,
43
- * e.g. bug-fixes
44
- *
45
- * You should have received a copy of the GNU Affero General Public License
46
- * along with MarchingSquaresJS. If not, see <http://www.gnu.org/licenses/>.
47
- */
48
-
49
- /**
50
- * Compute the isocontour(s) of a scalar 2D field given
51
- * a certain threshold by applying the Marching Squares
52
- * Algorithm. The function returns a list of path coordinates
53
- */
54
- var defaultSettings = {
55
- successCallback: null,
56
- verbose: false,
57
- };
58
-
59
- var settings = {};
60
-
61
- function isoContours(data, threshold, options) {
62
- /* process options */
63
- options = options ? options : {};
64
-
65
- var optionKeys = Object.keys(defaultSettings);
66
-
67
- for (var i = 0; i < optionKeys.length; i++) {
68
- var key = optionKeys[i];
69
- var val = options[key];
70
- val =
71
- typeof val !== "undefined" && val !== null ? val : defaultSettings[key];
72
-
73
- settings[key] = val;
74
- }
75
-
76
- if (settings.verbose)
77
- console.log(
78
- "MarchingSquaresJS-isoContours: computing isocontour for " + threshold
79
- );
80
-
81
- var ret = contourGrid2Paths(computeContourGrid(data, threshold));
82
-
83
- if (typeof settings.successCallback === "function")
84
- settings.successCallback(ret);
85
-
86
- return ret;
87
- }
88
-
89
- /*
90
- Thats all for the public interface, below follows the actual
91
- implementation
92
- */
93
-
94
- /*
95
- ################################
96
- Isocontour implementation below
97
- ################################
98
- */
99
-
100
- /* assume that x1 == 1 && x0 == 0 */
101
- function interpolateX(y, y0, y1) {
102
- return (y - y0) / (y1 - y0);
103
- }
104
-
105
- /* compute the isocontour 4-bit grid */
106
- function computeContourGrid(data, threshold) {
107
- var rows = data.length - 1;
108
- var cols = data[0].length - 1;
109
- var ContourGrid = { rows: rows, cols: cols, cells: [] };
110
-
111
- for (var j = 0; j < rows; ++j) {
112
- ContourGrid.cells[j] = [];
113
- for (var i = 0; i < cols; ++i) {
114
- /* compose the 4-bit corner representation */
115
- var cval = 0;
116
-
117
- var tl = data[j + 1][i];
118
- var tr = data[j + 1][i + 1];
119
- var br = data[j][i + 1];
120
- var bl = data[j][i];
121
-
122
- if (isNaN(tl) || isNaN(tr) || isNaN(br) || isNaN(bl)) {
123
- continue;
124
- }
125
- cval |= tl >= threshold ? 8 : 0;
126
- cval |= tr >= threshold ? 4 : 0;
127
- cval |= br >= threshold ? 2 : 0;
128
- cval |= bl >= threshold ? 1 : 0;
129
-
130
- /* resolve ambiguity for cval == 5 || 10 via averaging */
131
- var flipped = false;
132
- if (cval === 5 || cval === 10) {
133
- var average = (tl + tr + br + bl) / 4;
134
- if (cval === 5 && average < threshold) {
135
- cval = 10;
136
- flipped = true;
137
- } else if (cval === 10 && average < threshold) {
138
- cval = 5;
139
- flipped = true;
140
- }
141
- }
142
-
143
- /* add cell to ContourGrid if it contains edges */
144
- if (cval !== 0 && cval !== 15) {
145
- var top, bottom, left, right;
146
- top = bottom = left = right = 0.5;
147
- /* interpolate edges of cell */
148
- if (cval === 1) {
149
- left = 1 - interpolateX(threshold, tl, bl);
150
- bottom = 1 - interpolateX(threshold, br, bl);
151
- } else if (cval === 2) {
152
- bottom = interpolateX(threshold, bl, br);
153
- right = 1 - interpolateX(threshold, tr, br);
154
- } else if (cval === 3) {
155
- left = 1 - interpolateX(threshold, tl, bl);
156
- right = 1 - interpolateX(threshold, tr, br);
157
- } else if (cval === 4) {
158
- top = interpolateX(threshold, tl, tr);
159
- right = interpolateX(threshold, br, tr);
160
- } else if (cval === 5) {
161
- top = interpolateX(threshold, tl, tr);
162
- right = interpolateX(threshold, br, tr);
163
- bottom = 1 - interpolateX(threshold, br, bl);
164
- left = 1 - interpolateX(threshold, tl, bl);
165
- } else if (cval === 6) {
166
- bottom = interpolateX(threshold, bl, br);
167
- top = interpolateX(threshold, tl, tr);
168
- } else if (cval === 7) {
169
- left = 1 - interpolateX(threshold, tl, bl);
170
- top = interpolateX(threshold, tl, tr);
171
- } else if (cval === 8) {
172
- left = interpolateX(threshold, bl, tl);
173
- top = 1 - interpolateX(threshold, tr, tl);
174
- } else if (cval === 9) {
175
- bottom = 1 - interpolateX(threshold, br, bl);
176
- top = 1 - interpolateX(threshold, tr, tl);
177
- } else if (cval === 10) {
178
- top = 1 - interpolateX(threshold, tr, tl);
179
- right = 1 - interpolateX(threshold, tr, br);
180
- bottom = interpolateX(threshold, bl, br);
181
- left = interpolateX(threshold, bl, tl);
182
- } else if (cval === 11) {
183
- top = 1 - interpolateX(threshold, tr, tl);
184
- right = 1 - interpolateX(threshold, tr, br);
185
- } else if (cval === 12) {
186
- left = interpolateX(threshold, bl, tl);
187
- right = interpolateX(threshold, br, tr);
188
- } else if (cval === 13) {
189
- bottom = 1 - interpolateX(threshold, br, bl);
190
- right = interpolateX(threshold, br, tr);
191
- } else if (cval === 14) {
192
- left = interpolateX(threshold, bl, tl);
193
- bottom = interpolateX(threshold, bl, br);
194
- } else {
195
- console.log(
196
- "MarchingSquaresJS-isoContours: Illegal cval detected: " + cval
197
- );
198
- }
199
- ContourGrid.cells[j][i] = {
200
- cval: cval,
201
- flipped: flipped,
202
- top: top,
203
- right: right,
204
- bottom: bottom,
205
- left: left,
206
- };
207
- }
208
- }
209
- }
210
-
211
- return ContourGrid;
212
- }
213
-
214
- function isSaddle(cell) {
215
- return cell.cval === 5 || cell.cval === 10;
216
- }
217
-
218
- function isTrivial(cell) {
219
- return cell.cval === 0 || cell.cval === 15;
220
- }
221
-
222
- function clearCell(cell) {
223
- if (!isTrivial(cell) && cell.cval !== 5 && cell.cval !== 10) {
224
- cell.cval = 15;
225
- }
226
- }
227
-
228
- function getXY(cell, edge) {
229
- if (edge === "top") {
230
- return [cell.top, 1.0];
231
- } else if (edge === "bottom") {
232
- return [cell.bottom, 0.0];
233
- } else if (edge === "right") {
234
- return [1.0, cell.right];
235
- } else if (edge === "left") {
236
- return [0.0, cell.left];
237
- }
238
- }
239
-
240
- function contourGrid2Paths(grid) {
241
- var paths = [];
242
- var path_idx = 0;
243
- var epsilon = 1e-7;
244
-
245
- grid.cells.forEach(function (g, j) {
246
- g.forEach(function (gg, i) {
247
- if (typeof gg !== "undefined" && !isSaddle(gg) && !isTrivial(gg)) {
248
- var p = tracePath(grid.cells, j, i);
249
- var merged = false;
250
- /* we may try to merge paths at this point */
251
- if (p.info === "mergeable") {
252
- /*
253
- search backwards through the path array to find an entry
254
- that starts with where the current path ends...
255
- */
256
- var x = p.path[p.path.length - 1][0],
257
- y = p.path[p.path.length - 1][1];
258
-
259
- for (var k = path_idx - 1; k >= 0; k--) {
260
- if (
261
- Math.abs(paths[k][0][0] - x) <= epsilon &&
262
- Math.abs(paths[k][0][1] - y) <= epsilon
263
- ) {
264
- for (var l = p.path.length - 2; l >= 0; --l) {
265
- paths[k].unshift(p.path[l]);
266
- }
267
- merged = true;
268
- break;
269
- }
270
- }
271
- }
272
- if (!merged) paths[path_idx++] = p.path;
273
- }
274
- });
275
- });
276
-
277
- return paths;
278
- }
279
-
280
- /*
281
- construct consecutive line segments from starting cell by
282
- walking arround the enclosed area clock-wise
283
- */
284
- function tracePath(grid, j, i) {
285
- var maxj = grid.length;
286
- var p = [];
287
- var dxContour = [0, 0, 1, 1, 0, 0, 0, 0, -1, 0, 1, 1, -1, 0, -1, 0];
288
- var dyContour = [0, -1, 0, 0, 1, 1, 1, 1, 0, -1, 0, 0, 0, -1, 0, 0];
289
- var dx, dy;
290
- var startEdge = [
291
- "none",
292
- "left",
293
- "bottom",
294
- "left",
295
- "right",
296
- "none",
297
- "bottom",
298
- "left",
299
- "top",
300
- "top",
301
- "none",
302
- "top",
303
- "right",
304
- "right",
305
- "bottom",
306
- "none",
307
- ];
308
- var nextEdge = [
309
- "none",
310
- "bottom",
311
- "right",
312
- "right",
313
- "top",
314
- "top",
315
- "top",
316
- "top",
317
- "left",
318
- "bottom",
319
- "right",
320
- "right",
321
- "left",
322
- "bottom",
323
- "left",
324
- "none",
325
- ];
326
- var edge;
327
-
328
- var currentCell = grid[j][i];
329
-
330
- var cval = currentCell.cval;
331
- var edge = startEdge[cval];
332
-
333
- var pt = getXY(currentCell, edge);
334
-
335
- /* push initial segment */
336
- p.push([i + pt[0], j + pt[1]]);
337
- edge = nextEdge[cval];
338
- pt = getXY(currentCell, edge);
339
- p.push([i + pt[0], j + pt[1]]);
340
- clearCell(currentCell);
341
-
342
- /* now walk arround the enclosed area in clockwise-direction */
343
- var k = i + dxContour[cval];
344
- var l = j + dyContour[cval];
345
- var prev_cval = cval;
346
-
347
- while (k >= 0 && l >= 0 && l < maxj && (k != i || l != j)) {
348
- currentCell = grid[l][k];
349
- if (typeof currentCell === "undefined") {
350
- /* path ends here */
351
- //console.log(k + " " + l + " is undefined, stopping path!");
352
- break;
353
- }
354
- cval = currentCell.cval;
355
- if (cval === 0 || cval === 15) {
356
- return { path: p, info: "mergeable" };
357
- }
358
- edge = nextEdge[cval];
359
- dx = dxContour[cval];
360
- dy = dyContour[cval];
361
- if (cval === 5 || cval === 10) {
362
- /* select upper or lower band, depending on previous cells cval */
363
- if (cval === 5) {
364
- if (currentCell.flipped) {
365
- /* this is actually a flipped case 10 */
366
- if (dyContour[prev_cval] === -1) {
367
- edge = "left";
368
- dx = -1;
369
- dy = 0;
370
- } else {
371
- edge = "right";
372
- dx = 1;
373
- dy = 0;
374
- }
375
- } else {
376
- /* real case 5 */
377
- if (dxContour[prev_cval] === -1) {
378
- edge = "bottom";
379
- dx = 0;
380
- dy = -1;
381
- }
382
- }
383
- } else if (cval === 10) {
384
- if (currentCell.flipped) {
385
- /* this is actually a flipped case 5 */
386
- if (dxContour[prev_cval] === -1) {
387
- edge = "top";
388
- dx = 0;
389
- dy = 1;
390
- } else {
391
- edge = "bottom";
392
- dx = 0;
393
- dy = -1;
394
- }
395
- } else {
396
- /* real case 10 */
397
- if (dyContour[prev_cval] === 1) {
398
- edge = "left";
399
- dx = -1;
400
- dy = 0;
401
- }
402
- }
403
- }
404
- }
405
- pt = getXY(currentCell, edge);
406
- p.push([k + pt[0], l + pt[1]]);
407
- clearCell(currentCell);
408
- k += dx;
409
- l += dy;
410
- prev_cval = cval;
411
- }
412
-
413
- return { path: p, info: "closed" };
414
- }
415
-
416
- /**
417
- * Takes a {@link Point} grid and returns a correspondent matrix {Array<Array<number>>}
418
- * of the 'property' values
419
- *
420
- * @name gridToMatrix
421
- * @param {FeatureCollection<Point>} grid of points
422
- * @param {Object} [options={}] Optional parameters
423
- * @param {string} [options.zProperty='elevation'] the property name in `points` from which z-values will be pulled
424
- * @param {boolean} [options.flip=false] returns the matrix upside-down
425
- * @param {boolean} [options.flags=false] flags, adding a `matrixPosition` array field ([row, column]) to its properties,
426
- * the grid points with coordinates on the matrix
427
- * @returns {Array<Array<number>>} matrix of property values
428
- * @example
429
- * var extent = [-70.823364, -33.553984, -70.473175, -33.302986];
430
- * var cellSize = 3;
431
- * var grid = turf.pointGrid(extent, cellSize);
432
- * // add a random property to each point between 0 and 60
433
- * for (var i = 0; i < grid.features.length; i++) {
434
- * grid.features[i].properties.elevation = (Math.random() * 60);
435
- * }
436
- * gridToMatrix(grid);
437
- * //= [
438
- * [ 1, 13, 10, 9, 10, 13, 18],
439
- * [34, 8, 5, 4, 5, 8, 13],
440
- * [10, 5, 2, 1, 2, 5, 4],
441
- * [ 0, 4, 56, 19, 1, 4, 9],
442
- * [10, 5, 2, 1, 2, 5, 10],
443
- * [57, 8, 5, 4, 5, 0, 57],
444
- * [ 3, 13, 10, 9, 5, 13, 18],
445
- * [18, 13, 10, 9, 78, 13, 18]
446
- * ]
447
- */
448
- function gridToMatrix(grid, options) {
449
- // Optional parameters
450
- options = options || {};
451
- if (!helpers.isObject(options)) throw new Error("options is invalid");
452
- var zProperty = options.zProperty || "elevation";
453
- var flip = options.flip;
454
- var flags = options.flags;
455
-
456
- // validation
457
- invariant.collectionOf(grid, "Point", "input must contain Points");
458
-
459
- var pointsMatrix = sortPointsByLatLng(grid, flip);
460
-
461
- var matrix = [];
462
- // create property matrix from sorted points
463
- // looping order matters here
464
- for (var r = 0; r < pointsMatrix.length; r++) {
465
- var pointRow = pointsMatrix[r];
466
- var row = [];
467
- for (var c = 0; c < pointRow.length; c++) {
468
- var point = pointRow[c];
469
- // Check if zProperty exist
470
- if (point.properties[zProperty]) row.push(point.properties[zProperty]);
471
- else row.push(0);
472
- // add flags
473
- if (flags === true) point.properties.matrixPosition = [r, c];
474
- }
475
- matrix.push(row);
476
- }
477
-
478
- return matrix;
479
- }
480
-
481
- /**
482
- * Sorts points by latitude and longitude, creating a 2-dimensional array of points
483
- *
484
- * @private
485
- * @param {FeatureCollection<Point>} points GeoJSON Point features
486
- * @param {boolean} [flip=false] returns the matrix upside-down
487
- * @returns {Array<Array<Point>>} points ordered by latitude and longitude
488
- */
489
- function sortPointsByLatLng(points, flip) {
490
- var pointsByLatitude = {};
491
-
492
- // divide points by rows with the same latitude
493
- meta.featureEach(points, function (point) {
494
- var lat = invariant.getCoords(point)[1];
495
- if (!pointsByLatitude[lat]) pointsByLatitude[lat] = [];
496
- pointsByLatitude[lat].push(point);
497
- });
498
-
499
- // sort points (with the same latitude) by longitude
500
- var orderedRowsByLatitude = Object.keys(pointsByLatitude).map(function (lat) {
501
- var row = pointsByLatitude[lat];
502
- var rowOrderedByLongitude = row.sort(function (a, b) {
503
- return invariant.getCoords(a)[0] - invariant.getCoords(b)[0];
504
- });
505
- return rowOrderedByLongitude;
506
- });
507
-
508
- // sort rows (of points with the same latitude) by latitude
509
- var pointMatrix = orderedRowsByLatitude.sort(function (a, b) {
510
- if (flip) return invariant.getCoords(a[0])[1] - invariant.getCoords(b[0])[1];
511
- else return invariant.getCoords(b[0])[1] - invariant.getCoords(a[0])[1];
512
- });
513
-
514
- return pointMatrix;
515
- }
516
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const bbox_1 = tslib_1.__importDefault(require("@turf/bbox"));
5
+ const meta_1 = require("@turf/meta");
6
+ const invariant_1 = require("@turf/invariant");
7
+ const helpers_1 = require("@turf/helpers");
8
+ const marchingsquares_isocontours_1 = tslib_1.__importDefault(require("./lib/marchingsquares-isocontours"));
9
+ const grid_to_matrix_1 = tslib_1.__importDefault(require("./lib/grid-to-matrix"));
517
10
  /**
518
11
  * Takes a grid {@link FeatureCollection} of {@link Point} features with z-values and an array of
519
12
  * value breaks and generates [isolines](https://en.wikipedia.org/wiki/Contour_line).
@@ -544,36 +37,29 @@ function sortPointsByLatLng(points, flip) {
544
37
  * var addToMap = [lines];
545
38
  */
546
39
  function isolines(pointGrid, breaks, options) {
547
- // Optional parameters
548
- options = options || {};
549
- if (!helpers.isObject(options)) throw new Error("options is invalid");
550
- var zProperty = options.zProperty || "elevation";
551
- var commonProperties = options.commonProperties || {};
552
- var breaksProperties = options.breaksProperties || [];
553
-
554
- // Input validation
555
- invariant.collectionOf(pointGrid, "Point", "Input must contain Points");
556
- if (!breaks) throw new Error("breaks is required");
557
- if (!Array.isArray(breaks)) throw new Error("breaks must be an Array");
558
- if (!helpers.isObject(commonProperties))
559
- throw new Error("commonProperties must be an Object");
560
- if (!Array.isArray(breaksProperties))
561
- throw new Error("breaksProperties must be an Array");
562
-
563
- // Isoline methods
564
- var matrix = gridToMatrix(pointGrid, { zProperty: zProperty, flip: true });
565
- var createdIsoLines = createIsoLines(
566
- matrix,
567
- breaks,
568
- zProperty,
569
- commonProperties,
570
- breaksProperties
571
- );
572
- var scaledIsolines = rescaleIsolines(createdIsoLines, matrix, pointGrid);
573
-
574
- return helpers.featureCollection(scaledIsolines);
40
+ // Optional parameters
41
+ options = options || {};
42
+ if (!helpers_1.isObject(options))
43
+ throw new Error("options is invalid");
44
+ const zProperty = options.zProperty || "elevation";
45
+ const commonProperties = options.commonProperties || {};
46
+ const breaksProperties = options.breaksProperties || [];
47
+ // Input validation
48
+ invariant_1.collectionOf(pointGrid, "Point", "Input must contain Points");
49
+ if (!breaks)
50
+ throw new Error("breaks is required");
51
+ if (!Array.isArray(breaks))
52
+ throw new Error("breaks must be an Array");
53
+ if (!helpers_1.isObject(commonProperties))
54
+ throw new Error("commonProperties must be an Object");
55
+ if (!Array.isArray(breaksProperties))
56
+ throw new Error("breaksProperties must be an Array");
57
+ // Isoline methods
58
+ const matrix = grid_to_matrix_1.default(pointGrid, { zProperty: zProperty, flip: true });
59
+ const createdIsoLines = createIsoLines(matrix, breaks, zProperty, commonProperties, breaksProperties);
60
+ const scaledIsolines = rescaleIsolines(createdIsoLines, matrix, pointGrid);
61
+ return helpers_1.featureCollection(scaledIsolines);
575
62
  }
576
-
577
63
  /**
578
64
  * Creates the isolines lines (featuresCollection of MultiLineString features) from the 2D data grid
579
65
  *
@@ -583,32 +69,23 @@ function isolines(pointGrid, breaks, options) {
583
69
  *
584
70
  * @private
585
71
  * @param {Array<Array<number>>} matrix Grid Data
586
- * @param {Array<number>} breaks Breaks
72
+ * @param {Array<number>} breaks BreakProps
587
73
  * @param {string} zProperty name of the z-values property
588
74
  * @param {Object} [commonProperties={}] GeoJSON properties passed to ALL isolines
589
75
  * @param {Object} [breaksProperties=[]] GeoJSON properties passed to the correspondent isoline
590
76
  * @returns {Array<MultiLineString>} isolines
591
77
  */
592
- function createIsoLines(
593
- matrix,
594
- breaks,
595
- zProperty,
596
- commonProperties,
597
- breaksProperties
598
- ) {
599
- var results = [];
600
- for (var i = 1; i < breaks.length; i++) {
601
- var threshold = +breaks[i]; // make sure it's a number
602
-
603
- var properties = objectAssign({}, commonProperties, breaksProperties[i]);
604
- properties[zProperty] = threshold;
605
- var isoline = helpers.multiLineString(isoContours(matrix, threshold), properties);
606
-
607
- results.push(isoline);
608
- }
609
- return results;
78
+ function createIsoLines(matrix, breaks, zProperty, commonProperties, breaksProperties) {
79
+ const results = [];
80
+ for (let i = 1; i < breaks.length; i++) {
81
+ const threshold = +breaks[i]; // make sure it's a number
82
+ const properties = Object.assign(Object.assign({}, commonProperties), breaksProperties[i]);
83
+ properties[zProperty] = threshold;
84
+ const isoline = helpers_1.multiLineString(marchingsquares_isocontours_1.default(matrix, threshold), properties);
85
+ results.push(isoline);
86
+ }
87
+ return results;
610
88
  }
611
-
612
89
  /**
613
90
  * Translates and scales isolines
614
91
  *
@@ -619,33 +96,27 @@ function createIsoLines(
619
96
  * @returns {Array<MultiLineString>} isolines
620
97
  */
621
98
  function rescaleIsolines(createdIsoLines, matrix, points) {
622
- // get dimensions (on the map) of the original grid
623
- var gridBbox = bbox(points); // [ minX, minY, maxX, maxY ]
624
- var originalWidth = gridBbox[2] - gridBbox[0];
625
- var originalHeigth = gridBbox[3] - gridBbox[1];
626
-
627
- // get origin, which is the first point of the last row on the rectangular data on the map
628
- var x0 = gridBbox[0];
629
- var y0 = gridBbox[1];
630
-
631
- // get number of cells per side
632
- var matrixWidth = matrix[0].length - 1;
633
- var matrixHeight = matrix.length - 1;
634
-
635
- // calculate the scaling factor between matrix and rectangular grid on the map
636
- var scaleX = originalWidth / matrixWidth;
637
- var scaleY = originalHeigth / matrixHeight;
638
-
639
- var resize = function (point) {
640
- point[0] = point[0] * scaleX + x0;
641
- point[1] = point[1] * scaleY + y0;
642
- };
643
-
644
- // resize and shift each point/line of the createdIsoLines
645
- createdIsoLines.forEach(function (isoline) {
646
- meta.coordEach(isoline, resize);
647
- });
648
- return createdIsoLines;
99
+ // get dimensions (on the map) of the original grid
100
+ const gridBbox = bbox_1.default(points); // [ minX, minY, maxX, maxY ]
101
+ const originalWidth = gridBbox[2] - gridBbox[0];
102
+ const originalHeigth = gridBbox[3] - gridBbox[1];
103
+ // get origin, which is the first point of the last row on the rectangular data on the map
104
+ const x0 = gridBbox[0];
105
+ const y0 = gridBbox[1];
106
+ // get number of cells per side
107
+ const matrixWidth = matrix[0].length - 1;
108
+ const matrixHeight = matrix.length - 1;
109
+ // calculate the scaling factor between matrix and rectangular grid on the map
110
+ const scaleX = originalWidth / matrixWidth;
111
+ const scaleY = originalHeigth / matrixHeight;
112
+ const resize = (point) => {
113
+ point[0] = point[0] * scaleX + x0;
114
+ point[1] = point[1] * scaleY + y0;
115
+ };
116
+ // resize and shift each point/line of the createdIsoLines
117
+ createdIsoLines.forEach((isoline) => {
118
+ meta_1.coordEach(isoline, resize);
119
+ });
120
+ return createdIsoLines;
649
121
  }
650
-
651
- module.exports = isolines;
122
+ exports.default = isolines;