question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[@turf/coordsMap] proposal

See original GitHub issue

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<Any> (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 ?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tmcwcommented, Jul 11, 2018

Untested, but this would be the general direction of implementing each suggestion. And, yes, this mutates the data, but… just clone the data ahead of time, which is just the same as what a function would do internally.

Reproject a whole GeoJSON object

coordEach(object, coord => {
  const p = reproject(coord);
  coord.length = 0;
  coord.push(...p);
});

Remove z ([lng, lat, z]) from coordinates in a whole, dirty, GeoJSON object

coordEach(object, coord => coord.pop());

// safer if only some have a z
coordEach(object, coord => {
  const [x, y] = coord;
  coord.length = 0;
  coord.push(x, y);
});

Round coordinates to 6 decimal places into a whole GeoJSON object

coordEach(object, coord => {
  for (let i = 0; i < coord.length; i++) coord[i] = parseFloat(coord[i].toFixed(6));
});
0reactions
cyrilchaponcommented, Jul 12, 2018

And about the API in itself (returning geoJSON) object… well from my external POV I understood “coordsWhatever” functions like “mimic array functions on GeoJSON objects”. I kinda agree with you, but returning an array of transformed cords would be pointless, I guess (as you loose every indexes, tree logic, features)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ellsworth Drive Synthetic Turf Proposal - Friends of Sligo Creek
Peterson Companies decided to renovate the block of Ellsworth Drive that's already mostly a pedestrian plaza. We were not in theory opposed ...
Read more >
Current Requests for Proposal - Procurement and Materials ...
Washington River Protection Solutions, LLC (WRPS) requests proposals for Independent Source ... Proposal Due Date: Wednesday, January 18, 2023, 2:00 pm.
Read more >
10 Things to Know About the Proposal for Turf Fields ... - TAPinto
The proposal calls for about 40% of the field at Edison to remain grass, with the remainder being converted into synthetic turf. 9....
Read more >
Creating a Proposal — Stratis Academy documentation
This parameter defines a brief description of the proposal. Method Name: CreateProposal. This is the Smart Contract method that we are interacting with...
Read more >
Download Position Proposal Packet
Download this free packet of sample documents and information to use when proposing a new position, including: case studies of successful programs, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found