Add coordMap function to complement coordEach
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 10.5k
- Forks
- 1k
- Avg merge
- 1h 11m
- Merged PRs (30d)
- 4
Description
Explaination
Hey :)
Yesterday, searching for a tool to loop and map over coordinates, I did not succeed to find one.
The idea was basically simple : loop over all coordinates, and map each of them with a new item (new position, i.e); but the key part is leaving the whole geojson object untouched
I can think of 3 example use-cases, including mines :
- Reproject a whole GeoJSON object
- Remove
z([lng, lat, z]) from coordinates in a whole, dirty, GeoJSON object - Round coordinates to 6 decimal places into a whole GeoJSON object
- (do the 3 previous operations in a single motion, to improve performance)
I found coordsEach (which just loop), coordsReduce (which would suffice to recompose a new geojson, with indexes and stuff, but would not be very readable), and perliedman/reproject (which is too linked with reprojection stuff, and provide a too-rough cloning strategy IMHO). FYI I opened an issue there to propose extraction of "mapping coordinates logic" in another repo.
I ended up implementing it myself, but I think it could be a great addition to @turfjs 😄
Here is it : traverse-geojson
I used some gjtk tools, and the implementation is very basic. I'd like to use @turfjs formalism and helpers (invariants, etc.), but I'm not really used to it.
API
coordsMap(input, transformer) => returns output (same shape as input)
Params
input: GeoJSON (FeatureCollection<Any>|Geometry<Any>|Coordinates<Any>|Position|GeometryCollection)transfomer:function(position)=> returnstransformedPositionposition: [lng, lat[, ...rest]]transformedPosition: any, ideally a position
output: GeoJSON<Any>, exactinputdeep clone, with only coordinates mapped through transformer
Questions :
Is that a good idea ?
Could it be integrated into turf ?
What about also
featuresMap, which would basically do the same stuff, but with features ?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing coordEach and coordsReduce APIs, then compare the linked traverse-geojson implementation. Done means adding a coordsMap operation that returns a deep-cloned GeoJSON value with only coordinates transformed, while preserving the input shape and supporting the listed input forms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100