沿方法不工作如预期的TurfJS

  • 本文关键字:TurfJS 方法 工作 turfjs
  • 更新时间 :
  • 英文 :


我对turfJS的along()方法有一个问题。似乎turfJS与我的坐标有问题。

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);

代码运行后,我得到的控制台日志如下:

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

可以看到坐标是-37。和35。但是当我沿着这条线(-37和145)走1英里时,我不明白为什么它在这么远的地方(就像地球的一半在这条线的另一边!)

当使用TurfJS文档中的测试坐标时,它似乎工作得很好,但与我的坐标有关。这怎么可能呢?

你可以在这里找到带有示例的文档:http://turfjs.org/static/docs/module-turf_along.html

当使用它们的示例坐标

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

结果是(即使只使用2个点并且使用小于1英里:它总是返回正确的点):

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

坐标对的顺序不对。GeoJSON期望坐标对的[longitude, latitude]排序。

以下是GeoJSON规范:http://geojson.org/geojson-spec.html

这是一个方便的坐标对排序参考:http://www.macwright.org/lonlat/

这里有一个网站,你可以使用它来快速可视化你的GeoJSON: http://geojson.io/

相关内容

最新更新