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

Conversation

stebogit
Copy link
Collaborator

@stebogit stebogit commented Jun 7, 2017

Fixes #390

@stebogit stebogit self-assigned this Jun 7, 2017
@DenisCarriere
Copy link
Member

DenisCarriere commented Jun 7, 2017

?? Why all the changes to turf-bbox & turf-helpers??

Looks like you merged an old branch to this PR, might be best to close this PR and only send the changes for @turf/isolines.

👎

@stebogit
Copy link
Collaborator Author

stebogit commented Jun 7, 2017

@DenisCarriere Wow man, I didn't see those! 😳
It seems actually that it was my last yarn update (all I did was running yarn in my terminal) which generated all those changes in turf-bbox and turf-helpers; everything before was ok.
Shouldn't have I done that maybe?

@DenisCarriere
Copy link
Member

DenisCarriere commented Jun 7, 2017

Humm.. strange, I don't think yarn would of caused that.

Who knows!

I've been starting to use GitHub Desktop which allows you to easily Update from Default Branch. That will make your "stale" branch current to the Master branch.

image

This might not work in this current state, but that's what I did for some other older branches.

@stebogit
Copy link
Collaborator Author

stebogit commented Jun 7, 2017

@DenisCarriere you can easily see that those changes occurred only in the last commit; and I swear in there I only ran yarn cause I thought it would have updated the yard.lock file (which it did, among the other changes).
And you can see from the chart I branched out from the HEAD of master.

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.

@DenisCarriere
Copy link
Member

Undo the commit works. 👍

@DenisCarriere
Copy link
Member

That's really strange... Ah well... no worries 👍

image

@stebogit
Copy link
Collaborator Author

stebogit commented Jun 7, 2017

So, for the next time, should I run yarn to update the yarn.lock file or it get's updated maybe at merge or when Travis runs?

@DenisCarriere
Copy link
Member

You can still run yarn, but just keep track of your git commit & git push files.

@stebogit
Copy link
Collaborator Author

stebogit commented Jun 8, 2017

Yay!! Undo done 😃


/**
* 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;
Copy link
Member

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.

* @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
Copy link
Member

@DenisCarriere DenisCarriere Jun 8, 2017

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

* @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
Copy link
Member

@DenisCarriere DenisCarriere Jun 8, 2017

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 (zProperty in options) (would break backwards compatibility)

Copy link
Member

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.

Copy link
Collaborator Author

@stebogit stebogit Jun 9, 2017

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.

* @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
Copy link
Member

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

Copy link
Collaborator Author

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...

}
module.exports = function (points, breaks, zProperty, options) {
// Input validation
var isObject = function (input) {
Copy link
Member

@DenisCarriere DenisCarriere Jun 8, 2017

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...

Copy link
Member

@DenisCarriere DenisCarriere left a 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

@stebogit
Copy link
Collaborator Author

stebogit commented Jun 8, 2017

Thanks @DenisCarriere, always good to improve the code 😃
I'll clean up as soon as I have few minutes

@stebogit
Copy link
Collaborator Author

stebogit commented Jun 9, 2017

@DenisCarriere I implemented your suggestions, please take a look to index.d.ts cause I might have done it wrong.
I named the last optional parameter properties, which defines properties.perIsoline and properties.toAllIsolines, hopefully now is more clear.
Let me know what you think.

type Points = GeoJSON.FeatureCollection<GeoJSON.Point>;
type LineStrings = GeoJSON.FeatureCollection<GeoJSON.LineString>;
interface Properties {
perIsoline: Array<Object>,
Copy link
Member

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)

Copy link
Member

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
@DenisCarriere
Copy link
Member

👍 @stebogit You've outdone yourself this time, this module looks great! Can't wait to try this out on some big datasets.

image

@DenisCarriere
Copy link
Member

DenisCarriere commented Jun 11, 2017

Updates

  • Split properties={} to two params propertiesToAllIsolines & propertiesPerIsoline
  • 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
  • perIsoline overlaps properties from toAllIsolines
  • Update README

@DenisCarriere
Copy link
Member

👍 Going to merge, feel free to send commits on the master branch for any more little tweaks.

@DenisCarriere DenisCarriere merged commit 321d0df into master Jun 11, 2017
@DenisCarriere DenisCarriere deleted the isolines branch June 11, 2017 17:25
@DenisCarriere DenisCarriere added this to the 4.5.0 milestone Jun 12, 2017
DenisCarriere pushed a commit that referenced this pull request Jun 18, 2017
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants