You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found a bit of an issue with your turf.featureCollection() function with regards to inputs, and I'd like to share as it might be a heartache for beginners of your library. It was for me.
Setup
I'm currently trying determine the number of points within a radius of another point in a node environment where I chain a turf.featureCollection() to a turf.buffer() function. When I do this, my output is not compliant with the geojson spec, and any attempt at carrying out the turf.within() function gets me zero, even though one of the compare points is the point used to generate the buffer. Here is some setup, if someone wishes to replicate:
In my package.json file, the version I'm using is current, I believe. `"@turf/turf": "^4.1.0"
constturf=require('@turf/turf')constpoint={"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-79.419281,43.795368]}}// using a silly buffer for nowconstbuffer=turf.buffer(point,1000,'kilometers')constbufferCollection=turf.featuresCollection(buffer)
When I look at the docs for featureCollection, I find that the desired input is an array, but in my case, I'm laying down an object. But instead of offering a warning or throwing an error, It just carries on producing faulty geoJSON without warning.
Possible solution
The solution may be as easy as either forcing an array if the parameter is a geojson feature, or throwing an error in line 150 if the parameter isn't array. Would using the Array.isArray(arr) fit the bill as a condition to throw an exception? Just in case, here's a compatability table for the JS method.
Thanks for building and maintaining such a lovely library! If you think this is a solution to the problem I have, I would love to contribute.
The text was updated successfully, but these errors were encountered:
brianbancroft
changed the title
turf.featureCollection() cannot determine if parameter isn't array
turf.featureCollection() cannot Determine whether Parameter isn't Array
May 21, 2017
While there could be an additional validation performed but IMHO I think a function building a collection would clearly expect an array as input and not a single object. Maybe others could chime in and if there's enough support it could be added.
👍 @brianbancroft Thanks for reporting this, I've also ran into this problem when I would accidentally add a FeatureCollection with another FeatureCollection.
Added input validation
if(!Array.isArray(features))thrownewError('features must be an Array');
Hi there,
I've found a bit of an issue with your
turf.featureCollection()
function with regards to inputs, and I'd like to share as it might be a heartache for beginners of your library. It was for me.Setup
I'm currently trying determine the number of points within a radius of another point in a node environment where I chain a
turf.featureCollection()
to aturf.buffer()
function. When I do this, my output is not compliant with the geojson spec, and any attempt at carrying out theturf.within()
function gets me zero, even though one of the compare points is the point used to generate the buffer. Here is some setup, if someone wishes to replicate:package.json
file, the version I'm using is current, I believe. `"@turf/turf": "^4.1.0"The remainder of this example takes place in the node repl. Go to a node project with turf.
From the shell:
Here is the output.
The actual problem
When I look at the docs for
featureCollection
, I find that the desired input is an array, but in my case, I'm laying down an object. But instead of offering a warning or throwing an error, It just carries on producing faulty geoJSON without warning.Possible solution
The solution may be as easy as either forcing an array if the parameter is a geojson feature, or throwing an error in line 150 if the parameter isn't array. Would using the
Array.isArray(arr)
fit the bill as a condition to throw an exception? Just in case, here's a compatability table for the JS method.Thanks for building and maintaining such a lovely library! If you think this is a solution to the problem I have, I would love to contribute.
The text was updated successfully, but these errors were encountered: