-
Notifications
You must be signed in to change notification settings - Fork 955
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
Conversation
@DenisCarriere I don't know how travis works, could you please give me some hint on how to set/fix it? Thanks |
@stebogit 👍 Thanks attempting this, the linting is done at the TurfJS root level. Once you are in the root folder:
So far the You can also see this in the build logs https://travis-ci.org/Turfjs/turf/builds/211360094
|
thanks! |
packages/turf-isobands/.travis.yml
Outdated
- "4" | ||
before_install: | ||
- npm install -g npm@~3.8.9 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is not needed since TurfJS has .travis.yml
at the root level
packages/turf-isobands/.npmignore
Outdated
@@ -0,0 +1,2 @@ | |||
test | |||
coverage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed since this is covered in the package.json
using "files": ["index.js", "index.d.ts"]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly is not needed? the .npmignore
file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entire .npmignore
file is not required, I've changed every module in Turf so all of them have the same syntax & file structure.
Use any turf module as your starting point to propose a new module (except the index.js
).
https://github.com/Turfjs/turf/tree/master/packages/turf-along
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
packages/turf-isobands/LICENSE
Outdated
@@ -0,0 +1,21 @@ | |||
The MIT License (MIT) | |||
|
|||
Copyright (c) 2016 Stefano Borghi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been using TurfJS as a generic name for all licenses (also 2017)
packages/turf-isobands/bench.js
Outdated
.on('complete', function () { | ||
|
||
}) | ||
.run(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to write in ES6 👍 bench.js
& test.js
is your only chance to write arrow functions :)
packages/turf-isobands/index.d.ts
Outdated
* http://turfjs.org/docs/#isolines | ||
*/ | ||
declare function isobands(points: Points, z: string, resolution: number, breaks: Array<number>): LineStrings; | ||
declare namespace isolines { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace must be the same name as the function name.
This breaks the typescript definition.
packages/turf-isobands/index.js
Outdated
* var breaks = [0, 5, 8.5]; | ||
* var isobands = turf.isobands(pointGrid, 'z', breaks); | ||
* //=isobands | ||
******************************************************************/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above **/
packages/turf-isobands/index.js
Outdated
divide points in pointGrid by latitude, creating a 2-dimensional data grid | ||
####################################*/ | ||
var pointsByLatitude = {}; | ||
for (var j = 0; j < points.length; j++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try using one of the @turf/meta
functions, coordEach()
or featureEach()
packages/turf-isobands/package.json
Outdated
"name": "turf-isobands", | ||
"version": "2.0.0", | ||
"description": "turf isobands module", | ||
"main": "index.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include "types":"index.d.ts"
(next to main instead of at the bottom) & "files": ["index.js", "index.d.ts"]
packages/turf-isobands/package.json
Outdated
"description": "turf isobands module", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tape test.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add benchmark to scripts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is "bench": "node bench.js"
ok?
packages/turf-isobands/test.js
Outdated
var isobands = require('./'); | ||
|
||
test('isobands', function(t){ | ||
var points = JSON.parse(fs.readFileSync(__dirname + '/geojson/Points.geojson')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to make your tests have dynamic data loading instead of hard coded fixtures in your tests.
That way someone can expand easily the test cases by simply adding a new .geojson
to the test/in
.
@turf/union
has a good example of that:
https://github.com/Turfjs/turf/blob/master/packages/turf-union/test.js
@stebogit As for the MarchingSquare.js file, I would not include it as a minified file, does it exists on npm? |
@DenisCarriere |
Quick eslint trick is you can include this around your code to ignore "valid" lines that cause errors. /*eslint-disable*/
var isobands = MarchingSquaresJS.IsoBands(gridData, lowerBand, upperBand - lowerBand);
/*eslint-enable*/ |
@stebogit Glancing at the repo, I'm thinking we should drop (make optional) the The GeoJSON specs only allows (longitude, latitude, elevation/altitude) to be a valid geometry. Proposed valid input var points = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
7,
42,
300
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
10,
45,
230
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
5,
45,
215
]
}
}
]
}
var results = isobands(points, [200, 250, 300]) |
packages/turf-isobands/test.js
Outdated
t.deepEqual(isobanded, load.sync(directories.out + 'isobands' + idx), input.name); | ||
if (process.env.REGEN) write.sync(directories.out + filename, results); | ||
t.equal(results.features[0].geometry.type, 'MultiPolygon', name + ' geometry=MultiPolygon'); | ||
t.deepEqual(results, load.sync(directories.out + filename), name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this way the code looks definitely nicer, but the content of the output file, points1.geojson
, is not a collection of points
, but actually of multipolygons
or isobands
.
don't you think it might be a little confusing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test/in
& test/out
should be the same filename. That way it's clear what goes in and what goes out.
You can even call points.geojson
italy.geojson
and then the output would be test/out/italy.geojson
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This becomes more evident when you start adding more and more files in the test/in
, for example @turf/union
has many files.
https://github.com/Turfjs/turf/tree/master/packages/turf-union/test/in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then I'd call them input1.geojson
, input2.geojson
and so on 😄
not a biggie though
I get your point. |
@stebogit 👍 Valid point, I think having it optional would be a good idea, or at least have that param at the end of the function. function (pointGrid, breaks, z) We could have We can add that logic at the beginning as part of the user input validation by reading the first point entry and figuring out if his |
@DenisCarriere great! 🎉 |
@stebogit I will have a stab at it over the weekend, also there's a lot of "complicated" logic inside the |
@DenisCarriere Thanks, I'm not familiar with the |
No worries, I have this habit of refactoring code until the most minimal amounts of lines are needed. At least we have a "functional" prototype of |
@stebogit another idea for the
Scenario: User wants to create contour lines based on 25 meter intervals (elevation units must also be in meters or the desired unit which is the same as the breaks). |
@DenisCarriere splendid idea! |
MarchingSquaresJS is now available through npm as marchingsquares module. Note, however, that due to npm naming conventions I've reverted the public API function names to lower camel case since version 1.2.0 of MarchingSquaresJS, i.e. the |
@stebogit Let me know if you are happy to merge this module, looks good to me 👍 . Always room for improvements/fixes in future releases. Also, feel free to add your |
@DenisCarriere personally I would remove the random input interpolation (the
Do you mean in this module? My idea was to use them in |
Oh I thought that 👍 Yep, you can remove the random fixture, we can always add it later in a future minor release. Looking forward to publishing this module! 🚀 @stebogit Have a last glance at this module and merge this PR whenever you feel comfortable with it. |
@DenisCarriere I created a few more tests for |
@stebogit No rush... (take all the time in the world 👍 ).
I agree, Keep it up! |
- set aside z-coordinate test; - fixed output dimensions issue; - added grid-to-matrix dependancy;
Fixed output bug, next will add more tests with graphically easy-to-read grid/matrix input values, then will evaluate performances. |
added tests; updated benchmark; updated readme; introduced common and per isoband options;
@DenisCarriere please take a look at the module, and feel free to add more tests. |
Works for me! 👍 This will be released in the next minor release v4.3 (aiming to get that done |
npm test
at the sub modules where changes have occured.npm run lint
to ensure code style at the turf module level. --> not sure how/if it works