@turf/isobands 6.5.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.
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Takes a {@link Point} grid and returns a correspondent matrix {Array<Array<number>>}
3
+ * of the 'property' values
4
+ *
5
+ * @name gridToMatrix
6
+ * @param {FeatureCollection<Point>} grid of points
7
+ * @param {Object} [options={}] Optional parameters
8
+ * @param {string} [options.zProperty='elevation'] the property name in `points` from which z-values will be pulled
9
+ * @param {boolean} [options.flip=false] returns the matrix upside-down
10
+ * @param {boolean} [options.flags=false] flags, adding a `matrixPosition` array field ([row, column]) to its properties,
11
+ * the grid points with coordinates on the matrix
12
+ * @returns {Array<Array<number>>} matrix of property values
13
+ * @example
14
+ * var extent = [-70.823364, -33.553984, -70.473175, -33.302986];
15
+ * var cellSize = 3;
16
+ * var grid = turf.pointGrid(extent, cellSize);
17
+ * // add a random property to each point between 0 and 60
18
+ * for (var i = 0; i < grid.features.length; i++) {
19
+ * grid.features[i].properties.elevation = (Math.random() * 60);
20
+ * }
21
+ * gridToMatrix(grid);
22
+ * //= [
23
+ * [ 1, 13, 10, 9, 10, 13, 18],
24
+ * [34, 8, 5, 4, 5, 8, 13],
25
+ * [10, 5, 2, 1, 2, 5, 4],
26
+ * [ 0, 4, 56, 19, 1, 4, 9],
27
+ * [10, 5, 2, 1, 2, 5, 10],
28
+ * [57, 8, 5, 4, 5, 0, 57],
29
+ * [ 3, 13, 10, 9, 5, 13, 18],
30
+ * [18, 13, 10, 9, 78, 13, 18]
31
+ * ]
32
+ */
33
+ export default function gridToMatrix(grid: any, options?: {
34
+ zProperty?: string;
35
+ flip?: boolean;
36
+ flags?: boolean;
37
+ } | undefined): number[][];
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const invariant_1 = require("@turf/invariant");
4
+ const meta_1 = require("@turf/meta");
5
+ const helpers_1 = require("@turf/helpers");
6
+ /**
7
+ * Takes a {@link Point} grid and returns a correspondent matrix {Array<Array<number>>}
8
+ * of the 'property' values
9
+ *
10
+ * @name gridToMatrix
11
+ * @param {FeatureCollection<Point>} grid of points
12
+ * @param {Object} [options={}] Optional parameters
13
+ * @param {string} [options.zProperty='elevation'] the property name in `points` from which z-values will be pulled
14
+ * @param {boolean} [options.flip=false] returns the matrix upside-down
15
+ * @param {boolean} [options.flags=false] flags, adding a `matrixPosition` array field ([row, column]) to its properties,
16
+ * the grid points with coordinates on the matrix
17
+ * @returns {Array<Array<number>>} matrix of property values
18
+ * @example
19
+ * var extent = [-70.823364, -33.553984, -70.473175, -33.302986];
20
+ * var cellSize = 3;
21
+ * var grid = turf.pointGrid(extent, cellSize);
22
+ * // add a random property to each point between 0 and 60
23
+ * for (var i = 0; i < grid.features.length; i++) {
24
+ * grid.features[i].properties.elevation = (Math.random() * 60);
25
+ * }
26
+ * gridToMatrix(grid);
27
+ * //= [
28
+ * [ 1, 13, 10, 9, 10, 13, 18],
29
+ * [34, 8, 5, 4, 5, 8, 13],
30
+ * [10, 5, 2, 1, 2, 5, 4],
31
+ * [ 0, 4, 56, 19, 1, 4, 9],
32
+ * [10, 5, 2, 1, 2, 5, 10],
33
+ * [57, 8, 5, 4, 5, 0, 57],
34
+ * [ 3, 13, 10, 9, 5, 13, 18],
35
+ * [18, 13, 10, 9, 78, 13, 18]
36
+ * ]
37
+ */
38
+ function gridToMatrix(grid, options) {
39
+ // Optional parameters
40
+ options = options || {};
41
+ if (!helpers_1.isObject(options))
42
+ throw new Error("options is invalid");
43
+ var zProperty = options.zProperty || "elevation";
44
+ var flip = options.flip;
45
+ var flags = options.flags;
46
+ // validation
47
+ invariant_1.collectionOf(grid, "Point", "input must contain Points");
48
+ var pointsMatrix = sortPointsByLatLng(grid, flip);
49
+ var matrix = [];
50
+ // create property matrix from sorted points
51
+ // looping order matters here
52
+ for (var r = 0; r < pointsMatrix.length; r++) {
53
+ var pointRow = pointsMatrix[r];
54
+ var row = [];
55
+ for (var c = 0; c < pointRow.length; c++) {
56
+ var point = pointRow[c];
57
+ // Check if zProperty exist
58
+ if (point.properties[zProperty])
59
+ row.push(point.properties[zProperty]);
60
+ else
61
+ row.push(0);
62
+ // add flags
63
+ if (flags === true)
64
+ point.properties.matrixPosition = [r, c];
65
+ }
66
+ matrix.push(row);
67
+ }
68
+ return matrix;
69
+ }
70
+ exports.default = gridToMatrix;
71
+ /**
72
+ * Sorts points by latitude and longitude, creating a 2-dimensional array of points
73
+ *
74
+ * @private
75
+ * @param {FeatureCollection<Point>} points GeoJSON Point features
76
+ * @param {boolean} [flip=false] returns the matrix upside-down
77
+ * @returns {Array<Array<Point>>} points ordered by latitude and longitude
78
+ */
79
+ function sortPointsByLatLng(points, flip) {
80
+ var pointsByLatitude = {};
81
+ // divide points by rows with the same latitude
82
+ meta_1.featureEach(points, function (point) {
83
+ var lat = invariant_1.getCoords(point)[1];
84
+ if (!pointsByLatitude[lat])
85
+ pointsByLatitude[lat] = [];
86
+ pointsByLatitude[lat].push(point);
87
+ });
88
+ // sort points (with the same latitude) by longitude
89
+ var orderedRowsByLatitude = Object.keys(pointsByLatitude).map(function (lat) {
90
+ var row = pointsByLatitude[lat];
91
+ var rowOrderedByLongitude = row.sort(function (a, b) {
92
+ return invariant_1.getCoords(a)[0] - invariant_1.getCoords(b)[0];
93
+ });
94
+ return rowOrderedByLongitude;
95
+ });
96
+ // sort rows (of points with the same latitude) by latitude
97
+ var pointMatrix = orderedRowsByLatitude.sort(function (a, b) {
98
+ if (flip)
99
+ return invariant_1.getCoords(a[0])[1] - invariant_1.getCoords(b[0])[1];
100
+ else
101
+ return invariant_1.getCoords(b[0])[1] - invariant_1.getCoords(a[0])[1];
102
+ });
103
+ return pointMatrix;
104
+ }
@@ -0,0 +1 @@
1
+ export default function isoBands(data: any, minV: any, bandwidth: any, options: any): any[];