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-isobands module with MarchingSquares #619

Merged
merged 31 commits into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
dcb39ca
added isobands module
stebogit Jan 29, 2017
fa32920
updated to latest version of @turf and MarchingSquaresJS
stebogit Jan 29, 2017
def67a5
integrated module.export to MS-isobands, added sandbox
stebogit Feb 28, 2017
c42f537
updated marchingsquare library
stebogit Mar 15, 2017
3341cd4
removed sandbox
stebogit Mar 15, 2017
2093242
modified version and license
stebogit Mar 15, 2017
7a40684
made suggested corrections
stebogit Mar 16, 2017
c96d13e
replaced minified marchingsquare
stebogit Mar 16, 2017
bdbb1a8
Refactoring turf-isobands
DenisCarriere Mar 16, 2017
fb6cce8
Merge branch 'master' into isobands
DenisCarriere Mar 16, 2017
6017a04
Merge branch 'master' into isobands
DenisCarriere Mar 16, 2017
3f13aa4
Add z coordinate fixture
DenisCarriere Mar 19, 2017
49cc2e8
Merge branch 'isobands' of https://github.com/stebogit/turf into isob…
DenisCarriere Mar 19, 2017
bac2c75
Separate isobands into methods
DenisCarriere Mar 19, 2017
950d14c
Add isolines test fixture
DenisCarriere Mar 19, 2017
fc7591e
added methods to accept random points as input
stebogit Mar 27, 2017
b80512d
corrected linting issues
stebogit Mar 27, 2017
b0fa745
corrected linting issues
stebogit Mar 27, 2017
6cfae0c
rinamed function dividePointsByLatitude
stebogit Apr 7, 2017
440bae6
Merge branch 'master' into isobands
stebogit Apr 7, 2017
2933158
Update test/out fixtures
DenisCarriere Apr 16, 2017
6650f73
Merge remote-tracking branch 'upstream/master' into isobands
stebogit Apr 18, 2017
a0b7c78
Merge remote-tracking branch 'upstream/master' into isobands
stebogit Apr 22, 2017
6998178
reordered methods
stebogit Apr 22, 2017
0030a2b
- removed random points tests;
stebogit Apr 24, 2017
0b63cd7
Merge remote-tracking branch 'upstream/master' into isobands
stebogit Apr 25, 2017
e9fb0a8
adds matrix outer frame;
stebogit Apr 25, 2017
b1127ec
simplified code
stebogit Apr 27, 2017
42469e9
Merge remote-tracking branch 'upstream/master' into isobands
stebogit May 1, 2017
0b36635
set matrix json as valid test input
stebogit May 1, 2017
2ea0902
fixed output;
stebogit May 8, 2017
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ test.js
bench.js
packages/turf/turf.js
packages/turf/turf.min.js
marchingsquares-isobands.js
rollup.config.js
simplepolygon.js
21 changes: 21 additions & 0 deletions packages/turf-isobands/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 turf

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
59 changes: 59 additions & 0 deletions packages/turf-isobands/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# turf-isobands

# isobands

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 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
- `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
+ `isobandProperties` **[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 isoband (order defined by breaks)
+ `commonProperties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** GeoJSON properties passed to ALL isobands

**Examples**

```javascript
// create random points with random
// z-values in their properties
var extent = [-70.823364, -33.553984, -69.823364, -32.553984];
var cellWidth = 5;
var units = 'miles';
var pointGrid = turf.pointGrid(extent, cellWidth, units);
for (var i = 0; i < pointGrid.features.length; i++) {
pointGrid.features[i].properties.elevation = Math.random() * 10;
}
var breaks = [0, 5, 8.5];
var isobands = turf.isobands(pointGrid, breaks, 'elevation');
//=isobands
```

Returns **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)&lt;[MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon)>** a FeatureCollection of [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon) features representing isobands

<!-- This file is automatically generated. Please don't edit it directly:
if you find an error, edit the source file (likely index.js), and re-run
./scripts/generate-readmes in the turf project. -->

---

This module is part of the [Turfjs project](http://turfjs.org/), an open source
module collection dedicated to geographic algorithms. It is maintained in the
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
PRs and issues.

### Installation

Install this module individually:

```sh
$ npm install turf-isobands
```

Or install the Turf module that includes it as a function:

```sh
$ npm install @turf/turf
```
64 changes: 64 additions & 0 deletions packages/turf-isobands/bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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 isobands = require('./');

// 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)
};
});

/**
* Benchmark Results
*
* bigMatrix x 73.43 ops/sec ±2.12% (62 runs sampled)
* matrix1 x 5,205 ops/sec ±3.13% (78 runs sampled)
* matrix2 x 2,333 ops/sec ±9.38% (71 runs sampled)
* pointGrid x 3,201 ops/sec ±1.81% (78 runs sampled)
*/
const suite = new Benchmark.Suite('turf-isobands');
for (const {name, jsondata, filename} of fixtures) {

let breaks, points, zProperty, isobandProperties, commonProperties;
// allow geojson featureCollection...
if (filename.includes('geojson')) {
breaks = jsondata.properties.breaks;
zProperty = jsondata.properties.zProperty;
commonProperties = jsondata.properties.commonProperties;
isobandProperties = jsondata.properties.isobandProperties;
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;
isobandProperties = jsondata.isobandProperties;
}

isobands(points, breaks, zProperty, {
commonProperties,
isobandProperties
});

// isobands(geojson, 'elevation', [5, 45, 55, 65, 85, 95, 105, 120, 180]);
suite.add(name, () => isobands(points, breaks, zProperty, {
commonProperties,
isobandProperties
})
);
}
suite
.on('cycle', e => console.log(String(e.target)))
.on('complete', () => {})
.run();
8 changes: 8 additions & 0 deletions packages/turf-isobands/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {Points, MultiPolygons} from '@turf/helpers'

/**
* http://turfjs.org/docs/#isobands
*/
declare function isobands(points: Points, breaks: Array<number>, property?: string): MultiPolygons;
declare namespace isobands { }
export = isobands;
Loading