-
Notifications
You must be signed in to change notification settings - Fork 943
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
Conversation
?? Why all the changes to Looks like you merged an old branch to this PR, might be best to close this PR and only send the changes for 👎 |
@DenisCarriere Wow man, I didn't see those! 😳 |
Humm.. strange, I don't think Who knows! I've been starting to use GitHub Desktop which allows you to easily This might not work in this current state, but that's what I did for some other older branches. |
@DenisCarriere you can easily see that those changes occurred only in the last commit; and I swear in there I only ran However do you want me to close this PR and copy all the good changes on a new branch? I believe though we might just undo the last commit and all should be fine. |
Undo the commit works. 👍 |
So, for the next time, should I run |
You can still run |
Yay!! Undo done 😃 |
packages/turf-isolines/index.d.ts
Outdated
|
||
/** | ||
* http://turfjs.org/docs/#isolines | ||
*/ | ||
declare function isolines(points: Points, z: string, resolution: number, breaks: Array<number>): LineStrings; | ||
declare function isolines(points: Points, breaks: Array<number>, property?: string): MultiLineStrings; |
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.
Looks like you're missing options
You would need to build an interface for that.
interface Options {
isolineProperties: any[],
commonProperties: any
}
Then declare the option as a param.
packages/turf-isolines/index.js
Outdated
* @param {Object} [options={}] options on output | ||
* @param {Array<Object>} [options.isolineProperties=[]] GeoJSON properties passed, in order, to the correspondent | ||
* isoline (order defined by breaks) | ||
* @param {Object} [options.commonProperties={}] GeoJSON properties passed to ALL 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.
I would most likely change the name of the param to properties
.
Optional comment... I do agree that this module has lots of different properties
params/variables, it is a bit confusing if it's not defined as commonProperties
packages/turf-isolines/index.js
Outdated
* @returns {FeatureCollection<LineString>} isolines | ||
* @param {Array<number>} breaks where to draw isolines | ||
* @param {string} [zProperty='elevation'] the property name in `points` from which z-values will be pulled | ||
* @param {Object} [options={}] options on output |
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.
If you decide to use options, then all "optional" params should be included ( (would break backwards compatibility)zProperty
in options)
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.
Or just drop options
all together and just add 2 extra more params without the Object
, there's very rare amounts of TurfJS modules that use this type of syntax.
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.
(would break backwards compatibility)
Well actually compatibility is already an issue, since the resolution
parameter is not used/useful anymore (it is defined by the pointGrid
input itself).
Maybe we keep this module update for the next major release?
there's very rare amounts of TurfJS modules that use this type of syntax
The idea here is more similar the property
object that for example is passed to all the turf-helpers
function when creating a new feature (e.g. point([0,3], properties)
). Here we have multiple isolines that are being generated, and you can pass a single properties object to all the isolines and/or specific properties to specific isolines.
turf-isoband
currently follows this same syntax; we can improve the naming/description in there or change to two separate parameters in both modules.
packages/turf-isolines/index.js
Outdated
* @param {Array<number>} breaks where to draw isolines | ||
* @param {string} [zProperty='elevation'] the property name in `points` from which z-values will be pulled | ||
* @param {Object} [options={}] options on output | ||
* @param {Array<Object>} [options.isolineProperties=[]] GeoJSON properties passed, in order, to the correspondent |
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.
I don't quite understand this param...? We might want to improve the description a bit
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.
If you look at the bigMatrix
test it is how you can pass for example different colors to the isolines
. The first property of the isolineProperty
will be assigned to the first isoline (defined by the first breaks
value), the second isolineProperty
to the second isoline and so on.
Don't know how to better describe it in a concise way though...
packages/turf-isolines/index.js
Outdated
} | ||
module.exports = function (points, breaks, zProperty, options) { | ||
// Input validation | ||
var isObject = function (input) { |
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.
No need to nest this function inside another function.
Optional comment...
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.
👍 Looks good! I posted a few comments, but they are totally optional
Thanks @DenisCarriere, always good to improve the code 😃 |
@DenisCarriere I implemented your suggestions, please take a look to |
packages/turf-isolines/index.d.ts
Outdated
type Points = GeoJSON.FeatureCollection<GeoJSON.Point>; | ||
type LineStrings = GeoJSON.FeatureCollection<GeoJSON.LineString>; | ||
interface Properties { | ||
perIsoline: Array<Object>, |
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.
👍 Looks good, only thing is since perIsolines
& toAllIsolines
are optional, you will need to add :?
to make them optional.
interface Properties {
perIsoline?: Array<Object>,
toAllIsolines?: Object
}
However, it might be best to not have those properties
tags as an Object and just by their own param.
declare function isolines(
points: Points,
breaks: number[],
zProperty?:string,
propertiesPerIsoline?: Object[],
propertiesToAllIsolines?: Object): MultiLineStrings;
javascript code
isolines(points, breaks, 'temperature', [{foo: 'bar'}], properties)
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.
Also propertiesPerIsoline
, seems a bit more complex to use vs. the propertiesToAllIsolines
. We might want to reverse them.
const properties = {foo: 'bar'}
isolines(points, breaks, 'temperature', properties)
isolines(points, breaks, 'temperature', properties, [{name: 'break1'}, {name: 'break2'])
- 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
👍 @stebogit You've outdone yourself this time, this module looks great! Can't wait to try this out on some big datasets. |
Updates
|
👍 Going to merge, feel free to send commits on the master branch for any more little tweaks. |
* added fiji + resolute-bay tests to translate * added fiji + resolute-bay test to rotate * Add new modules to Turf core * v4.4.0 * Fix tests for blank dependencies * Add inside tests * 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 * Buffer (#786) Buffer - Drop circle buffer operation * removed turf-isolines old test files * copied files from repo * refactored index and test * updated README * updated index.d.ts and bench * added yarn.lock * removed Polygon as accepted input; added array test; * added masking feature to turf-grid * added throws tests * updated yarn.lock * added contributor * Resolves #785 * Add test fixture * Update complex unkink-polygon * Update name to boolean-clockwise * Declare input as line instead of Feature
Fixes #390