-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New @turf/isolines based on MarchingSquares.js (#781)
* replaced conrec with marchingsquare * fixed script and tests * updated bench * updated readme * updated package.json * updated index.d.ts * introduced suggested changes * added zProperty to index.d.ts * minor doc change * Updates to Isolines - Divide properties={} to two params - Simplify Catch error logic (index.js) - Update Typescript definition - Add types.ts to test Typescript definition - Add single task to benchmark - Update Yarn.lock - Simplify bench & test logic - Save fixtures out to GeoJSON CC: @stebogit * perIsoline overlaps properties from toAllIsolines * Update Readme
- Loading branch information
1 parent
537cd4b
commit 321d0df
Showing
17 changed files
with
5,721 additions
and
637 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,56 @@ | ||
var isolines = require('./'); | ||
var Benchmark = require('benchmark'); | ||
var fs = require('fs'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const load = require('load-json-file'); | ||
const Benchmark = require('benchmark'); | ||
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: 21.457ms | ||
* matrix1: 0.741ms | ||
* matrix2: 0.547ms | ||
* pointGrid: 1.373ms | ||
* 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) { | ||
const { | ||
breaks, | ||
zProperty, | ||
propertiesPerIsoline, | ||
propertiesToAllIsolines, | ||
matrix, | ||
cellSize, | ||
units, | ||
origin} = jsondata.properties || jsondata; | ||
|
||
// allow GeoJSON FeatureCollection or Matrix | ||
let points; | ||
if (filename.includes('geojson')) points = jsondata; | ||
else points = matrixToGrid(matrix, origin, cellSize, {zProperty, units}); | ||
|
||
console.time(name); | ||
isolines(points, breaks, zProperty, propertiesToAllIsolines, propertiesPerIsoline); | ||
console.timeEnd(name); | ||
suite.add(name, () => isolines(points, breaks, zProperty, propertiesToAllIsolines, propertiesPerIsoline)); | ||
} | ||
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(); | ||
|
Oops, something went wrong.