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

Add featureIndex & subIndex to coordEach/coordReduce callback @turf/meta #867

Closed
3 tasks done
DenisCarriere opened this issue Jul 26, 2017 · 4 comments
Closed
3 tasks done
Assignees
Milestone

Comments

@DenisCarriere
Copy link
Member

DenisCarriere commented Jul 26, 2017

Add featureIndex & subIndex callback params

Most of the @turf/meta callback modules all have a way to retrace back to the original Feature in the FeatureCollection using the index or subIndex callback parameters.

To-Do

  • Update coordEach & coordReduce callback parameters
    • Add featureIndex callback parameter
    • Add subIndex callback parameter (Optional)

Examples (Current State)

const features = turf.featureCollection([
    turf.lineString([[0, 0], [1, 1]]), // index 0
    turf.multiPoint([[4, 4], [0, 0]]), // index 1 & subIndex 0, 1
    turf.point([3, 3]),                // index 2
    turf.lineString([[2, 2], [1, 1]])  // index 3
]);

turf.featureEach(features, (feature, featureIndex) => {
    // featureIndex => 0, 1, 2, 3
})

turf.geomEach(features, (geometry, featureIndex) => {
    // featureIndex => 0, 1, 2, 3
})

turf.flattenEach(features, (feature, featureIndex, subIndex) => {
    // featureIndex => 0, 1, 1, 2, 3   (1 = MultiPoint)
    // subIndex     => 0, 0, 1, 0, 0
})

turf.coordEach(features, (coord, coordIndex) => {
    // coordIndex => 0, 1, 2, 3, 4, 5, 6
    // No way to reference back to original FeatureCollection
})

Proposed

turf.coordEach(geojson, (coord, coordIndex, featureIndex, subIndex) => {
    // coordIndex   => 0, 1, 2, 3, 4, 5, 6
    // featureIndex => 0, 0, 1, 1, 2, 3, 3
    // subIndex     => 0, 1, 0, 1, 0, 0, 1
})
@DenisCarriere DenisCarriere added this to the 4.6.0 milestone Jul 26, 2017
@rowanwins
Copy link
Member

you're my hero @DenisCarriere !

@DenisCarriere
Copy link
Member Author

🤣 Thanks @rowanwins It's a big team effort! ❤️

@DenisCarriere
Copy link
Member Author

@rowanwins Just pushed a PR for this, have a look and let me what you think about it.

@DenisCarriere
Copy link
Member Author

Implemented PR #872

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants