turfjs


TurfJS Along Method not working as expected


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: {}
}
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/

Related Links

turf.within() fails but turf.inside() is successful
Distance between two points over a path with turf.js
TurfJS Along Method not working as expected

Categories

HOME
oracle12c
twitter-bootstrap-3
paraview
gdb
apache-flink
ecmascript-6
datastore
angular-formly
numbers
error-handling
entity-framework-core
tail
echo
banner
angularfire2
character
google-schemas
emoji
angular-dart
intercom
atlassian
http-post
alpacajs
symfony-2.8
vuejs
jersey-1.0
bourbon
gulp-watch
r-mice
imageresizer
roundup
jquery-multiselect
licensing
corpus
mat
ms-access-2003
calculation
mobx
recurring-events
postback
testbed
r-grid
memory-address
code-snippets
github3.py
biztalk-rule-engine
keras-layer
activexobject
html-encode
sql-delete
salesforce-communities
openalpr
connection-pool
apache-stanbol
mcustomscrollbar
congestion-control
tcc
memory-mapping
builder
geotiff
carrot2
custom-font
yii2-user
android-instrumentation
cvxpy
reporting-services-2012
seek
async.js
windows-azure-queues
x-tag
ng-grid
hclust
embedding
upx
mobiledoc-kit
relativelayout
opl
eoferror
zscript
sha512
dnssec
osc
code-documentation
cross-join
exceldatareader
variadic-templates
beatsmusic
big-ip
grails-plugin-rabbitmq
solace-mq
scrypt
jeromq
extreme-programming
vfs
faye
lambdaj
mapping-by-code
cgimage
hibernateexception
luabind
xcelsius
msr
object-database
perl5.12
java1.4

Resources

Encrypt Message