Skip to content

Commit

Permalink
updated isolines and isobands readme (solves #829)
Browse files Browse the repository at this point in the history
  • Loading branch information
stebogit committed Jul 7, 2017
1 parent 738ba4d commit 1851c45
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
5 changes: 2 additions & 3 deletions packages/turf-isobands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ value breaks and generates filled contour isobands.

**Parameters**

- `points` **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** a FeatureCollection of [Point](http://geojson.org/geojson-spec.html#point) features
- `pointGrid` **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** input points
- `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)>** where to draw contours
- `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` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** options on output (optional, default `{}`)
Expand All @@ -18,8 +18,7 @@ value breaks and generates filled contour isobands.
**Examples**

```javascript
// create random points with random
// z-values in their properties
// create a grid of points with random z-values in their properties
var extent = [-70.823364, -33.553984, -69.823364, -32.553984];
var cellWidth = 5;
var units = 'miles';
Expand Down
13 changes: 6 additions & 7 deletions packages/turf-isobands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var featureCollection = helpers.featureCollection;
* value breaks and generates filled contour isobands.
*
* @name isobands
* @param {FeatureCollection<Point>} points a FeatureCollection of {@link Point} features
* @param {FeatureCollection<Point>} pointGrid input points
* @param {Array<number>} breaks where to draw contours
* @param {string} [zProperty='elevation'] the property name in `points` from which z-values will be pulled
* @param {Object} [options={}] options on output
Expand All @@ -25,8 +25,7 @@ var featureCollection = helpers.featureCollection;
* @param {Object} [options.commonProperties={}] GeoJSON properties passed to ALL isobands
* @returns {FeatureCollection<MultiPolygon>} a FeatureCollection of {@link MultiPolygon} features representing isobands
* @example
* // create random points with random
* // z-values in their properties
* // create a grid of points with random z-values in their properties
* var extent = [-70.823364, -33.553984, -69.823364, -32.553984];
* var cellWidth = 5;
* var units = 'miles';
Expand All @@ -40,12 +39,12 @@ var featureCollection = helpers.featureCollection;
* //addToMap
* var addToMap = [isobands];
*/
module.exports = function (points, breaks, zProperty, options) {
module.exports = function (pointGrid, breaks, zProperty, options) {
// Input validation
var isObject = function (input) {
return (!!input) && (input.constructor === Object);
};
collectionOf(points, 'Point', 'Input must contain Points');
collectionOf(pointGrid, 'Point', 'Input must contain Points');
if (!breaks || !Array.isArray(breaks)) throw new Error('breaks is required');
if (options.commonProperties && !isObject(options.commonProperties)) {
throw new Error('commonProperties is not an Object');
Expand All @@ -61,9 +60,9 @@ module.exports = function (points, breaks, zProperty, options) {
var isobandProperties = options.isobandProperties || [];

// Isoband methods
var matrix = gridToMatrix(points, zProperty, true);
var matrix = gridToMatrix(pointGrid, zProperty, true);
var contours = createContourLines(matrix, breaks, zProperty);
contours = rescaleContours(contours, matrix, points);
contours = rescaleContours(contours, matrix, pointGrid);

var multipolygons = contours.map(function (contour, index) {
if (isobandProperties[index] && !isObject(isobandProperties[index])) {
Expand Down
23 changes: 12 additions & 11 deletions packages/turf-isolines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

# isolines

Takes [points](http://geojson.org/geojson-spec.html#point) with z-values and an array of
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
value breaks and generates [isolines](http://en.wikipedia.org/wiki/Isoline).

**Parameters**

- `points` **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)&lt;[Point](http://geojson.org/geojson-spec.html#point)>** input points
- `pointGrid` **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)&lt;[Point](http://geojson.org/geojson-spec.html#point)>** input points
- `breaks` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[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 `{}`)
Expand All @@ -17,15 +17,16 @@ value breaks and generates [isolines](http://en.wikipedia.org/wiki/Isoline).
**Examples**

```javascript
// create random points with random z-values in their properties
var points = turf.random('point', 100, {
bbox: [0, 30, 20, 50]
});
for (var i = 0; i < points.features.length; i++) {
points.features[i].properties.z = Math.random() * 10;
}
var breaks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var isolines = turf.isolines(points, breaks, 'temperature');
// create a grid of points with random z-values in their properties
var extent = [0, 30, 20, 50];
var cellWidth = 100;
var units = 'miles';
var pointGrid = turf.pointGrid(extent, cellWidth, units);
for (var i = 0; i < pointGrid.features.length; i++) {
pointGrid.features[i].properties.temperature = Math.random() * 10;
}
var breaks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var isolines = turf.isolines(pointGrid, breaks, 'temperature');

//addToMap
var addToMap = [isolines];
Expand Down
29 changes: 15 additions & 14 deletions packages/turf-isolines/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,50 @@ var collectionOf = invariant.collectionOf;
var featureCollection = helpers.featureCollection;

/**
* Takes {@link Point|points} with z-values and an array of
* Takes a grid {@link FeatureCollection} of {@link Point} features with z-values and an array of
* value breaks and generates [isolines](http://en.wikipedia.org/wiki/Isoline).
*
* @name isolines
* @param {FeatureCollection<Point>} points input points
* @param {FeatureCollection<Point>} pointGrid input points
* @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; the breaks array will define the order in which the isolines are created
* @returns {FeatureCollection<MultiLineString>} a FeatureCollection of {@link MultiLineString} features representing isolines
* @example
* // create random points with random z-values in their properties
* var points = turf.random('point', 100, {
* bbox: [0, 30, 20, 50]
* });
* for (var i = 0; i < points.features.length; i++) {
* points.features[i].properties.z = Math.random() * 10;
* // create a grid of points with random z-values in their properties
* var extent = [0, 30, 20, 50];
* var cellWidth = 100;
* var units = 'miles';
* var pointGrid = turf.pointGrid(extent, cellWidth, units);
* for (var i = 0; i < pointGrid.features.length; i++) {
* pointGrid.features[i].properties.temperature = Math.random() * 10;
* }
* var breaks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
* var isolines = turf.isolines(points, breaks, 'temperature');
* var isolines = turf.isolines(pointGrid, breaks, 'temperature');
*
* //addToMap
* var addToMap = [isolines];
*/
module.exports = function (points, breaks, zProperty, propertiesToAllIsolines, propertiesPerIsoline) {
module.exports = function (pointGrid, breaks, zProperty, propertiesToAllIsolines, propertiesPerIsoline) {
// Default Params
zProperty = zProperty || 'elevation';
propertiesToAllIsolines = propertiesToAllIsolines || {};
propertiesPerIsoline = propertiesPerIsoline || [];

// Input validation
collectionOf(points, 'Point', 'Input must contain Points');
collectionOf(pointGrid, 'Point', 'Input must contain Points');
if (!breaks) throw new Error('breaks is required');
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');

// Isolined methods
var matrix = gridToMatrix(points, zProperty, true);
// Isoline methods
var matrix = gridToMatrix(pointGrid, zProperty, true);
var isolines = createIsoLines(matrix, breaks, zProperty, propertiesToAllIsolines, propertiesPerIsoline);
var scaledIsolines = rescaleIsolines(isolines, matrix, points);
var scaledIsolines = rescaleIsolines(isolines, matrix, pointGrid);

return featureCollection(scaledIsolines);
};
Expand Down

0 comments on commit 1851c45

Please sign in to comment.