Module/Method proposal makeIterable()
See original GitHub issue@DenisCarriere’s new proposals in #1202 spurred me into starting to write this module, but I’m not having a lot of luck, and I want to talk it over w/ you all because maybe I’m stepping on discussions that you’ve already had.
Simply put, I don’t like turf.featureEach()
. I wish there were a way to do something like:
featureCollection = turf.makeIterable(turf.points([[0, 0], ... ]));
var namesArray = featureCollection.map(function(f){ return f.properties.name;});
featureCollection.forEach(function(f){ f.properties.fillColor = "#aa0000"; });
if(featureCollection.length > 100){ console.log("you have a big data set!");};
IIRC, in python, as long as the object responds to two hidden methods, it exposes the object to all of the enumerable methods. It seems like ES6 has something similar w/ Symbol.iterator
, if not quite as flexible.
My suggestion then, is having turf.makeIterable()
add a bunch of methods to a feature collection so we can use them like arrays. I don’t know if this is a terrible idea, but in writing my modules, I certainly wished feature collections had, at least, map()
and filter()
methods. I know turf provides turf.featureReduce()
in addition to turf.featureEach()
.
Or would attaching methods to geojson objects cause compatibility problems?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
-1 from me sorry @muziejus although I understand the sentiment. I don’t think we should be tinkering with the geojson object given that it is a recognised spec, it’s a smidge unintuitive but not really that bad.
The intention was good with
Symbol.iterator
, however we won’t be tinkering with the GeoJSON object.However we will be eventually adding iterators (apparently it will speed things up), I’ll open a dedicated issue for just that.
Closing this issue.