Skip to content

Add coordMap function to complement coordEach #1438

Description

@cyrilchapon

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) => returns transformedPosition
    • position : [lng, lat[, ...rest]]
    • transformedPosition : any, ideally a position
  • output : GeoJSON<Any>, exact input deep 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 ?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions