matrix-to-grid
Advanced tools
Comparing version 1.0.0 to 2.0.0
30
index.js
@@ -12,7 +12,8 @@ var destination = require('@turf/destination'); | ||
* @param {Array<Array<number>>} matrix of numbers | ||
* @param {Point|Array<number>} origin position of the first bottom-left point of the grid | ||
* @param {number} [cellSize] the distance across each cell | ||
* @param {string} [property='elevation'] the grid points property name associated with the matrix value | ||
* @param {Object=} [props=] properties passed to all the points | ||
* @param {string} [units=kilometers] used in calculating cellSize, can be degrees, radians, miles, or kilometers | ||
* @param {Point|Array<number>} origin position of the first bottom-left (South-West) point of the grid | ||
* @param {number} cellSize the distance across each cell | ||
* @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 degrees, radians, miles, or kilometers | ||
* @returns {FeatureCollection<Point>} grid of points | ||
@@ -22,3 +23,2 @@ * | ||
* var matrixToGrid = require('matrix-to-grid'); | ||
* | ||
* var matrix = [ | ||
@@ -35,7 +35,6 @@ * [ 1, 13, 20, 9, 10, 13, 18], | ||
* var origin = [-70.823364, -33.553984] | ||
* | ||
* matrixToGrid(matrix, origin, 10); | ||
* //= pointGrid | ||
*/ | ||
module.exports = function (matrix, origin, cellSize, property, props, units) { | ||
module.exports = function (matrix, origin, cellSize, options) { | ||
// validation | ||
@@ -55,15 +54,16 @@ if (!matrix || !Array.isArray(matrix)) throw new Error('matrix is required'); | ||
// default value | ||
property = property || 'elevation'; | ||
options = options || {}; | ||
options.zProperty = options.zProperty || 'elevation'; | ||
var points = []; | ||
for (var r = 0; r < matrixRows; r++) { | ||
var first = destination(origin, cellSize * r, 0, units); | ||
if (props) first.properties = props; | ||
first.properties[property] = matrix[matrixRows - 1 - r][0]; | ||
var first = destination(origin, cellSize * r, 0, options.units); | ||
if (options.properties) first.properties = options.properties; | ||
first.properties[options.zProperty] = matrix[matrixRows - 1 - r][0]; | ||
points.push(first); | ||
for (var c = 1; c < matrixCols; c++) { | ||
var pt = destination(first, cellSize * c, 90, units); | ||
var pt = destination(first, cellSize * c, 90, options.units); | ||
// add matrix property | ||
if (props) pt.properties = props; | ||
pt.properties[property] = matrix[matrixRows - 1 - r][c]; | ||
if (options.properties) pt.properties = options.properties; | ||
pt.properties[options.zProperty] = matrix[matrixRows - 1 - r][c]; | ||
points.push(pt); | ||
@@ -70,0 +70,0 @@ } |
{ | ||
"name": "matrix-to-grid", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Takes a matrix array of numbers and returns a grid of GeoJSON points with correspondent property value", | ||
@@ -9,3 +9,4 @@ "main": "index.js", | ||
"index.js", | ||
"index.d.ts" | ||
"index.d.ts", | ||
"dist" | ||
], | ||
@@ -12,0 +13,0 @@ "scripts": { |
@@ -12,12 +12,14 @@ # matrix-to-grid | ||
- `origin` \[**[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> | [Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>**] position of the first bottom-left point of the grid | ||
- `origin` \[**[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> | [Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>**] position of the first bottom-left (South-West) point of the grid | ||
- `cellSize` \[**[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**] the distance across each cell | ||
- `property` \[**[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**] the name of the property of the points which will represent the correspondent matrix value (optional, default `elevation`) | ||
- `options` \[**[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**] optional parameters: | ||
- `props` \[**[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**] properties passed to all the points (optional, default `null`) | ||
- `zProperty` \[**[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**] the name of the property of the points which will represent the correspondent matrix value (optional, default `elevation`) | ||
- `properties` \[**[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**] GeoJSON properties passed to all the points (optional, default `{}`) | ||
- `units` \[**[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**] miles, kilometers, degrees, or radians (optional, default `kilometers`) | ||
- `units` \[**[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**] miles, kilometers, degrees, or radians (optional, default `kilometers`) | ||
**Returns** | ||
@@ -36,2 +38,8 @@ | ||
**browser (ES5)** | ||
```html | ||
<script src="https://unpkg.com/matrix-to-grid@2.0.0/dist/matrix-to-grid.min.js"></script> | ||
``` | ||
### Quickstart | ||
@@ -41,3 +49,2 @@ | ||
var matrixToGrid = require('matrix-to-grid'); | ||
var matrix = [ | ||
@@ -54,3 +61,2 @@ [ 1, 13, 20, 9, 10, 13, 18], | ||
var origin = [-70.823364, -33.553984]; | ||
matrixToGrid(matrix, origin, 10); | ||
@@ -57,0 +63,0 @@ // = pointGrid |
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
33947
7
637
62
1