@turf/isolines
Advanced tools
Comparing version 4.7.3 to 5.0.4
@@ -1,2 +0,2 @@ | ||
import {Points, MultiLineStrings} from '@turf/helpers' | ||
import { Point, MultiLineString, FeatureCollection, Properties } from '@turf/helpers' | ||
@@ -6,10 +6,10 @@ /** | ||
*/ | ||
declare function isolines( | ||
points: Points, | ||
export default function isolines( | ||
points: FeatureCollection<Point>, | ||
breaks: number[], | ||
zProperty?:string, | ||
propertiesToAllIsolines?: Object, | ||
propertiesPerIsoline?: Object[]): MultiLineStrings; | ||
declare namespace isolines { } | ||
export = isolines; | ||
options?: { | ||
zProperty?: string, | ||
commonProperties?: Properties, | ||
breaksProperties?: Properties[] | ||
} | ||
): FeatureCollection<MultiLineString>; |
74
index.js
@@ -1,11 +0,7 @@ | ||
var bbox = require('@turf/bbox'); | ||
var meta = require('@turf/meta'); | ||
var helpers = require('@turf/helpers'); | ||
var invariant = require('@turf/invariant'); | ||
var gridToMatrix = require('grid-to-matrix'); | ||
var marchingsquares = require('marchingsquares'); | ||
var multiLineString = helpers.multiLineString; | ||
var coordEach = meta.coordEach; | ||
var collectionOf = invariant.collectionOf; | ||
var featureCollection = helpers.featureCollection; | ||
import bbox from '@turf/bbox'; | ||
import { coordEach } from '@turf/meta'; | ||
import { collectionOf } from '@turf/invariant'; | ||
import { multiLineString, featureCollection, isObject } from '@turf/helpers'; | ||
import isoContours from './lib/marchingsquares-isocontours'; | ||
import gridToMatrix from './lib/grid-to-matrix'; | ||
@@ -19,5 +15,6 @@ /** | ||
* @param {Array<number>} breaks values of `zProperty` where to draw isolines | ||
* @param {string} [zProperty='elevation'] the property name in `points` from which z-values will be pulled | ||
* @param {Object} [propertiesToAllIsolines={}] GeoJSON properties passed to ALL isolines | ||
* @param {Array<Object>} [propertiesPerIsoline=[]] GeoJSON properties passed, in order, to the correspondent isoline; | ||
* @param {Object} [options={}] Optional parameters | ||
* @param {string} [options.zProperty='elevation'] the property name in `points` from which z-values will be pulled | ||
* @param {Object} [options.commonProperties={}] GeoJSON properties passed to ALL isolines | ||
* @param {Array<Object>} [options.breaksProperties=[]] GeoJSON properties passed, in order, to the correspondent isoline; | ||
* the breaks array will define the order in which the isolines are created | ||
@@ -29,4 +26,3 @@ * @returns {FeatureCollection<MultiLineString>} a FeatureCollection of {@link MultiLineString} features representing isolines | ||
* var cellWidth = 100; | ||
* var units = 'miles'; | ||
* var pointGrid = turf.pointGrid(extent, cellWidth, units); | ||
* var pointGrid = turf.pointGrid(extent, cellWidth, {units: 'miles'}); | ||
* for (var i = 0; i < pointGrid.features.length; i++) { | ||
@@ -37,3 +33,3 @@ * pointGrid.features[i].properties.temperature = Math.random() * 10; | ||
* | ||
* var isolines = turf.isolines(pointGrid, breaks, 'temperature'); | ||
* var isolines = turf.isolines(pointGrid, breaks, {zProperty: 'temperature'}); | ||
* | ||
@@ -43,7 +39,9 @@ * //addToMap | ||
*/ | ||
module.exports = function (pointGrid, breaks, zProperty, propertiesToAllIsolines, propertiesPerIsoline) { | ||
// Default Params | ||
zProperty = zProperty || 'elevation'; | ||
propertiesToAllIsolines = propertiesToAllIsolines || {}; | ||
propertiesPerIsoline = propertiesPerIsoline || []; | ||
function isolines(pointGrid, breaks, options) { | ||
// Optional parameters | ||
options = options || {}; | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
var zProperty = options.zProperty || 'elevation'; | ||
var commonProperties = options.commonProperties || {}; | ||
var breaksProperties = options.breaksProperties || []; | ||
@@ -54,13 +52,12 @@ // Input validation | ||
if (!Array.isArray(breaks)) throw new Error('breaks must be an Array'); | ||
if (!isObject(propertiesToAllIsolines)) throw new Error('propertiesToAllIsolines must be an Object'); | ||
if (!Array.isArray(propertiesPerIsoline)) throw new Error('propertiesPerIsoline must be an Array'); | ||
if (typeof zProperty !== 'string') throw new Error('zProperty must be a string'); | ||
if (!isObject(commonProperties)) throw new Error('commonProperties must be an Object'); | ||
if (!Array.isArray(breaksProperties)) throw new Error('breaksProperties must be an Array'); | ||
// Isoline methods | ||
var matrix = gridToMatrix(pointGrid, zProperty, true); | ||
var isolines = createIsoLines(matrix, breaks, zProperty, propertiesToAllIsolines, propertiesPerIsoline); | ||
var matrix = gridToMatrix(pointGrid, {zProperty: zProperty, flip: true}); | ||
var isolines = createIsoLines(matrix, breaks, zProperty, commonProperties, breaksProperties); | ||
var scaledIsolines = rescaleIsolines(isolines, matrix, pointGrid); | ||
return featureCollection(scaledIsolines); | ||
}; | ||
} | ||
@@ -78,7 +75,7 @@ /** | ||
* @param {string} zProperty name of the z-values property | ||
* @param {Object} [propertiesToAllIsolines={}] GeoJSON properties passed to ALL isolines | ||
* @param {Object} [propertiesPerIsoline=[]] GeoJSON properties passed to the correspondent isoline | ||
* @param {Object} [commonProperties={}] GeoJSON properties passed to ALL isolines | ||
* @param {Object} [breaksProperties=[]] GeoJSON properties passed to the correspondent isoline | ||
* @returns {Array<MultiLineString>} isolines | ||
*/ | ||
function createIsoLines(matrix, breaks, zProperty, propertiesToAllIsolines, propertiesPerIsoline) { | ||
function createIsoLines(matrix, breaks, zProperty, commonProperties, breaksProperties) { | ||
var isolines = []; | ||
@@ -90,7 +87,7 @@ for (var i = 1; i < breaks.length; i++) { | ||
{}, | ||
propertiesToAllIsolines, | ||
propertiesPerIsoline[i] | ||
commonProperties, | ||
breaksProperties[i] | ||
); | ||
properties[zProperty] = threshold; | ||
var isoline = multiLineString(marchingsquares.isoContours(matrix, threshold), properties); | ||
var isoline = multiLineString(isoContours(matrix, threshold), properties); | ||
@@ -142,11 +139,2 @@ isolines.push(isoline); | ||
/** | ||
* Checks input type | ||
* | ||
* @private | ||
* @param {*} input to be checked | ||
* @returns {boolean} true if the input is an Object | ||
*/ | ||
function isObject(input) { | ||
return (!!input) && (input.constructor === Object); | ||
} | ||
export default isolines; |
{ | ||
"name": "@turf/isolines", | ||
"version": "4.7.3", | ||
"version": "5.0.4", | ||
"description": "turf isolines module", | ||
"main": "index.js", | ||
"main": "main", | ||
"module": "index", | ||
"jsnext:main": "index", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
"index.d.ts", | ||
"main.js", | ||
"lib" | ||
], | ||
"scripts": { | ||
"test": "node test.js", | ||
"bench": "node bench.js" | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"bench": "node -r @std/esm bench.js" | ||
}, | ||
@@ -37,19 +42,25 @@ "repository": { | ||
"devDependencies": { | ||
"@turf/envelope": "^4.7.3", | ||
"@turf/point-grid": "^4.7.3", | ||
"@turf/random": "^4.7.3", | ||
"benchmark": "2.1.4", | ||
"load-json-file": "2.0.0", | ||
"matrix-to-grid": "3.0.0", | ||
"tape": "4.7.0", | ||
"write-json-file": "2.2.0" | ||
"@std/esm": "*", | ||
"@turf/envelope": "^5.0.4", | ||
"@turf/point-grid": "^5.0.4", | ||
"@turf/random": "^5.0.4", | ||
"@turf/rhumb-destination": "^5.0.4", | ||
"@turf/truncate": "^5.0.4", | ||
"benchmark": "*", | ||
"load-json-file": "*", | ||
"matrix-to-grid": "*", | ||
"rollup": "*", | ||
"tape": "*", | ||
"write-json-file": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/bbox": "^4.7.3", | ||
"@turf/helpers": "^4.7.3", | ||
"@turf/invariant": "^4.7.3", | ||
"@turf/meta": "^4.7.3", | ||
"grid-to-matrix": "1.2.0", | ||
"marchingsquares": "1.2.0" | ||
"@turf/bbox": "^5.0.4", | ||
"@turf/helpers": "^5.0.4", | ||
"@turf/invariant": "^5.0.4", | ||
"@turf/meta": "^5.0.4" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
} | ||
} |
# @turf/isolines | ||
# isolines | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
## isolines | ||
Takes a grid [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) of [Point](http://geojson.org/geojson-spec.html#point) features with z-values and an array of | ||
@@ -12,6 +14,7 @@ value breaks and generates [isolines](http://en.wikipedia.org/wiki/Isoline). | ||
- `breaks` **[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)>** values of `zProperty` where to draw isolines | ||
- `zProperty` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** the property name in `points` from which z-values will be pulled (optional, default `'elevation'`) | ||
- `propertiesToAllIsolines` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** GeoJSON properties passed to ALL isolines (optional, default `{}`) | ||
- `propertiesPerIsoline` **\[[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>]** GeoJSON properties passed, in order, to the correspondent isoline; | ||
the breaks array will define the order in which the isolines are created (optional, default `[]`) | ||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`) | ||
- `options.zProperty` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the property name in `points` from which z-values will be pulled (optional, default `'elevation'`) | ||
- `options.commonProperties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** GeoJSON properties passed to ALL isolines (optional, default `{}`) | ||
- `options.breaksProperties` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** GeoJSON properties passed, in order, to the correspondent isoline; | ||
the breaks array will define the order in which the isolines are created (optional, default `[]`) | ||
@@ -24,4 +27,3 @@ **Examples** | ||
var cellWidth = 100; | ||
var units = 'miles'; | ||
var pointGrid = turf.pointGrid(extent, cellWidth, units); | ||
var pointGrid = turf.pointGrid(extent, cellWidth, {units: 'miles'}); | ||
for (var i = 0; i < pointGrid.features.length; i++) { | ||
@@ -32,3 +34,3 @@ pointGrid.features[i].properties.temperature = Math.random() * 10; | ||
var isolines = turf.isolines(pointGrid, breaks, 'temperature'); | ||
var isolines = turf.isolines(pointGrid, breaks, {zProperty: 'temperature'}); | ||
@@ -35,0 +37,0 @@ //addToMap |
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
51394
4
9
1093
64
12
1
+ Added@turf/bbox@5.1.5(transitive)
+ Added@turf/helpers@5.1.5(transitive)
+ Added@turf/invariant@5.2.0(transitive)
+ Added@turf/meta@5.2.0(transitive)
- Removedgrid-to-matrix@1.2.0
- Removedmarchingsquares@1.2.0
- Removed@turf/bbox@4.7.3(transitive)
- Removed@turf/helpers@4.7.3(transitive)
- Removed@turf/invariant@4.7.3(transitive)
- Removed@turf/meta@4.7.4(transitive)
- Removedgrid-to-matrix@1.2.0(transitive)
- Removedmarchingsquares@1.2.0(transitive)
Updated@turf/bbox@^5.0.4
Updated@turf/helpers@^5.0.4
Updated@turf/invariant@^5.0.4
Updated@turf/meta@^5.0.4