Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New @turf/isolines based on MarchingSquares.js #781

Merged
merged 12 commits into from
Jun 11, 2017
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/turf-isolines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ value breaks and generates [isolines](http://en.wikipedia.org/wiki/Isoline).

**Parameters**

- `points` **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** input points
- `z` **[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
- `resolution` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** resolution of the underlying grid
- `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
- `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 `{}`)
- `options.isolineProperties` **\[[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 (order defined by breaks) (optional, default `[]`)
- `options.commonProperties` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** GeoJSON properties passed to ALL isolines (optional, default `{}`)

**Examples**

Expand Down
75 changes: 61 additions & 14 deletions packages/turf-isolines/bench.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,65 @@
var isolines = require('./');
var Benchmark = require('benchmark');
var fs = require('fs');
const path = require('path');
const Benchmark = require('benchmark');
const load = require('load-json-file');
const fs = require('fs');
const matrixToGrid = require('matrix-to-grid');
const isolines = require('./');

var points = JSON.parse(fs.readFileSync(__dirname+'/test/Points.geojson'));
// Define Fixtures
const directory = path.join(__dirname, 'test', 'in') + path.sep;
const fixtures = fs.readdirSync(directory).map(filename => {
return {
filename,
name: path.parse(filename).name,
jsondata: load.sync(directory + filename)
};
});

var suite = new Benchmark.Suite('turf-isolines');
/**
* Benchmark Results
*
* bigMatrix x 168 ops/sec ±2.79% (72 runs sampled)
* matrix1 x 17,145 ops/sec ±4.73% (68 runs sampled)
* matrix2 x 11,004 ops/sec ±2.56% (79 runs sampled)
* pointGrid x 12,109 ops/sec ±2.01% (77 runs sampled)
*/
const suite = new Benchmark.Suite('turf-isolines');
for (const {name, jsondata, filename} of fixtures) {

let breaks, points, zProperty, isolineProperties, commonProperties;
// allow geojson featureCollection...
if (filename.includes('geojson')) {
breaks = jsondata.properties.breaks;
zProperty = jsondata.properties.zProperty;
commonProperties = jsondata.properties.commonProperties;
isolineProperties = jsondata.properties.isolineProperties;
points = jsondata;
} else {
// ...or matrix input
const matrix = jsondata.matrix;
const cellSize = jsondata.cellSize;
const origin = jsondata.origin;
breaks = jsondata.breaks;
zProperty = jsondata.zProperty;
points = matrixToGrid(matrix, origin, cellSize, {zProperty, units: jsondata.units});
commonProperties = jsondata.commonProperties;
isolineProperties = jsondata.isolineProperties;
}

isolines(points, breaks, zProperty, {
commonProperties,
isolineProperties
});

// isolines(geojson, 'elevation', [5, 45, 55, 65, 85, 95, 105, 120, 180]);
suite.add(name, () => isolines(points, breaks, zProperty, {
commonProperties,
isolineProperties
})
);
}
suite
.add('turf-isolines',function () {
isolines(points, 'elevation', 15, [25, 45, 55, 65, 85, 95, 105, 120, 180]);
})
.on('cycle', function (event) {
console.log(String(event.target));
})
.on('complete', function () {

})
.on('cycle', e => console.log(String(e.target)))
.on('complete', () => {})
.run();

Loading