Add flattenEach/flattenReduce to @turf/meta. #712
Merged
+656
−270
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This addresses issue #692. There are a few design choices made that deserve scrutiny:
@turf/helpers
is added as a dependency to@turf/meta
. Needed to create features as geometries get flattened.geomEach
callback function was changed to add an additional third argument that passes the properties of the source feature from which the geometry came. Wasn't sure if adding this to the argument list was a good idea since a geometry doesn't have a property per the GeoJSON spec but sincegeomEach
is essentially a flattening function the source will usually be a feature. It's backward compatible as the last argument and existing users can just ignore it.flattenEach
andflattenReduce
callback function returns anindex
argument (increases for each geometry) and an additionalsubIndex
argument that increases for each sub-geometry if the geometry being flattened was a multi-geometry (MultiPoint, MultiLineString, MultiPolygon). For example, for a MultiPoint with, say, 3 points each point will have the sameindex
but theirsubIndex
will be 0, 1, and 2. I'm open to making this a single growing index but I thought this would be helpful if the caller wanted to index back into some property for multi-geometries.Finally, does Turf have a unit test coverage functionality somewhere? I didn't see any and it would be good to know if the tests are hitting all the right code.
Please fill in this template.
npm test
at the sub modules where changes have occurred.npm run lint
to ensure code style at the turf module level.