{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-isobands/dist/cjs/index.cjs","../../index.ts","../../lib/grid-to-matrix.js"],"names":["isObject","collectionOf"],"mappings":"AAAA,6EAAI,UAAU,EAAE,MAAM,CAAC,cAAc;AACrC,IAAI,oBAAoB,EAAE,MAAM,CAAC,qBAAqB;AACtD,IAAI,aAAa,EAAE,MAAM,CAAC,SAAS,CAAC,cAAc;AAClD,IAAI,aAAa,EAAE,MAAM,CAAC,SAAS,CAAC,oBAAoB;AACxD,IAAI,gBAAgB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK;AAC/J,IAAI,eAAe,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG;AAC/B,EAAE,IAAI,CAAC,IAAI,KAAK,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAChC,IAAI,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AAClC,MAAM,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;AACvC,EAAE,GAAG,CAAC,mBAAmB;AACzB,IAAI,IAAI,CAAC,IAAI,KAAK,GAAG,mBAAmB,CAAC,CAAC,CAAC,EAAE;AAC7C,MAAM,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AACpC,QAAQ,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;AACzC,IAAI;AACJ,EAAE,OAAO,CAAC;AACV,CAAC;AACD;AACA;ACjBA,kCAAqB;AACrB,kCA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AAQ,CAAA,EAAA,EAAK;AAC/C,IAAA,GAAA,CAAI,CAAC,0DAAA,MAAsB,CAAO,QAAA,CAAS,CAAC,CAAA,EAAG,aAAa,CAAA,EAAG;AAC7D,MAAA,OAAO,KAAA;AAAA,IACT;AAAA,EACF;AACA,EAAA,OAAO,IAAA;AACT;AAOA,SAAS,UAAA,CACP,IAAA,EACS;AACT,EAAA,IAAA,CAAA,IAAS,EAAA,EAAI,CAAA,EAAG,EAAA,EAAI,IAAA,CAAK,MAAA,EAAQ,CAAA,EAAA,EAAK;AACpC,IAAA,GAAA,CAAI,IAAA,CAAK,CAAC,CAAA,CAAE,QAAA,IAAY,KAAA,EAAO;AAC7B,MAAA,OAAO,KAAA;AAAA,IACT;AAAA,EACF;AACA,EAAA,OAAO,IAAA;AACT;AAGA,IAAO,sBAAA,EAAQ,QAAA;ADhFf;AACE;AACA;AACF,qEAAC","file":"/home/runner/work/turf/turf/packages/turf-isobands/dist/cjs/index.cjs","sourcesContent":[null,"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 * @function\n * @param {FeatureCollection} pointGrid input points - must be square or rectangular\n * @param {Array} 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} [options.breaksProperties=[]] GeoJSON properties passed, in order, to the correspondent isoband (order defined by breaks)\n * @returns {FeatureCollection} a FeatureCollection of {@link MultiPolygon} features representing isobands\n */\nfunction isobands(\n pointGrid: FeatureCollection,\n breaks: number[],\n options?: {\n zProperty?: string;\n commonProperties?: GeoJsonProperties;\n breaksProperties?: GeoJsonProperties[];\n }\n): FeatureCollection {\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>} matrix Grid Data\n * @param {Array} breaks Breaks\n * @param {string} [property='elevation'] Property\n * @returns {Array} 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} contours Contours\n * @param {Array>} matrix Grid Data\n * @param {Object} points Points by Latitude\n * @returns {Array} contours\n */\nfunction rescaleContours(\n contours: GroupedRings[],\n matrix: number[][],\n points: FeatureCollection\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} 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 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,\n targetPolygon: Feature\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} 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>}\n * of the 'property' values\n *\n * @name gridToMatrix\n * @param {FeatureCollection} 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>} 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} points GeoJSON Point features\n * @param {boolean} [flip=false] returns the matrix upside-down\n * @returns {Array>} 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"]}