0

I have a problem with the along() method of turfJS. It seems that turfJS has problems with my coordinates.

var alongLine = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "LineString",
    "coordinates": [
      [-37.86902659740041, 144.6185302734375],
      [-37.86902659740041, 145.57159423828125]
    ]
  }
};

var newPoint = Turf.along(alongLine, 1, 'miles');
console.log('Walked 1 miles', newPoint);

After the code was running this is the console log I get:

  Walked 1 miles { type: 'Feature',
geometry: { 
  type: 'Point',
  coordinates: [ -37.86902659740041, 35.367001095372345 ] },
  properties: {} 
}

As you can see the coordinates are -37. and 35. But when walking 1 mile along this line (which is -37 and 145) I cant understand why its this far away point (its like the half of the earth away of the line!).

When working with the test coordinates in the docs of TurfJS it seems to work fine, but with my coordinates its breaking. How can this be ?

The docs with the along example you can find here: http://turfjs.org/static/docs/module-turf_along.html

When using their example coordinates

[-77.031669, 38.878605],
[-77.029609, 38.881946],
...

the result is (even when only using 2 points and using less then a mile: its always the right point which is returned):

Walked 1 miles { type: 'Feature',
geometry: { 
  type: 'Point',
  coordinates: [ -77.02417351582903, 38.885335546214506 ] },
  properties: {} 
}

1 Answer 1

2

You have your coordinate pairs in the wrong order. GeoJSON expects [longitude, latitude] ordering of coordinate pairs.

Here's the GeoJSON specification: http://geojson.org/geojson-spec.html

Here is a handy reference for coordinate pair ordering: http://www.macwright.org/lonlat/

And here's a site you can use to quickly visualize your GeoJSON: http://geojson.io/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.