@turf/isobands 7.0.0 → 7.1.0-alpha.7
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/cjs/index.cjs +0 -10
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +0 -10
- package/dist/esm/index.js.map +1 -1
- package/package.json +14 -14
package/dist/cjs/index.cjs
CHANGED
|
@@ -14,7 +14,6 @@ var __spreadValues = (a, b) => {
|
|
|
14
14
|
}
|
|
15
15
|
return a;
|
|
16
16
|
};
|
|
17
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
18
17
|
|
|
19
18
|
// index.ts
|
|
20
19
|
var _bbox = require('@turf/bbox');
|
|
@@ -59,7 +58,6 @@ function gridToMatrix(grid, options) {
|
|
|
59
58
|
}
|
|
60
59
|
return matrix;
|
|
61
60
|
}
|
|
62
|
-
__name(gridToMatrix, "gridToMatrix");
|
|
63
61
|
function sortPointsByLatLng(points, flip) {
|
|
64
62
|
var pointsByLatitude = {};
|
|
65
63
|
_meta.featureEach.call(void 0, points, function(point) {
|
|
@@ -83,7 +81,6 @@ function sortPointsByLatLng(points, flip) {
|
|
|
83
81
|
});
|
|
84
82
|
return pointMatrix;
|
|
85
83
|
}
|
|
86
|
-
__name(sortPointsByLatLng, "sortPointsByLatLng");
|
|
87
84
|
|
|
88
85
|
// index.ts
|
|
89
86
|
var _marchingsquares = require('marchingsquares');
|
|
@@ -120,7 +117,6 @@ function isobands(pointGrid, breaks, options) {
|
|
|
120
117
|
});
|
|
121
118
|
return _helpers.featureCollection.call(void 0, multipolygons);
|
|
122
119
|
}
|
|
123
|
-
__name(isobands, "isobands");
|
|
124
120
|
function createContourLines(matrix, breaks, property) {
|
|
125
121
|
const contours = [];
|
|
126
122
|
for (let i = 1; i < breaks.length; i++) {
|
|
@@ -136,7 +132,6 @@ function createContourLines(matrix, breaks, property) {
|
|
|
136
132
|
}
|
|
137
133
|
return contours;
|
|
138
134
|
}
|
|
139
|
-
__name(createContourLines, "createContourLines");
|
|
140
135
|
function rescaleContours(contours, matrix, points) {
|
|
141
136
|
const gridBbox = _bbox.bbox.call(void 0, points);
|
|
142
137
|
const originalWidth = gridBbox[2] - gridBbox[0];
|
|
@@ -161,7 +156,6 @@ function rescaleContours(contours, matrix, points) {
|
|
|
161
156
|
return contour;
|
|
162
157
|
});
|
|
163
158
|
}
|
|
164
|
-
__name(rescaleContours, "rescaleContours");
|
|
165
159
|
function orderByArea(ringsCoords) {
|
|
166
160
|
const ringsWithArea = ringsCoords.map(function(coords) {
|
|
167
161
|
return { ring: coords, area: _area.area.call(void 0, _helpers.polygon.call(void 0, [coords])) };
|
|
@@ -173,7 +167,6 @@ function orderByArea(ringsCoords) {
|
|
|
173
167
|
return x.ring;
|
|
174
168
|
});
|
|
175
169
|
}
|
|
176
|
-
__name(orderByArea, "orderByArea");
|
|
177
170
|
function groupNestedRings(orderedLinearRings) {
|
|
178
171
|
const lrList = orderedLinearRings.map((lr) => {
|
|
179
172
|
return { lrCoordinates: lr, grouped: false };
|
|
@@ -201,7 +194,6 @@ function groupNestedRings(orderedLinearRings) {
|
|
|
201
194
|
}
|
|
202
195
|
return groupedLinearRingsCoords;
|
|
203
196
|
}
|
|
204
|
-
__name(groupNestedRings, "groupNestedRings");
|
|
205
197
|
function isInside(testPolygon, targetPolygon) {
|
|
206
198
|
const points = _explode.explode.call(void 0, testPolygon);
|
|
207
199
|
for (let i = 0; i < points.features.length; i++) {
|
|
@@ -211,7 +203,6 @@ function isInside(testPolygon, targetPolygon) {
|
|
|
211
203
|
}
|
|
212
204
|
return true;
|
|
213
205
|
}
|
|
214
|
-
__name(isInside, "isInside");
|
|
215
206
|
function allGrouped(list) {
|
|
216
207
|
for (let i = 0; i < list.length; i++) {
|
|
217
208
|
if (list[i].grouped === false) {
|
|
@@ -220,7 +211,6 @@ function allGrouped(list) {
|
|
|
220
211
|
}
|
|
221
212
|
return true;
|
|
222
213
|
}
|
|
223
|
-
__name(allGrouped, "allGrouped");
|
|
224
214
|
var turf_isobands_default = isobands;
|
|
225
215
|
|
|
226
216
|
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts","../../lib/grid-to-matrix.js"],"names":["collectionOf","isObject"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,6BAA6B;AACtC,SAAS,eAAe;AACxB,SAAS,gBAAAA,qBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAAC;AAAA,OACK;;;ACVP,SAAS,WAAW,oBAAoB;AACxC,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAkCzB,SAAS,aAAa,MAAM,SAAS;AAEnC,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,MAAI,YAAY,QAAQ,aAAa;AACrC,MAAI,OAAO,QAAQ;AACnB,MAAI,QAAQ,QAAQ;AAGpB,eAAa,MAAM,SAAS,2BAA2B;AAEvD,MAAI,eAAe,mBAAmB,MAAM,IAAI;AAEhD,MAAI,SAAS,CAAC;AAGd,WAAS,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;AAC5C,QAAI,WAAW,aAAa,CAAC;AAC7B,QAAI,MAAM,CAAC;AACX,aAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;AACxC,UAAI,QAAQ,SAAS,CAAC;AAEtB,UAAI,MAAM,WAAW,SAAS;AAAG,YAAI,KAAK,MAAM,WAAW,SAAS,CAAC;AAAA;AAChE,YAAI,KAAK,CAAC;AAEf,UAAI,UAAU;AAAM,cAAM,WAAW,iBAAiB,CAAC,GAAG,CAAC;AAAA,IAC7D;AACA,WAAO,KAAK,GAAG;AAAA,EACjB;AAEA,SAAO;AACT;AA/BS;AAyCT,SAAS,mBAAmB,QAAQ,MAAM;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EAAE,aAAa;AAClC,eAAO,CAAC,EAAE,UAAU;AACpB,cAAM,gBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;AAEvD,iBAAS,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AAC1C,cAAI,CAAC,OAAO,CAAC,EAAE,SAAS;AACtB,kBAAM,SAAS,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;AAChD,gBAAI,SAAS,QAAQ,aAAa,GAAG;AACnC,oBAAM,KAAK,OAAO,CAAC,EAAE,aAAa;AAClC,qBAAO,CAAC,EAAE,UAAU;AAAA,YACtB;AAAA,UACF;AAAA,QACF;AAEA,iCAAyB,KAAK,KAAK;AAAA,MACrC;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AA/BS;AAuCT,SAAS,SACP,aACA,eACS;AACT,QAAM,SAAS,QAAQ,WAAW;AAClC,WAAS,IAAI,GAAG,IAAI,OAAO,SAAS,QAAQ,KAAK;AAC/C,QAAI,CAAC,sBAAsB,OAAO,SAAS,CAAC,GAAG,aAAa,GAAG;AAC7D,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAXS;AAkBT,SAAS,WACP,MACS;AACT,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,QAAI,KAAK,CAAC,EAAE,YAAY,OAAO;AAC7B,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AATS;AAYT,IAAO,wBAAQ","sourcesContent":["import { bbox } from \"@turf/bbox\";\nimport { area } from \"@turf/area\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { explode } from \"@turf/explode\";\nimport { collectionOf } from \"@turf/invariant\";\nimport {\n polygon,\n multiPolygon,\n featureCollection,\n isObject,\n} from \"@turf/helpers\";\n\nimport {\n FeatureCollection,\n Point,\n GeoJsonProperties,\n MultiPolygon,\n Position,\n Polygon,\n Feature,\n} from \"geojson\";\n\nimport { gridToMatrix } from \"./lib/grid-to-matrix.js\";\nimport { isoBands } from \"marchingsquares\";\n\ntype GroupRingProps = { [prop: string]: string };\ntype GroupedRings =\n | {\n groupedRings: Position[][][];\n }\n | GroupRingProps;\n\n/**\n * Takes a square or rectangular grid {@link FeatureCollection} of {@link Point} features with z-values and an array of\n * value breaks and generates filled contour isobands.\n *\n * @name isobands\n * @param {FeatureCollection<Point>} pointGrid input points - must be square or rectangular\n * @param {Array<number>} breaks where to draw contours\n * @param {Object} [options={}] options on output\n * @param {string} [options.zProperty='elevation'] the property name in `points` from which z-values will be pulled\n * @param {Object} [options.commonProperties={}] GeoJSON properties passed to ALL isobands\n * @param {Array<Object>} [options.breaksProperties=[]] GeoJSON properties passed, in order, to the correspondent isoband (order defined by breaks)\n * @returns {FeatureCollection<MultiPolygon>} a FeatureCollection of {@link MultiPolygon} features representing isobands\n */\nfunction isobands(\n pointGrid: FeatureCollection<Point>,\n breaks: number[],\n options?: {\n zProperty?: string;\n commonProperties?: GeoJsonProperties;\n breaksProperties?: GeoJsonProperties[];\n }\n): FeatureCollection<MultiPolygon> {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const zProperty = options.zProperty || \"elevation\";\n const commonProperties = options.commonProperties || {};\n const breaksProperties = options.breaksProperties || [];\n\n // Validation\n collectionOf(pointGrid, \"Point\", \"Input must contain Points\");\n if (!breaks) throw new Error(\"breaks is required\");\n if (!Array.isArray(breaks)) throw new Error(\"breaks is not an Array\");\n if (!isObject(commonProperties))\n throw new Error(\"commonProperties is not an Object\");\n if (!Array.isArray(breaksProperties))\n throw new Error(\"breaksProperties is not an Array\");\n\n // Isoband methods\n const matrix = gridToMatrix(pointGrid, { zProperty: zProperty, flip: true });\n let contours = createContourLines(matrix, breaks, zProperty);\n contours = rescaleContours(contours, matrix, pointGrid);\n\n const multipolygons = contours.map((contour, index) => {\n if (breaksProperties[index] && !isObject(breaksProperties[index])) {\n throw new Error(\"Each mappedProperty is required to be an Object\");\n }\n // collect all properties\n const contourProperties = {\n ...commonProperties,\n ...breaksProperties[index],\n };\n\n contourProperties[zProperty] = (contour as GroupRingProps)[zProperty];\n\n const multiP = multiPolygon(\n contour.groupedRings as Position[][][],\n contourProperties\n );\n return multiP;\n });\n\n return featureCollection(multipolygons);\n}\n\n/**\n * Creates the contours lines (featuresCollection of polygon features) from the 2D data grid\n *\n * Marchingsquares process the grid data as a 3D representation of a function on a 2D plane, therefore it\n * assumes the points (x-y coordinates) are one 'unit' distance. The result of the IsoBands function needs to be\n * rescaled, with turfjs, to the original area and proportions on the map\n *\n * @private\n * @param {Array<Array<number>>} matrix Grid Data\n * @param {Array<number>} breaks Breaks\n * @param {string} [property='elevation'] Property\n * @returns {Array<any>} contours\n */\nfunction createContourLines(\n matrix: number[][],\n breaks: number[],\n property: string\n): GroupedRings[] {\n const contours: GroupedRings[] = [];\n for (let i = 1; i < breaks.length; i++) {\n const lowerBand = +breaks[i - 1]; // make sure the breaks value is a number\n const upperBand = +breaks[i];\n\n const isobandsCoords = isoBands(matrix, lowerBand, upperBand - lowerBand);\n // as per GeoJson rules for creating a Polygon, make sure the first element\n // in the array of LinearRings represents the exterior ring (i.e. biggest area),\n // and any subsequent elements represent interior rings (i.e. smaller area);\n // this avoids rendering issues of the MultiPolygons on the map\n const nestedRings = orderByArea(isobandsCoords);\n const groupedRings = groupNestedRings(nestedRings);\n\n contours.push({\n groupedRings: groupedRings as Position[][][],\n [property]: lowerBand + \"-\" + upperBand,\n });\n }\n return contours;\n}\n\n/**\n * Transform isobands of 2D grid to polygons for the map\n *\n * @private\n * @param {Array<any>} contours Contours\n * @param {Array<Array<number>>} matrix Grid Data\n * @param {Object} points Points by Latitude\n * @returns {Array<any>} contours\n */\nfunction rescaleContours(\n contours: GroupedRings[],\n matrix: number[][],\n points: FeatureCollection<Point>\n): GroupedRings[] {\n // get dimensions (on the map) of the original grid\n const gridBbox = bbox(points); // [ minX, minY, maxX, maxY ]\n const originalWidth = gridBbox[2] - gridBbox[0];\n const originalHeigth = gridBbox[3] - gridBbox[1];\n\n // get origin, which is the first point of the last row on the rectangular data on the map\n const x0 = gridBbox[0];\n const y0 = gridBbox[1];\n // get number of cells per side\n const matrixWidth = matrix[0].length - 1;\n const matrixHeight = matrix.length - 1;\n // calculate the scaling factor between matrix and rectangular grid on the map\n const scaleX = originalWidth / matrixWidth;\n const scaleY = originalHeigth / matrixHeight;\n\n // resize and shift each point/line of the isobands\n return contours.map(function (contour) {\n contour.groupedRings = (contour.groupedRings as Position[][][]).map(\n function (lineRingSet) {\n return lineRingSet.map(function (lineRing) {\n return lineRing.map((point: Position) => [\n point[0] * scaleX + x0,\n point[1] * scaleY + y0,\n ]);\n });\n }\n );\n\n return contour;\n });\n}\n\n/* utility functions */\n\n/**\n * Returns an array of coordinates (of LinearRings) in descending order by area\n *\n * @private\n * @param {Array<LineString>} ringsCoords array of closed LineString\n * @returns {Array} array of the input LineString ordered by area\n */\nfunction orderByArea(ringsCoords: Position[][]): Position[][] {\n const ringsWithArea = ringsCoords.map(function (coords) {\n // associate each lineRing with its area\n return { ring: coords, area: area(polygon([coords])) };\n });\n ringsWithArea.sort(function (a, b) {\n // bigger --> smaller\n return b.area - a.area;\n });\n // create a new array of linearRings coordinates ordered by their area\n return ringsWithArea.map(function (x) {\n return x.ring;\n });\n}\n\n/**\n * Returns an array of arrays of coordinates, each representing\n * a set of (coordinates of) nested LinearRings,\n * i.e. the first ring contains all the others\n *\n * @private\n * @param {Array} orderedLinearRings array of coordinates (of LinearRings) in descending order by area\n * @returns {Array<Array>} Array of coordinates of nested LinearRings\n */\nfunction groupNestedRings(orderedLinearRings: Position[][]): Position[][][] {\n // create a list of the (coordinates of) LinearRings\n const lrList = orderedLinearRings.map((lr) => {\n return { lrCoordinates: lr, grouped: false };\n });\n const groupedLinearRingsCoords: Position[][][] = [];\n\n while (!allGrouped(lrList)) {\n for (let i = 0; i < lrList.length; i++) {\n if (!lrList[i].grouped) {\n // create new group starting with the larger not already grouped ring\n const group: Position[][] = [];\n group.push(lrList[i].lrCoordinates);\n lrList[i].grouped = true;\n const outerMostPoly = polygon([lrList[i].lrCoordinates]);\n // group all the rings contained by the outermost ring\n for (let j = i + 1; j < lrList.length; j++) {\n if (!lrList[j].grouped) {\n const lrPoly = polygon([lrList[j].lrCoordinates]);\n if (isInside(lrPoly, outerMostPoly)) {\n group.push(lrList[j].lrCoordinates);\n lrList[j].grouped = true;\n }\n }\n }\n // insert the new group\n groupedLinearRingsCoords.push(group);\n }\n }\n }\n return groupedLinearRingsCoords;\n}\n\n/**\n * @private\n * @param {Polygon} testPolygon polygon of interest\n * @param {Polygon} targetPolygon polygon you want to compare with\n * @returns {boolean} true if test-Polygon is inside target-Polygon\n */\nfunction isInside(\n testPolygon: Feature<Polygon>,\n targetPolygon: Feature<Polygon>\n): boolean {\n const points = explode(testPolygon);\n for (let i = 0; i < points.features.length; i++) {\n if (!booleanPointInPolygon(points.features[i], targetPolygon)) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * @private\n * @param {Array<Object>} list list of objects which might contain the 'group' attribute\n * @returns {boolean} true if all the objects in the list are marked as grouped\n */\nfunction allGrouped(\n list: { grouped: boolean; lrCoordinates: Position[] }[]\n): boolean {\n for (let i = 0; i < list.length; i++) {\n if (list[i].grouped === false) {\n return false;\n }\n }\n return true;\n}\n\nexport { isobands };\nexport default isobands;\n","import { getCoords, collectionOf } from \"@turf/invariant\";\nimport { featureEach } from \"@turf/meta\";\nimport { isObject } from \"@turf/helpers\";\n\n/**\n * Takes a {@link Point} grid and returns a correspondent matrix {Array<Array<number>>}\n * of the 'property' values\n *\n * @name gridToMatrix\n * @param {FeatureCollection<Point>} grid of points\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.zProperty='elevation'] the property name in `points` from which z-values will be pulled\n * @param {boolean} [options.flip=false] returns the matrix upside-down\n * @param {boolean} [options.flags=false] flags, adding a `matrixPosition` array field ([row, column]) to its properties,\n * the grid points with coordinates on the matrix\n * @returns {Array<Array<number>>} matrix of property values\n * @example\n * var extent = [-70.823364, -33.553984, -70.473175, -33.302986];\n * var cellSize = 3;\n * var grid = turf.pointGrid(extent, cellSize);\n * // add a random property to each point between 0 and 60\n * for (var i = 0; i < grid.features.length; i++) {\n * grid.features[i].properties.elevation = (Math.random() * 60);\n * }\n * gridToMatrix(grid);\n * //= [\n * [ 1, 13, 10, 9, 10, 13, 18],\n * [34, 8, 5, 4, 5, 8, 13],\n * [10, 5, 2, 1, 2, 5, 4],\n * [ 0, 4, 56, 19, 1, 4, 9],\n * [10, 5, 2, 1, 2, 5, 10],\n * [57, 8, 5, 4, 5, 0, 57],\n * [ 3, 13, 10, 9, 5, 13, 18],\n * [18, 13, 10, 9, 78, 13, 18]\n * ]\n */\nfunction gridToMatrix(grid, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var zProperty = options.zProperty || \"elevation\";\n var flip = options.flip;\n var flags = options.flags;\n\n // validation\n collectionOf(grid, \"Point\", \"input must contain Points\");\n\n var pointsMatrix = sortPointsByLatLng(grid, flip);\n\n var matrix = [];\n // create property matrix from sorted points\n // looping order matters here\n for (var r = 0; r < pointsMatrix.length; r++) {\n var pointRow = pointsMatrix[r];\n var row = [];\n for (var c = 0; c < pointRow.length; c++) {\n var point = pointRow[c];\n // Check if zProperty exist\n if (point.properties[zProperty]) row.push(point.properties[zProperty]);\n else row.push(0);\n // add flags\n if (flags === true) point.properties.matrixPosition = [r, c];\n }\n matrix.push(row);\n }\n\n return matrix;\n}\n\n/**\n * Sorts points by latitude and longitude, creating a 2-dimensional array of points\n *\n * @private\n * @param {FeatureCollection<Point>} points GeoJSON Point features\n * @param {boolean} [flip=false] returns the matrix upside-down\n * @returns {Array<Array<Point>>} points ordered by latitude and longitude\n */\nfunction sortPointsByLatLng(points, flip) {\n var pointsByLatitude = {};\n\n // divide points by rows with the same latitude\n featureEach(points, function (point) {\n var lat = getCoords(point)[1];\n if (!pointsByLatitude[lat]) pointsByLatitude[lat] = [];\n pointsByLatitude[lat].push(point);\n });\n\n // sort points (with the same latitude) by longitude\n var orderedRowsByLatitude = Object.keys(pointsByLatitude).map(function (lat) {\n var row = pointsByLatitude[lat];\n var rowOrderedByLongitude = row.sort(function (a, b) {\n return getCoords(a)[0] - getCoords(b)[0];\n });\n return rowOrderedByLongitude;\n });\n\n // sort rows (of points with the same latitude) by latitude\n var pointMatrix = orderedRowsByLatitude.sort(function (a, b) {\n if (flip) return getCoords(a[0])[1] - getCoords(b[0])[1];\n else return getCoords(b[0])[1] - getCoords(a[0])[1];\n });\n\n return pointMatrix;\n}\n\nexport { gridToMatrix };\nexport default gridToMatrix;\n"]}
|
|
1
|
+
{"version":3,"sources":["../../index.ts","../../lib/grid-to-matrix.js"],"names":["collectionOf","isObject"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,6BAA6B;AACtC,SAAS,eAAe;AACxB,SAAS,gBAAAA,qBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAAC;AAAA,OACK;;;ACVP,SAAS,WAAW,oBAAoB;AACxC,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAkCzB,SAAS,aAAa,MAAM,SAAS;AAEnC,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,MAAI,YAAY,QAAQ,aAAa;AACrC,MAAI,OAAO,QAAQ;AACnB,MAAI,QAAQ,QAAQ;AAGpB,eAAa,MAAM,SAAS,2BAA2B;AAEvD,MAAI,eAAe,mBAAmB,MAAM,IAAI;AAEhD,MAAI,SAAS,CAAC;AAGd,WAAS,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;AAC5C,QAAI,WAAW,aAAa,CAAC;AAC7B,QAAI,MAAM,CAAC;AACX,aAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;AACxC,UAAI,QAAQ,SAAS,C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AAAA,EAC7C,CAAC;AACD,QAAM,2BAA2C,CAAC;AAElD,SAAO,CAAC,WAAW,MAAM,GAAG;AAC1B,aAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,UAAI,CAAC,OAAO,CAAC,EAAE,SAAS;AAEtB,cAAM,QAAsB,CAAC;AAC7B,cAAM,KAAK,OAAO,CAAC,EAAE,aAAa;AAClC,eAAO,CAAC,EAAE,UAAU;AACpB,cAAM,gBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;AAEvD,iBAAS,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AAC1C,cAAI,CAAC,OAAO,CAAC,EAAE,SAAS;AACtB,kBAAM,SAAS,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;AAChD,gBAAI,SAAS,QAAQ,aAAa,GAAG;AACnC,oBAAM,KAAK,OAAO,CAAC,EAAE,aAAa;AAClC,qBAAO,CAAC,EAAE,UAAU;AAAA,YACtB;AAAA,UACF;AAAA,QACF;AAEA,iCAAyB,KAAK,KAAK;AAAA,MACrC;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAQA,SAAS,SACP,aACA,eACS;AACT,QAAM,SAAS,QAAQ,WAAW;AAClC,WAAS,IAAI,GAAG,IAAI,OAAO,SAAS,QAAQ,KAAK;AAC/C,QAAI,CAAC,sBAAsB,OAAO,SAAS,CAAC,GAAG,aAAa,GAAG;AAC7D,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAOA,SAAS,WACP,MACS;AACT,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,QAAI,KAAK,CAAC,EAAE,YAAY,OAAO;AAC7B,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAGA,IAAO,wBAAQ","sourcesContent":["import { bbox } from \"@turf/bbox\";\nimport { area } from \"@turf/area\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { explode } from \"@turf/explode\";\nimport { collectionOf } from \"@turf/invariant\";\nimport {\n polygon,\n multiPolygon,\n featureCollection,\n isObject,\n} from \"@turf/helpers\";\n\nimport {\n FeatureCollection,\n Point,\n GeoJsonProperties,\n MultiPolygon,\n Position,\n Polygon,\n Feature,\n} from \"geojson\";\n\nimport { gridToMatrix } from \"./lib/grid-to-matrix.js\";\nimport { isoBands } from \"marchingsquares\";\n\ntype GroupRingProps = { [prop: string]: string };\ntype GroupedRings =\n | {\n groupedRings: Position[][][];\n }\n | GroupRingProps;\n\n/**\n * Takes a square or rectangular grid {@link FeatureCollection} of {@link Point} features with z-values and an array of\n * value breaks and generates filled contour isobands.\n *\n * @name isobands\n * @param {FeatureCollection<Point>} pointGrid input points - must be square or rectangular\n * @param {Array<number>} breaks where to draw contours\n * @param {Object} [options={}] options on output\n * @param {string} [options.zProperty='elevation'] the property name in `points` from which z-values will be pulled\n * @param {Object} [options.commonProperties={}] GeoJSON properties passed to ALL isobands\n * @param {Array<Object>} [options.breaksProperties=[]] GeoJSON properties passed, in order, to the correspondent isoband (order defined by breaks)\n * @returns {FeatureCollection<MultiPolygon>} a FeatureCollection of {@link MultiPolygon} features representing isobands\n */\nfunction isobands(\n pointGrid: FeatureCollection<Point>,\n breaks: number[],\n options?: {\n zProperty?: string;\n commonProperties?: GeoJsonProperties;\n breaksProperties?: GeoJsonProperties[];\n }\n): FeatureCollection<MultiPolygon> {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const zProperty = options.zProperty || \"elevation\";\n const commonProperties = options.commonProperties || {};\n const breaksProperties = options.breaksProperties || [];\n\n // Validation\n collectionOf(pointGrid, \"Point\", \"Input must contain Points\");\n if (!breaks) throw new Error(\"breaks is required\");\n if (!Array.isArray(breaks)) throw new Error(\"breaks is not an Array\");\n if (!isObject(commonProperties))\n throw new Error(\"commonProperties is not an Object\");\n if (!Array.isArray(breaksProperties))\n throw new Error(\"breaksProperties is not an Array\");\n\n // Isoband methods\n const matrix = gridToMatrix(pointGrid, { zProperty: zProperty, flip: true });\n let contours = createContourLines(matrix, breaks, zProperty);\n contours = rescaleContours(contours, matrix, pointGrid);\n\n const multipolygons = contours.map((contour, index) => {\n if (breaksProperties[index] && !isObject(breaksProperties[index])) {\n throw new Error(\"Each mappedProperty is required to be an Object\");\n }\n // collect all properties\n const contourProperties = {\n ...commonProperties,\n ...breaksProperties[index],\n };\n\n contourProperties[zProperty] = (contour as GroupRingProps)[zProperty];\n\n const multiP = multiPolygon(\n contour.groupedRings as Position[][][],\n contourProperties\n );\n return multiP;\n });\n\n return featureCollection(multipolygons);\n}\n\n/**\n * Creates the contours lines (featuresCollection of polygon features) from the 2D data grid\n *\n * Marchingsquares process the grid data as a 3D representation of a function on a 2D plane, therefore it\n * assumes the points (x-y coordinates) are one 'unit' distance. The result of the IsoBands function needs to be\n * rescaled, with turfjs, to the original area and proportions on the map\n *\n * @private\n * @param {Array<Array<number>>} matrix Grid Data\n * @param {Array<number>} breaks Breaks\n * @param {string} [property='elevation'] Property\n * @returns {Array<any>} contours\n */\nfunction createContourLines(\n matrix: number[][],\n breaks: number[],\n property: string\n): GroupedRings[] {\n const contours: GroupedRings[] = [];\n for (let i = 1; i < breaks.length; i++) {\n const lowerBand = +breaks[i - 1]; // make sure the breaks value is a number\n const upperBand = +breaks[i];\n\n const isobandsCoords = isoBands(matrix, lowerBand, upperBand - lowerBand);\n // as per GeoJson rules for creating a Polygon, make sure the first element\n // in the array of LinearRings represents the exterior ring (i.e. biggest area),\n // and any subsequent elements represent interior rings (i.e. smaller area);\n // this avoids rendering issues of the MultiPolygons on the map\n const nestedRings = orderByArea(isobandsCoords);\n const groupedRings = groupNestedRings(nestedRings);\n\n contours.push({\n groupedRings: groupedRings as Position[][][],\n [property]: lowerBand + \"-\" + upperBand,\n });\n }\n return contours;\n}\n\n/**\n * Transform isobands of 2D grid to polygons for the map\n *\n * @private\n * @param {Array<any>} contours Contours\n * @param {Array<Array<number>>} matrix Grid Data\n * @param {Object} points Points by Latitude\n * @returns {Array<any>} contours\n */\nfunction rescaleContours(\n contours: GroupedRings[],\n matrix: number[][],\n points: FeatureCollection<Point>\n): GroupedRings[] {\n // get dimensions (on the map) of the original grid\n const gridBbox = bbox(points); // [ minX, minY, maxX, maxY ]\n const originalWidth = gridBbox[2] - gridBbox[0];\n const originalHeigth = gridBbox[3] - gridBbox[1];\n\n // get origin, which is the first point of the last row on the rectangular data on the map\n const x0 = gridBbox[0];\n const y0 = gridBbox[1];\n // get number of cells per side\n const matrixWidth = matrix[0].length - 1;\n const matrixHeight = matrix.length - 1;\n // calculate the scaling factor between matrix and rectangular grid on the map\n const scaleX = originalWidth / matrixWidth;\n const scaleY = originalHeigth / matrixHeight;\n\n // resize and shift each point/line of the isobands\n return contours.map(function (contour) {\n contour.groupedRings = (contour.groupedRings as Position[][][]).map(\n function (lineRingSet) {\n return lineRingSet.map(function (lineRing) {\n return lineRing.map((point: Position) => [\n point[0] * scaleX + x0,\n point[1] * scaleY + y0,\n ]);\n });\n }\n );\n\n return contour;\n });\n}\n\n/* utility functions */\n\n/**\n * Returns an array of coordinates (of LinearRings) in descending order by area\n *\n * @private\n * @param {Array<LineString>} ringsCoords array of closed LineString\n * @returns {Array} array of the input LineString ordered by area\n */\nfunction orderByArea(ringsCoords: Position[][]): Position[][] {\n const ringsWithArea = ringsCoords.map(function (coords) {\n // associate each lineRing with its area\n return { ring: coords, area: area(polygon([coords])) };\n });\n ringsWithArea.sort(function (a, b) {\n // bigger --> smaller\n return b.area - a.area;\n });\n // create a new array of linearRings coordinates ordered by their area\n return ringsWithArea.map(function (x) {\n return x.ring;\n });\n}\n\n/**\n * Returns an array of arrays of coordinates, each representing\n * a set of (coordinates of) nested LinearRings,\n * i.e. the first ring contains all the others\n *\n * @private\n * @param {Array} orderedLinearRings array of coordinates (of LinearRings) in descending order by area\n * @returns {Array<Array>} Array of coordinates of nested LinearRings\n */\nfunction groupNestedRings(orderedLinearRings: Position[][]): Position[][][] {\n // create a list of the (coordinates of) LinearRings\n const lrList = orderedLinearRings.map((lr) => {\n return { lrCoordinates: lr, grouped: false };\n });\n const groupedLinearRingsCoords: Position[][][] = [];\n\n while (!allGrouped(lrList)) {\n for (let i = 0; i < lrList.length; i++) {\n if (!lrList[i].grouped) {\n // create new group starting with the larger not already grouped ring\n const group: Position[][] = [];\n group.push(lrList[i].lrCoordinates);\n lrList[i].grouped = true;\n const outerMostPoly = polygon([lrList[i].lrCoordinates]);\n // group all the rings contained by the outermost ring\n for (let j = i + 1; j < lrList.length; j++) {\n if (!lrList[j].grouped) {\n const lrPoly = polygon([lrList[j].lrCoordinates]);\n if (isInside(lrPoly, outerMostPoly)) {\n group.push(lrList[j].lrCoordinates);\n lrList[j].grouped = true;\n }\n }\n }\n // insert the new group\n groupedLinearRingsCoords.push(group);\n }\n }\n }\n return groupedLinearRingsCoords;\n}\n\n/**\n * @private\n * @param {Polygon} testPolygon polygon of interest\n * @param {Polygon} targetPolygon polygon you want to compare with\n * @returns {boolean} true if test-Polygon is inside target-Polygon\n */\nfunction isInside(\n testPolygon: Feature<Polygon>,\n targetPolygon: Feature<Polygon>\n): boolean {\n const points = explode(testPolygon);\n for (let i = 0; i < points.features.length; i++) {\n if (!booleanPointInPolygon(points.features[i], targetPolygon)) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * @private\n * @param {Array<Object>} list list of objects which might contain the 'group' attribute\n * @returns {boolean} true if all the objects in the list are marked as grouped\n */\nfunction allGrouped(\n list: { grouped: boolean; lrCoordinates: Position[] }[]\n): boolean {\n for (let i = 0; i < list.length; i++) {\n if (list[i].grouped === false) {\n return false;\n }\n }\n return true;\n}\n\nexport { isobands };\nexport default isobands;\n","import { getCoords, collectionOf } from \"@turf/invariant\";\nimport { featureEach } from \"@turf/meta\";\nimport { isObject } from \"@turf/helpers\";\n\n/**\n * Takes a {@link Point} grid and returns a correspondent matrix {Array<Array<number>>}\n * of the 'property' values\n *\n * @name gridToMatrix\n * @param {FeatureCollection<Point>} grid of points\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.zProperty='elevation'] the property name in `points` from which z-values will be pulled\n * @param {boolean} [options.flip=false] returns the matrix upside-down\n * @param {boolean} [options.flags=false] flags, adding a `matrixPosition` array field ([row, column]) to its properties,\n * the grid points with coordinates on the matrix\n * @returns {Array<Array<number>>} matrix of property values\n * @example\n * var extent = [-70.823364, -33.553984, -70.473175, -33.302986];\n * var cellSize = 3;\n * var grid = turf.pointGrid(extent, cellSize);\n * // add a random property to each point between 0 and 60\n * for (var i = 0; i < grid.features.length; i++) {\n * grid.features[i].properties.elevation = (Math.random() * 60);\n * }\n * gridToMatrix(grid);\n * //= [\n * [ 1, 13, 10, 9, 10, 13, 18],\n * [34, 8, 5, 4, 5, 8, 13],\n * [10, 5, 2, 1, 2, 5, 4],\n * [ 0, 4, 56, 19, 1, 4, 9],\n * [10, 5, 2, 1, 2, 5, 10],\n * [57, 8, 5, 4, 5, 0, 57],\n * [ 3, 13, 10, 9, 5, 13, 18],\n * [18, 13, 10, 9, 78, 13, 18]\n * ]\n */\nfunction gridToMatrix(grid, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var zProperty = options.zProperty || \"elevation\";\n var flip = options.flip;\n var flags = options.flags;\n\n // validation\n collectionOf(grid, \"Point\", \"input must contain Points\");\n\n var pointsMatrix = sortPointsByLatLng(grid, flip);\n\n var matrix = [];\n // create property matrix from sorted points\n // looping order matters here\n for (var r = 0; r < pointsMatrix.length; r++) {\n var pointRow = pointsMatrix[r];\n var row = [];\n for (var c = 0; c < pointRow.length; c++) {\n var point = pointRow[c];\n // Check if zProperty exist\n if (point.properties[zProperty]) row.push(point.properties[zProperty]);\n else row.push(0);\n // add flags\n if (flags === true) point.properties.matrixPosition = [r, c];\n }\n matrix.push(row);\n }\n\n return matrix;\n}\n\n/**\n * Sorts points by latitude and longitude, creating a 2-dimensional array of points\n *\n * @private\n * @param {FeatureCollection<Point>} points GeoJSON Point features\n * @param {boolean} [flip=false] returns the matrix upside-down\n * @returns {Array<Array<Point>>} points ordered by latitude and longitude\n */\nfunction sortPointsByLatLng(points, flip) {\n var pointsByLatitude = {};\n\n // divide points by rows with the same latitude\n featureEach(points, function (point) {\n var lat = getCoords(point)[1];\n if (!pointsByLatitude[lat]) pointsByLatitude[lat] = [];\n pointsByLatitude[lat].push(point);\n });\n\n // sort points (with the same latitude) by longitude\n var orderedRowsByLatitude = Object.keys(pointsByLatitude).map(function (lat) {\n var row = pointsByLatitude[lat];\n var rowOrderedByLongitude = row.sort(function (a, b) {\n return getCoords(a)[0] - getCoords(b)[0];\n });\n return rowOrderedByLongitude;\n });\n\n // sort rows (of points with the same latitude) by latitude\n var pointMatrix = orderedRowsByLatitude.sort(function (a, b) {\n if (flip) return getCoords(a[0])[1] - getCoords(b[0])[1];\n else return getCoords(b[0])[1] - getCoords(a[0])[1];\n });\n\n return pointMatrix;\n}\n\nexport { gridToMatrix };\nexport default gridToMatrix;\n"]}
|
package/dist/esm/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var __spreadValues = (a, b) => {
|
|
|
14
14
|
}
|
|
15
15
|
return a;
|
|
16
16
|
};
|
|
17
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
18
17
|
|
|
19
18
|
// index.ts
|
|
20
19
|
import { bbox } from "@turf/bbox";
|
|
@@ -59,7 +58,6 @@ function gridToMatrix(grid, options) {
|
|
|
59
58
|
}
|
|
60
59
|
return matrix;
|
|
61
60
|
}
|
|
62
|
-
__name(gridToMatrix, "gridToMatrix");
|
|
63
61
|
function sortPointsByLatLng(points, flip) {
|
|
64
62
|
var pointsByLatitude = {};
|
|
65
63
|
featureEach(points, function(point) {
|
|
@@ -83,7 +81,6 @@ function sortPointsByLatLng(points, flip) {
|
|
|
83
81
|
});
|
|
84
82
|
return pointMatrix;
|
|
85
83
|
}
|
|
86
|
-
__name(sortPointsByLatLng, "sortPointsByLatLng");
|
|
87
84
|
|
|
88
85
|
// index.ts
|
|
89
86
|
import { isoBands } from "marchingsquares";
|
|
@@ -120,7 +117,6 @@ function isobands(pointGrid, breaks, options) {
|
|
|
120
117
|
});
|
|
121
118
|
return featureCollection(multipolygons);
|
|
122
119
|
}
|
|
123
|
-
__name(isobands, "isobands");
|
|
124
120
|
function createContourLines(matrix, breaks, property) {
|
|
125
121
|
const contours = [];
|
|
126
122
|
for (let i = 1; i < breaks.length; i++) {
|
|
@@ -136,7 +132,6 @@ function createContourLines(matrix, breaks, property) {
|
|
|
136
132
|
}
|
|
137
133
|
return contours;
|
|
138
134
|
}
|
|
139
|
-
__name(createContourLines, "createContourLines");
|
|
140
135
|
function rescaleContours(contours, matrix, points) {
|
|
141
136
|
const gridBbox = bbox(points);
|
|
142
137
|
const originalWidth = gridBbox[2] - gridBbox[0];
|
|
@@ -161,7 +156,6 @@ function rescaleContours(contours, matrix, points) {
|
|
|
161
156
|
return contour;
|
|
162
157
|
});
|
|
163
158
|
}
|
|
164
|
-
__name(rescaleContours, "rescaleContours");
|
|
165
159
|
function orderByArea(ringsCoords) {
|
|
166
160
|
const ringsWithArea = ringsCoords.map(function(coords) {
|
|
167
161
|
return { ring: coords, area: area(polygon([coords])) };
|
|
@@ -173,7 +167,6 @@ function orderByArea(ringsCoords) {
|
|
|
173
167
|
return x.ring;
|
|
174
168
|
});
|
|
175
169
|
}
|
|
176
|
-
__name(orderByArea, "orderByArea");
|
|
177
170
|
function groupNestedRings(orderedLinearRings) {
|
|
178
171
|
const lrList = orderedLinearRings.map((lr) => {
|
|
179
172
|
return { lrCoordinates: lr, grouped: false };
|
|
@@ -201,7 +194,6 @@ function groupNestedRings(orderedLinearRings) {
|
|
|
201
194
|
}
|
|
202
195
|
return groupedLinearRingsCoords;
|
|
203
196
|
}
|
|
204
|
-
__name(groupNestedRings, "groupNestedRings");
|
|
205
197
|
function isInside(testPolygon, targetPolygon) {
|
|
206
198
|
const points = explode(testPolygon);
|
|
207
199
|
for (let i = 0; i < points.features.length; i++) {
|
|
@@ -211,7 +203,6 @@ function isInside(testPolygon, targetPolygon) {
|
|
|
211
203
|
}
|
|
212
204
|
return true;
|
|
213
205
|
}
|
|
214
|
-
__name(isInside, "isInside");
|
|
215
206
|
function allGrouped(list) {
|
|
216
207
|
for (let i = 0; i < list.length; i++) {
|
|
217
208
|
if (list[i].grouped === false) {
|
|
@@ -220,7 +211,6 @@ function allGrouped(list) {
|
|
|
220
211
|
}
|
|
221
212
|
return true;
|
|
222
213
|
}
|
|
223
|
-
__name(allGrouped, "allGrouped");
|
|
224
214
|
var turf_isobands_default = isobands;
|
|
225
215
|
export {
|
|
226
216
|
turf_isobands_default as default,
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts","../../lib/grid-to-matrix.js"],"sourcesContent":["import { bbox } from \"@turf/bbox\";\nimport { area } from \"@turf/area\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { explode } from \"@turf/explode\";\nimport { collectionOf } from \"@turf/invariant\";\nimport {\n polygon,\n multiPolygon,\n featureCollection,\n isObject,\n} from \"@turf/helpers\";\n\nimport {\n FeatureCollection,\n Point,\n GeoJsonProperties,\n MultiPolygon,\n Position,\n Polygon,\n Feature,\n} from \"geojson\";\n\nimport { gridToMatrix } from \"./lib/grid-to-matrix.js\";\nimport { isoBands } from \"marchingsquares\";\n\ntype GroupRingProps = { [prop: string]: string };\ntype GroupedRings =\n | {\n groupedRings: Position[][][];\n }\n | GroupRingProps;\n\n/**\n * Takes a square or rectangular grid {@link FeatureCollection} of {@link Point} features with z-values and an array of\n * value breaks and generates filled contour isobands.\n *\n * @name isobands\n * @param {FeatureCollection<Point>} pointGrid input points - must be square or rectangular\n * @param {Array<number>} breaks where to draw contours\n * @param {Object} [options={}] options on output\n * @param {string} [options.zProperty='elevation'] the property name in `points` from which z-values will be pulled\n * @param {Object} [options.commonProperties={}] GeoJSON properties passed to ALL isobands\n * @param {Array<Object>} [options.breaksProperties=[]] GeoJSON properties passed, in order, to the correspondent isoband (order defined by breaks)\n * @returns {FeatureCollection<MultiPolygon>} a FeatureCollection of {@link MultiPolygon} features representing isobands\n */\nfunction isobands(\n pointGrid: FeatureCollection<Point>,\n breaks: number[],\n options?: {\n zProperty?: string;\n commonProperties?: GeoJsonProperties;\n breaksProperties?: GeoJsonProperties[];\n }\n): FeatureCollection<MultiPolygon> {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const zProperty = options.zProperty || \"elevation\";\n const commonProperties = options.commonProperties || {};\n const breaksProperties = options.breaksProperties || [];\n\n // Validation\n collectionOf(pointGrid, \"Point\", \"Input must contain Points\");\n if (!breaks) throw new Error(\"breaks is required\");\n if (!Array.isArray(breaks)) throw new Error(\"breaks is not an Array\");\n if (!isObject(commonProperties))\n throw new Error(\"commonProperties is not an Object\");\n if (!Array.isArray(breaksProperties))\n throw new Error(\"breaksProperties is not an Array\");\n\n // Isoband methods\n const matrix = gridToMatrix(pointGrid, { zProperty: zProperty, flip: true });\n let contours = createContourLines(matrix, breaks, zProperty);\n contours = rescaleContours(contours, matrix, pointGrid);\n\n const multipolygons = contours.map((contour, index) => {\n if (breaksProperties[index] && !isObject(breaksProperties[index])) {\n throw new Error(\"Each mappedProperty is required to be an Object\");\n }\n // collect all properties\n const contourProperties = {\n ...commonProperties,\n ...breaksProperties[index],\n };\n\n contourProperties[zProperty] = (contour as GroupRingProps)[zProperty];\n\n const multiP = multiPolygon(\n contour.groupedRings as Position[][][],\n contourProperties\n );\n return multiP;\n });\n\n return featureCollection(multipolygons);\n}\n\n/**\n * Creates the contours lines (featuresCollection of polygon features) from the 2D data grid\n *\n * Marchingsquares process the grid data as a 3D representation of a function on a 2D plane, therefore it\n * assumes the points (x-y coordinates) are one 'unit' distance. The result of the IsoBands function needs to be\n * rescaled, with turfjs, to the original area and proportions on the map\n *\n * @private\n * @param {Array<Array<number>>} matrix Grid Data\n * @param {Array<number>} breaks Breaks\n * @param {string} [property='elevation'] Property\n * @returns {Array<any>} contours\n */\nfunction createContourLines(\n matrix: number[][],\n breaks: number[],\n property: string\n): GroupedRings[] {\n const contours: GroupedRings[] = [];\n for (let i = 1; i < breaks.length; i++) {\n const lowerBand = +breaks[i - 1]; // make sure the breaks value is a number\n const upperBand = +breaks[i];\n\n const isobandsCoords = isoBands(matrix, lowerBand, upperBand - lowerBand);\n // as per GeoJson rules for creating a Polygon, make sure the first element\n // in the array of LinearRings represents the exterior ring (i.e. biggest area),\n // and any subsequent elements represent interior rings (i.e. smaller area);\n // this avoids rendering issues of the MultiPolygons on the map\n const nestedRings = orderByArea(isobandsCoords);\n const groupedRings = groupNestedRings(nestedRings);\n\n contours.push({\n groupedRings: groupedRings as Position[][][],\n [property]: lowerBand + \"-\" + upperBand,\n });\n }\n return contours;\n}\n\n/**\n * Transform isobands of 2D grid to polygons for the map\n *\n * @private\n * @param {Array<any>} contours Contours\n * @param {Array<Array<number>>} matrix Grid Data\n * @param {Object} points Points by Latitude\n * @returns {Array<any>} contours\n */\nfunction rescaleContours(\n contours: GroupedRings[],\n matrix: number[][],\n points: FeatureCollection<Point>\n): GroupedRings[] {\n // get dimensions (on the map) of the original grid\n const gridBbox = bbox(points); // [ minX, minY, maxX, maxY ]\n const originalWidth = gridBbox[2] - gridBbox[0];\n const originalHeigth = gridBbox[3] - gridBbox[1];\n\n // get origin, which is the first point of the last row on the rectangular data on the map\n const x0 = gridBbox[0];\n const y0 = gridBbox[1];\n // get number of cells per side\n const matrixWidth = matrix[0].length - 1;\n const matrixHeight = matrix.length - 1;\n // calculate the scaling factor between matrix and rectangular grid on the map\n const scaleX = originalWidth / matrixWidth;\n const scaleY = originalHeigth / matrixHeight;\n\n // resize and shift each point/line of the isobands\n return contours.map(function (contour) {\n contour.groupedRings = (contour.groupedRings as Position[][][]).map(\n function (lineRingSet) {\n return lineRingSet.map(function (lineRing) {\n return lineRing.map((point: Position) => [\n point[0] * scaleX + x0,\n point[1] * scaleY + y0,\n ]);\n });\n }\n );\n\n return contour;\n });\n}\n\n/* utility functions */\n\n/**\n * Returns an array of coordinates (of LinearRings) in descending order by area\n *\n * @private\n * @param {Array<LineString>} ringsCoords array of closed LineString\n * @returns {Array} array of the input LineString ordered by area\n */\nfunction orderByArea(ringsCoords: Position[][]): Position[][] {\n const ringsWithArea = ringsCoords.map(function (coords) {\n // associate each lineRing with its area\n return { ring: coords, area: area(polygon([coords])) };\n });\n ringsWithArea.sort(function (a, b) {\n // bigger --> smaller\n return b.area - a.area;\n });\n // create a new array of linearRings coordinates ordered by their area\n return ringsWithArea.map(function (x) {\n return x.ring;\n });\n}\n\n/**\n * Returns an array of arrays of coordinates, each representing\n * a set of (coordinates of) nested LinearRings,\n * i.e. the first ring contains all the others\n *\n * @private\n * @param {Array} orderedLinearRings array of coordinates (of LinearRings) in descending order by area\n * @returns {Array<Array>} Array of coordinates of nested LinearRings\n */\nfunction groupNestedRings(orderedLinearRings: Position[][]): Position[][][] {\n // create a list of the (coordinates of) LinearRings\n const lrList = orderedLinearRings.map((lr) => {\n return { lrCoordinates: lr, grouped: false };\n });\n const groupedLinearRingsCoords: Position[][][] = [];\n\n while (!allGrouped(lrList)) {\n for (let i = 0; i < lrList.length; i++) {\n if (!lrList[i].grouped) {\n // create new group starting with the larger not already grouped ring\n const group: Position[][] = [];\n group.push(lrList[i].lrCoordinates);\n lrList[i].grouped = true;\n const outerMostPoly = polygon([lrList[i].lrCoordinates]);\n // group all the rings contained by the outermost ring\n for (let j = i + 1; j < lrList.length; j++) {\n if (!lrList[j].grouped) {\n const lrPoly = polygon([lrList[j].lrCoordinates]);\n if (isInside(lrPoly, outerMostPoly)) {\n group.push(lrList[j].lrCoordinates);\n lrList[j].grouped = true;\n }\n }\n }\n // insert the new group\n groupedLinearRingsCoords.push(group);\n }\n }\n }\n return groupedLinearRingsCoords;\n}\n\n/**\n * @private\n * @param {Polygon} testPolygon polygon of interest\n * @param {Polygon} targetPolygon polygon you want to compare with\n * @returns {boolean} true if test-Polygon is inside target-Polygon\n */\nfunction isInside(\n testPolygon: Feature<Polygon>,\n targetPolygon: Feature<Polygon>\n): boolean {\n const points = explode(testPolygon);\n for (let i = 0; i < points.features.length; i++) {\n if (!booleanPointInPolygon(points.features[i], targetPolygon)) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * @private\n * @param {Array<Object>} list list of objects which might contain the 'group' attribute\n * @returns {boolean} true if all the objects in the list are marked as grouped\n */\nfunction allGrouped(\n list: { grouped: boolean; lrCoordinates: Position[] }[]\n): boolean {\n for (let i = 0; i < list.length; i++) {\n if (list[i].grouped === false) {\n return false;\n }\n }\n return true;\n}\n\nexport { isobands };\nexport default isobands;\n","import { getCoords, collectionOf } from \"@turf/invariant\";\nimport { featureEach } from \"@turf/meta\";\nimport { isObject } from \"@turf/helpers\";\n\n/**\n * Takes a {@link Point} grid and returns a correspondent matrix {Array<Array<number>>}\n * of the 'property' values\n *\n * @name gridToMatrix\n * @param {FeatureCollection<Point>} grid of points\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.zProperty='elevation'] the property name in `points` from which z-values will be pulled\n * @param {boolean} [options.flip=false] returns the matrix upside-down\n * @param {boolean} [options.flags=false] flags, adding a `matrixPosition` array field ([row, column]) to its properties,\n * the grid points with coordinates on the matrix\n * @returns {Array<Array<number>>} matrix of property values\n * @example\n * var extent = [-70.823364, -33.553984, -70.473175, -33.302986];\n * var cellSize = 3;\n * var grid = turf.pointGrid(extent, cellSize);\n * // add a random property to each point between 0 and 60\n * for (var i = 0; i < grid.features.length; i++) {\n * grid.features[i].properties.elevation = (Math.random() * 60);\n * }\n * gridToMatrix(grid);\n * //= [\n * [ 1, 13, 10, 9, 10, 13, 18],\n * [34, 8, 5, 4, 5, 8, 13],\n * [10, 5, 2, 1, 2, 5, 4],\n * [ 0, 4, 56, 19, 1, 4, 9],\n * [10, 5, 2, 1, 2, 5, 10],\n * [57, 8, 5, 4, 5, 0, 57],\n * [ 3, 13, 10, 9, 5, 13, 18],\n * [18, 13, 10, 9, 78, 13, 18]\n * ]\n */\nfunction gridToMatrix(grid, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var zProperty = options.zProperty || \"elevation\";\n var flip = options.flip;\n var flags = options.flags;\n\n // validation\n collectionOf(grid, \"Point\", \"input must contain Points\");\n\n var pointsMatrix = sortPointsByLatLng(grid, flip);\n\n var matrix = [];\n // create property matrix from sorted points\n // looping order matters here\n for (var r = 0; r < pointsMatrix.length; r++) {\n var pointRow = pointsMatrix[r];\n var row = [];\n for (var c = 0; c < pointRow.length; c++) {\n var point = pointRow[c];\n // Check if zProperty exist\n if (point.properties[zProperty]) row.push(point.properties[zProperty]);\n else row.push(0);\n // add flags\n if (flags === true) point.properties.matrixPosition = [r, c];\n }\n matrix.push(row);\n }\n\n return matrix;\n}\n\n/**\n * Sorts points by latitude and longitude, creating a 2-dimensional array of points\n *\n * @private\n * @param {FeatureCollection<Point>} points GeoJSON Point features\n * @param {boolean} [flip=false] returns the matrix upside-down\n * @returns {Array<Array<Point>>} points ordered by latitude and longitude\n */\nfunction sortPointsByLatLng(points, flip) {\n var pointsByLatitude = {};\n\n // divide points by rows with the same latitude\n featureEach(points, function (point) {\n var lat = getCoords(point)[1];\n if (!pointsByLatitude[lat]) pointsByLatitude[lat] = [];\n pointsByLatitude[lat].push(point);\n });\n\n // sort points (with the same latitude) by longitude\n var orderedRowsByLatitude = Object.keys(pointsByLatitude).map(function (lat) {\n var row = pointsByLatitude[lat];\n var rowOrderedByLongitude = row.sort(function (a, b) {\n return getCoords(a)[0] - getCoords(b)[0];\n });\n return rowOrderedByLongitude;\n });\n\n // sort rows (of points with the same latitude) by latitude\n var pointMatrix = orderedRowsByLatitude.sort(function (a, b) {\n if (flip) return getCoords(a[0])[1] - getCoords(b[0])[1];\n else return getCoords(b[0])[1] - getCoords(a[0])[1];\n });\n\n return pointMatrix;\n}\n\nexport { gridToMatrix };\nexport default gridToMatrix;\n"],"mappings":";;;;;;;;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BAAM,SAAS,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;AAChD,gBAAI,SAAS,QAAQ,aAAa,GAAG;AACnC,oBAAM,KAAK,OAAO,CAAC,EAAE,aAAa;AAClC,qBAAO,CAAC,EAAE,UAAU;AAAA,YACtB;AAAA,UACF;AAAA,QACF;AAEA,iCAAyB,KAAK,KAAK;AAAA,MACrC;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AA/BS;AAuCT,SAAS,SACP,aACA,eACS;AACT,QAAM,SAAS,QAAQ,WAAW;AAClC,WAAS,IAAI,GAAG,IAAI,OAAO,SAAS,QAAQ,KAAK;AAC/C,QAAI,CAAC,sBAAsB,OAAO,SAAS,CAAC,GAAG,aAAa,GAAG;AAC7D,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAXS;AAkBT,SAAS,WACP,MACS;AACT,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,QAAI,KAAK,CAAC,EAAE,YAAY,OAAO;AAC7B,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AATS;AAYT,IAAO,wBAAQ;","names":["collectionOf","isObject","isObject","collectionOf"]}
|
|
1
|
+
{"version":3,"sources":["../../index.ts","../../lib/grid-to-matrix.js"],"sourcesContent":["import { bbox } from \"@turf/bbox\";\nimport { area } from \"@turf/area\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { explode } from \"@turf/explode\";\nimport { collectionOf } from \"@turf/invariant\";\nimport {\n polygon,\n multiPolygon,\n featureCollection,\n isObject,\n} from \"@turf/helpers\";\n\nimport {\n FeatureCollection,\n Point,\n GeoJsonProperties,\n MultiPolygon,\n Position,\n Polygon,\n Feature,\n} from \"geojson\";\n\nimport { gridToMatrix } from \"./lib/grid-to-matrix.js\";\nimport { isoBands } from \"marchingsquares\";\n\ntype GroupRingProps = { [prop: string]: string };\ntype GroupedRings =\n | {\n groupedRings: Position[][][];\n }\n | GroupRingProps;\n\n/**\n * Takes a square or rectangular grid {@link FeatureCollection} of {@link Point} features with z-values and an array of\n * value breaks and generates filled contour isobands.\n *\n * @name isobands\n * @param {FeatureCollection<Point>} pointGrid input points - must be square or rectangular\n * @param {Array<number>} breaks where to draw contours\n * @param {Object} [options={}] options on output\n * @param {string} [options.zProperty='elevation'] the property name in `points` from which z-values will be pulled\n * @param {Object} [options.commonProperties={}] GeoJSON properties passed to ALL isobands\n * @param {Array<Object>} [options.breaksProperties=[]] GeoJSON properties passed, in order, to the correspondent isoband (order defined by breaks)\n * @returns {FeatureCollection<MultiPolygon>} a FeatureCollection of {@link MultiPolygon} features representing isobands\n */\nfunction isobands(\n pointGrid: FeatureCollection<Point>,\n breaks: number[],\n options?: {\n zProperty?: string;\n commonProperties?: GeoJsonProperties;\n breaksProperties?: GeoJsonProperties[];\n }\n): FeatureCollection<MultiPolygon> {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const zProperty = options.zProperty || \"elevation\";\n const commonProperties = options.commonProperties || {};\n const breaksProperties = options.breaksProperties || [];\n\n // Validation\n collectionOf(pointGrid, \"Point\", \"Input must contain Points\");\n if (!breaks) throw new Error(\"breaks is required\");\n if (!Array.isArray(breaks)) throw new Error(\"breaks is not an Array\");\n if (!isObject(commonProperties))\n throw new Error(\"commonProperties is not an Object\");\n if (!Array.isArray(breaksProperties))\n throw new Error(\"breaksProperties is not an Array\");\n\n // Isoband methods\n const matrix = gridToMatrix(pointGrid, { zProperty: zProperty, flip: true });\n let contours = createContourLines(matrix, breaks, zProperty);\n contours = rescaleContours(contours, matrix, pointGrid);\n\n const multipolygons = contours.map((contour, index) => {\n if (breaksProperties[index] && !isObject(breaksProperties[index])) {\n throw new Error(\"Each mappedProperty is required to be an Object\");\n }\n // collect all properties\n const contourProperties = {\n ...commonProperties,\n ...breaksProperties[index],\n };\n\n contourProperties[zProperty] = (contour as GroupRingProps)[zProperty];\n\n const multiP = multiPolygon(\n contour.groupedRings as Position[][][],\n contourProperties\n );\n return multiP;\n });\n\n return featureCollection(multipolygons);\n}\n\n/**\n * Creates the contours lines (featuresCollection of polygon features) from the 2D data grid\n *\n * Marchingsquares process the grid data as a 3D representation of a function on a 2D plane, therefore it\n * assumes the points (x-y coordinates) are one 'unit' distance. The result of the IsoBands function needs to be\n * rescaled, with turfjs, to the original area and proportions on the map\n *\n * @private\n * @param {Array<Array<number>>} matrix Grid Data\n * @param {Array<number>} breaks Breaks\n * @param {string} [property='elevation'] Property\n * @returns {Array<any>} contours\n */\nfunction createContourLines(\n matrix: number[][],\n breaks: number[],\n property: string\n): GroupedRings[] {\n const contours: GroupedRings[] = [];\n for (let i = 1; i < breaks.length; i++) {\n const lowerBand = +breaks[i - 1]; // make sure the breaks value is a number\n const upperBand = +breaks[i];\n\n const isobandsCoords = isoBands(matrix, lowerBand, upperBand - lowerBand);\n // as per GeoJson rules for creating a Polygon, make sure the first element\n // in the array of LinearRings represents the exterior ring (i.e. biggest area),\n // and any subsequent elements represent interior rings (i.e. smaller area);\n // this avoids rendering issues of the MultiPolygons on the map\n const nestedRings = orderByArea(isobandsCoords);\n const groupedRings = groupNestedRings(nestedRings);\n\n contours.push({\n groupedRings: groupedRings as Position[][][],\n [property]: lowerBand + \"-\" + upperBand,\n });\n }\n return contours;\n}\n\n/**\n * Transform isobands of 2D grid to polygons for the map\n *\n * @private\n * @param {Array<any>} contours Contours\n * @param {Array<Array<number>>} matrix Grid Data\n * @param {Object} points Points by Latitude\n * @returns {Array<any>} contours\n */\nfunction rescaleContours(\n contours: GroupedRings[],\n matrix: number[][],\n points: FeatureCollection<Point>\n): GroupedRings[] {\n // get dimensions (on the map) of the original grid\n const gridBbox = bbox(points); // [ minX, minY, maxX, maxY ]\n const originalWidth = gridBbox[2] - gridBbox[0];\n const originalHeigth = gridBbox[3] - gridBbox[1];\n\n // get origin, which is the first point of the last row on the rectangular data on the map\n const x0 = gridBbox[0];\n const y0 = gridBbox[1];\n // get number of cells per side\n const matrixWidth = matrix[0].length - 1;\n const matrixHeight = matrix.length - 1;\n // calculate the scaling factor between matrix and rectangular grid on the map\n const scaleX = originalWidth / matrixWidth;\n const scaleY = originalHeigth / matrixHeight;\n\n // resize and shift each point/line of the isobands\n return contours.map(function (contour) {\n contour.groupedRings = (contour.groupedRings as Position[][][]).map(\n function (lineRingSet) {\n return lineRingSet.map(function (lineRing) {\n return lineRing.map((point: Position) => [\n point[0] * scaleX + x0,\n point[1] * scaleY + y0,\n ]);\n });\n }\n );\n\n return contour;\n });\n}\n\n/* utility functions */\n\n/**\n * Returns an array of coordinates (of LinearRings) in descending order by area\n *\n * @private\n * @param {Array<LineString>} ringsCoords array of closed LineString\n * @returns {Array} array of the input LineString ordered by area\n */\nfunction orderByArea(ringsCoords: Position[][]): Position[][] {\n const ringsWithArea = ringsCoords.map(function (coords) {\n // associate each lineRing with its area\n return { ring: coords, area: area(polygon([coords])) };\n });\n ringsWithArea.sort(function (a, b) {\n // bigger --> smaller\n return b.area - a.area;\n });\n // create a new array of linearRings coordinates ordered by their area\n return ringsWithArea.map(function (x) {\n return x.ring;\n });\n}\n\n/**\n * Returns an array of arrays of coordinates, each representing\n * a set of (coordinates of) nested LinearRings,\n * i.e. the first ring contains all the others\n *\n * @private\n * @param {Array} orderedLinearRings array of coordinates (of LinearRings) in descending order by area\n * @returns {Array<Array>} Array of coordinates of nested LinearRings\n */\nfunction groupNestedRings(orderedLinearRings: Position[][]): Position[][][] {\n // create a list of the (coordinates of) LinearRings\n const lrList = orderedLinearRings.map((lr) => {\n return { lrCoordinates: lr, grouped: false };\n });\n const groupedLinearRingsCoords: Position[][][] = [];\n\n while (!allGrouped(lrList)) {\n for (let i = 0; i < lrList.length; i++) {\n if (!lrList[i].grouped) {\n // create new group starting with the larger not already grouped ring\n const group: Position[][] = [];\n group.push(lrList[i].lrCoordinates);\n lrList[i].grouped = true;\n const outerMostPoly = polygon([lrList[i].lrCoordinates]);\n // group all the rings contained by the outermost ring\n for (let j = i + 1; j < lrList.length; j++) {\n if (!lrList[j].grouped) {\n const lrPoly = polygon([lrList[j].lrCoordinates]);\n if (isInside(lrPoly, outerMostPoly)) {\n group.push(lrList[j].lrCoordinates);\n lrList[j].grouped = true;\n }\n }\n }\n // insert the new group\n groupedLinearRingsCoords.push(group);\n }\n }\n }\n return groupedLinearRingsCoords;\n}\n\n/**\n * @private\n * @param {Polygon} testPolygon polygon of interest\n * @param {Polygon} targetPolygon polygon you want to compare with\n * @returns {boolean} true if test-Polygon is inside target-Polygon\n */\nfunction isInside(\n testPolygon: Feature<Polygon>,\n targetPolygon: Feature<Polygon>\n): boolean {\n const points = explode(testPolygon);\n for (let i = 0; i < points.features.length; i++) {\n if (!booleanPointInPolygon(points.features[i], targetPolygon)) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * @private\n * @param {Array<Object>} list list of objects which might contain the 'group' attribute\n * @returns {boolean} true if all the objects in the list are marked as grouped\n */\nfunction allGrouped(\n list: { grouped: boolean; lrCoordinates: Position[] }[]\n): boolean {\n for (let i = 0; i < list.length; i++) {\n if (list[i].grouped === false) {\n return false;\n }\n }\n return true;\n}\n\nexport { isobands };\nexport default isobands;\n","import { getCoords, collectionOf } from \"@turf/invariant\";\nimport { featureEach } from \"@turf/meta\";\nimport { isObject } from \"@turf/helpers\";\n\n/**\n * Takes a {@link Point} grid and returns a correspondent matrix {Array<Array<number>>}\n * of the 'property' values\n *\n * @name gridToMatrix\n * @param {FeatureCollection<Point>} grid of points\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.zProperty='elevation'] the property name in `points` from which z-values will be pulled\n * @param {boolean} [options.flip=false] returns the matrix upside-down\n * @param {boolean} [options.flags=false] flags, adding a `matrixPosition` array field ([row, column]) to its properties,\n * the grid points with coordinates on the matrix\n * @returns {Array<Array<number>>} matrix of property values\n * @example\n * var extent = [-70.823364, -33.553984, -70.473175, -33.302986];\n * var cellSize = 3;\n * var grid = turf.pointGrid(extent, cellSize);\n * // add a random property to each point between 0 and 60\n * for (var i = 0; i < grid.features.length; i++) {\n * grid.features[i].properties.elevation = (Math.random() * 60);\n * }\n * gridToMatrix(grid);\n * //= [\n * [ 1, 13, 10, 9, 10, 13, 18],\n * [34, 8, 5, 4, 5, 8, 13],\n * [10, 5, 2, 1, 2, 5, 4],\n * [ 0, 4, 56, 19, 1, 4, 9],\n * [10, 5, 2, 1, 2, 5, 10],\n * [57, 8, 5, 4, 5, 0, 57],\n * [ 3, 13, 10, 9, 5, 13, 18],\n * [18, 13, 10, 9, 78, 13, 18]\n * ]\n */\nfunction gridToMatrix(grid, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var zProperty = options.zProperty || \"elevation\";\n var flip = options.flip;\n var flags = options.flags;\n\n // validation\n collectionOf(grid, \"Point\", \"input must contain Points\");\n\n var pointsMatrix = sortPointsByLatLng(grid, flip);\n\n var matrix = [];\n // create property matrix from sorted points\n // looping order matters here\n for (var r = 0; r < pointsMatrix.length; r++) {\n var pointRow = pointsMatrix[r];\n var row = [];\n for (var c = 0; c < pointRow.length; c++) {\n var point = pointRow[c];\n // Check if zProperty exist\n if (point.properties[zProperty]) row.push(point.properties[zProperty]);\n else row.push(0);\n // add flags\n if (flags === true) point.properties.matrixPosition = [r, c];\n }\n matrix.push(row);\n }\n\n return matrix;\n}\n\n/**\n * Sorts points by latitude and longitude, creating a 2-dimensional array of points\n *\n * @private\n * @param {FeatureCollection<Point>} points GeoJSON Point features\n * @param {boolean} [flip=false] returns the matrix upside-down\n * @returns {Array<Array<Point>>} points ordered by latitude and longitude\n */\nfunction sortPointsByLatLng(points, flip) {\n var pointsByLatitude = {};\n\n // divide points by rows with the same latitude\n featureEach(points, function (point) {\n var lat = getCoords(point)[1];\n if (!pointsByLatitude[lat]) pointsByLatitude[lat] = [];\n pointsByLatitude[lat].push(point);\n });\n\n // sort points (with the same latitude) by longitude\n var orderedRowsByLatitude = Object.keys(pointsByLatitude).map(function (lat) {\n var row = pointsByLatitude[lat];\n var rowOrderedByLongitude = row.sort(function (a, b) {\n return getCoords(a)[0] - getCoords(b)[0];\n });\n return rowOrderedByLongitude;\n });\n\n // sort rows (of points with the same latitude) by latitude\n var pointMatrix = orderedRowsByLatitude.sort(function (a, b) {\n if (flip) return getCoords(a[0])[1] - getCoords(b[0])[1];\n else return getCoords(b[0])[1] - getCoords(a[0])[1];\n });\n\n return pointMatrix;\n}\n\nexport { gridToMatrix };\nexport default gridToMatrix;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,6BAA6B;AACtC,SAAS,eAAe;AACxB,SAAS,gBAAAA,qBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAAC;AAAA,OACK;;;ACVP,SAAS,WAAW,oBAAoB;AACxC,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAkCzB,SAAS,aAAa,MAAM,SAAS;AAEnC,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,MAAI,YAAY,QAAQ,aAAa;AACrC,MAAI,OAAO,QAAQ;AACnB,MAAI,QAAQ,QAAQ;AAGpB,eAAa,MAAM,SAAS,2BAA2B;AAEvD,MAAI,eAAe,mBAAmB,MAAM,IAAI;AAEhD,MAAI,SAAS,CAAC;AAGd,WAAS,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;AAC5C,QAAI,WAAW,aAAa,CAAC;AAC7B,QAAI,MAAM,CAAC;AACX,aAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;AACxC,UAAI,QAAQ,SAAS,CAAC;AAEtB,UAAI,MAAM,WAAW,SAAS;AAAG,YAAI,KAAK,MAAM,WAAW,SAAS,CAAC;AAAA;AAChE,YAAI,KAAK,CAAC;AAEf,UAAI,UAAU;AAAM,cAAM,WAAW,iBAAiB,CAAC,GAAG,CAAC;AAAA,IAC7D;AACA,WAAO,KAAK,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AC7B,cAAM,KAAK,OAAO,CAAC,EAAE,aAAa;AAClC,eAAO,CAAC,EAAE,UAAU;AACpB,cAAM,gBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;AAEvD,iBAAS,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AAC1C,cAAI,CAAC,OAAO,CAAC,EAAE,SAAS;AACtB,kBAAM,SAAS,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;AAChD,gBAAI,SAAS,QAAQ,aAAa,GAAG;AACnC,oBAAM,KAAK,OAAO,CAAC,EAAE,aAAa;AAClC,qBAAO,CAAC,EAAE,UAAU;AAAA,YACtB;AAAA,UACF;AAAA,QACF;AAEA,iCAAyB,KAAK,KAAK;AAAA,MACrC;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAQA,SAAS,SACP,aACA,eACS;AACT,QAAM,SAAS,QAAQ,WAAW;AAClC,WAAS,IAAI,GAAG,IAAI,OAAO,SAAS,QAAQ,KAAK;AAC/C,QAAI,CAAC,sBAAsB,OAAO,SAAS,CAAC,GAAG,aAAa,GAAG;AAC7D,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAOA,SAAS,WACP,MACS;AACT,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,QAAI,KAAK,CAAC,EAAE,YAAY,OAAO;AAC7B,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAGA,IAAO,wBAAQ;","names":["collectionOf","isObject","isObject","collectionOf"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/isobands",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.1.0-alpha.7+0ce6ecca0",
|
|
4
4
|
"description": "turf isobands module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -57,11 +57,11 @@
|
|
|
57
57
|
"test:tape": "tsx test.ts"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@turf/envelope": "^7.0.
|
|
61
|
-
"@turf/point-grid": "^7.0.
|
|
62
|
-
"@turf/random": "^7.0.
|
|
63
|
-
"@turf/rhumb-destination": "^7.0.
|
|
64
|
-
"@turf/truncate": "^7.0.
|
|
60
|
+
"@turf/envelope": "^7.1.0-alpha.7+0ce6ecca0",
|
|
61
|
+
"@turf/point-grid": "^7.1.0-alpha.7+0ce6ecca0",
|
|
62
|
+
"@turf/random": "^7.1.0-alpha.7+0ce6ecca0",
|
|
63
|
+
"@turf/rhumb-destination": "^7.1.0-alpha.7+0ce6ecca0",
|
|
64
|
+
"@turf/truncate": "^7.1.0-alpha.7+0ce6ecca0",
|
|
65
65
|
"@types/benchmark": "^2.1.5",
|
|
66
66
|
"@types/tape": "^4.2.32",
|
|
67
67
|
"benchmark": "^2.1.4",
|
|
@@ -75,15 +75,15 @@
|
|
|
75
75
|
"write-json-file": "^5.0.0"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@turf/area": "^7.0.
|
|
79
|
-
"@turf/bbox": "^7.0.
|
|
80
|
-
"@turf/boolean-point-in-polygon": "^7.0.
|
|
81
|
-
"@turf/explode": "^7.0.
|
|
82
|
-
"@turf/helpers": "^7.0.
|
|
83
|
-
"@turf/invariant": "^7.0.
|
|
84
|
-
"@turf/meta": "^7.0.
|
|
78
|
+
"@turf/area": "^7.1.0-alpha.7+0ce6ecca0",
|
|
79
|
+
"@turf/bbox": "^7.1.0-alpha.7+0ce6ecca0",
|
|
80
|
+
"@turf/boolean-point-in-polygon": "^7.1.0-alpha.7+0ce6ecca0",
|
|
81
|
+
"@turf/explode": "^7.1.0-alpha.7+0ce6ecca0",
|
|
82
|
+
"@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0",
|
|
83
|
+
"@turf/invariant": "^7.1.0-alpha.7+0ce6ecca0",
|
|
84
|
+
"@turf/meta": "^7.1.0-alpha.7+0ce6ecca0",
|
|
85
85
|
"marchingsquares": "^1.3.3",
|
|
86
86
|
"tslib": "^2.6.2"
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea"
|
|
89
89
|
}
|