matrix-to-grid
Advanced tools
Comparing version 3.0.1 to 4.0.0
@@ -1,7 +0,12 @@ | ||
/// <reference types="geojson" /> | ||
import { FeatureCollection, Point, Units, Coord } from '@turf/helpers'; | ||
import {Points} from '@turf/helpers'; | ||
declare function matrixToGrid(matrix: Array<Array<number>>, property?: string): Points; | ||
declare namespace matrixToGrid { } | ||
export = matrixToGrid; | ||
export default function matrixToGrid( | ||
matrix: number[][], | ||
origin: Coord, | ||
cellSize: number, | ||
options?: { | ||
zProperty?: string, | ||
properties?: object, | ||
units?: Units | ||
} | ||
): FeatureCollection<Point>; |
72
index.js
@@ -1,5 +0,3 @@ | ||
var helpers = require('@turf/helpers'); | ||
var point = helpers.point; | ||
var featureCollection = helpers.featureCollection; | ||
var GeodesyLatLon = require('geodesy').LatLonSpherical; | ||
import {isObject, featureCollection} from '@turf/helpers'; | ||
import rhumbDestination from '@turf/rhumb-destination'; | ||
@@ -14,6 +12,6 @@ /** | ||
* @param {number} cellSize the distance across each cell | ||
* @param {Object} options optional parameters | ||
* @param {Object} [options={}] optional parameters | ||
* @param {string} [options.zProperty='elevation'] the grid points property name associated with the matrix value | ||
* @param {Object} [options.properties={}] GeoJSON properties passed to all the points | ||
* @param {string} [options.units=kilometers] used in calculating cellSize, can be miles, or kilometers | ||
* @param {string} [options.units='kilometers'] used in calculating cellSize, can be miles, or kilometers | ||
* @returns {FeatureCollection<Point>} grid of points | ||
@@ -37,9 +35,14 @@ * | ||
*/ | ||
module.exports = function (matrix, origin, cellSize, options) { | ||
export default function matrixToGrid(matrix, origin, cellSize, options) { | ||
// Optional parameters | ||
options = options || {}; | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
var zProperty = options.zProperty || 'elevation'; | ||
var properties = options.properties; | ||
var units = options.units; | ||
// validation | ||
if (!matrix || !Array.isArray(matrix)) throw new Error('matrix is required'); | ||
if (!origin) throw new Error('origin is required'); | ||
if (Array.isArray(origin)) { | ||
origin = point(origin); // Convert coordinates array to point | ||
} | ||
// all matrix array have to be of the same size | ||
@@ -52,18 +55,9 @@ var matrixCols = matrix[0].length; | ||
// default values | ||
options = options || {}; | ||
options.zProperty = options.zProperty || 'elevation'; | ||
if (options.units === 'miles') { | ||
cellSize *= 1.60934; // km | ||
} | ||
cellSize *= 1000; // meters | ||
var points = []; | ||
for (var r = 0; r < matrixRows; r++) { | ||
// create first point in the row | ||
var first = rhumbDestinationPoint(origin, cellSize * r, 0); | ||
first.properties[options.zProperty] = matrix[matrixRows - 1 - r][0]; | ||
for (var prop in options.properties) { | ||
first.properties[prop] = options.properties[prop]; | ||
var first = rhumbDestination(origin, cellSize * r, 0, {units: units}); | ||
first.properties[zProperty] = matrix[matrixRows - 1 - r][0]; | ||
for (var prop in properties) { | ||
first.properties[prop] = properties[prop]; | ||
} | ||
@@ -73,35 +67,13 @@ points.push(first); | ||
// create the other points in the same row | ||
var pt = rhumbDestinationPoint(first, cellSize * c, 90); | ||
for (var prop2 in options.properties) { | ||
pt.properties[prop2] = options.properties[prop2]; | ||
var pt = rhumbDestination(first, cellSize * c, 90, {units: units}); | ||
for (var prop2 in properties) { | ||
pt.properties[prop2] = properties[prop2]; | ||
} | ||
// add matrix property | ||
var val = matrix[matrixRows - 1 - r][c]; | ||
pt.properties[options.zProperty] = val; | ||
pt.properties[zProperty] = val; | ||
points.push(pt); | ||
} | ||
} | ||
var grid = featureCollection(points); | ||
return grid; | ||
}; | ||
/** | ||
* Returns the destination point having travelled along a rhumb line from the originPoint the given | ||
* distance on the given bearing. | ||
* | ||
* @private | ||
* @param {Point|Array<number>} originPoint - Distance travelled, in same units as earth radius (default: metres). | ||
* @param {number} distance - Distance travelled, in same units as earth radius (default: metres). | ||
* @param {number} bearing - Bearing in degrees from north. | ||
* @returns {Point|Array<number>} Destination point. | ||
* | ||
*/ | ||
function rhumbDestinationPoint(originPoint, distance, bearing) { | ||
var coords = originPoint.geometry.coordinates; | ||
var pt = new GeodesyLatLon(coords[1], coords[0]); | ||
var destination = pt.rhumbDestinationPoint(distance, bearing); | ||
return point([destination.lon, destination.lat]); | ||
return featureCollection(points); | ||
} |
{ | ||
"name": "matrix-to-grid", | ||
"version": "3.0.1", | ||
"version": "4.0.0", | ||
"description": "Takes a matrix array of numbers and returns a grid of GeoJSON points with correspondent property value", | ||
"main": "index.js", | ||
"main": "matrix-to-grid.js", | ||
"module": "index.js", | ||
"jsnext:main": "index.js", | ||
"types": "index.d.ts", | ||
@@ -10,13 +12,11 @@ "files": [ | ||
"index.d.ts", | ||
"dist" | ||
"matrix-to-grid.js", | ||
"matrix-to-grid.min.js" | ||
], | ||
"scripts": { | ||
"prepublish": "npm run test && npm run build", | ||
"pretest": "npm run lint", | ||
"prepublish": "npm run test", | ||
"pretest": "rollup -c rollup.config.js", | ||
"test": "node test.js", | ||
"bench": "node bench.js", | ||
"lint": "eslint index.js", | ||
"build": "npm run rollup && npm run uglify", | ||
"rollup": "rollup -c rollup.config.js", | ||
"uglify": "uglifyjs dist/matrix-to-grid.js -c -m > dist/matrix-to-grid.min.js" | ||
"posttest": "eslint index.js", | ||
"bench": "node bench.js" | ||
}, | ||
@@ -40,23 +40,19 @@ "repository": { | ||
"devDependencies": { | ||
"@turf/circle": "4.2.0", | ||
"@turf/truncate": "4.1.0", | ||
"benchmark": "^2.1.3", | ||
"eslint": "^2.0.0", | ||
"eslint-config-mourner": "^2.0.0", | ||
"load-json-file": "^2.0.0", | ||
"rollup": "^0.41.5", | ||
"rollup-plugin-commonjs": "^8.0.2", | ||
"rollup-plugin-json": "^2.1.0", | ||
"rollup-plugin-node-builtins": "^2.1.0", | ||
"rollup-plugin-node-globals": "^1.1.0", | ||
"rollup-plugin-node-resolve": "^2.0.0", | ||
"tape": "^3.5.0", | ||
"typescript": "^2.2.1", | ||
"uglifyjs": "^2.4.10", | ||
"write-json-file": "^2.0.0" | ||
"@turf/circle": "*", | ||
"@turf/truncate": "*", | ||
"benchmark": "*", | ||
"eslint": "*", | ||
"eslint-config-mourner": "*", | ||
"glob": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"rollup-plugin-node-resolve": "*", | ||
"rollup-plugin-uglify": "*", | ||
"tape": "*", | ||
"write-json-file": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/helpers": "4.1.0", | ||
"geodesy": "1.1.1" | ||
"@turf/helpers": "5.x", | ||
"@turf/rhumb-destination": "5.x" | ||
} | ||
} |
# matrix-to-grid | ||
<!-- [](https://travis-ci.org/stebogit/matrix-to-grid) --> | ||
[](https://travis-ci.org/stebogit/matrix-to-grid) | ||
[](https://badge.fury.io/js/matrix-to-grid) | ||
@@ -40,3 +41,3 @@ [](https://github.com/stebogit/matrix-to-grid/blob/master/LICENSE) | ||
```html | ||
<script src="https://unpkg.com/matrix-to-grid@2.0.0/dist/matrix-to-grid.min.js"></script> | ||
<script src="https://unpkg.com/matrix-to-grid/matrix-to-grid.min.js"></script> | ||
``` | ||
@@ -43,0 +44,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12
63
38204
762
1
+ Added@turf/rhumb-destination@5.x
+ Added@turf/helpers@5.1.5(transitive)
+ Added@turf/invariant@5.2.0(transitive)
+ Added@turf/rhumb-destination@5.1.5(transitive)
- Removedgeodesy@1.1.1
- Removed@turf/helpers@4.1.0(transitive)
- Removedgeodesy@1.1.1(transitive)
Updated@turf/helpers@5.x