turfjs可以在地​​理坐标和应用程序坐标之间提供坐标转换吗 [英] Can turfjs provide a coordinate transform between geo coords and application coords

查看:932
本文介绍了turfjs可以在地​​理坐标和应用程序坐标之间提供坐标转换吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从地理坐标系到另一个坐标系的转换. 我认为这样做的明显方法是给系统提供两个边界框.

I need a transform from geo coord system to/from another coord system. I'd think the obvious way to do this would be to give the two bounding boxes of the systems.

因此,如果我有一个以lon/lat坐标表示的geo bbox,并且有一个与之对应但在我自己的坐标中的非geo bbox,我希望有一个xfm可以将geo-to-me和me-到地域.

So if I had a geo bbox, in lon/lat coords, and a non-geo bbox that corresponds to that but in my own coordinates, I'd like a xfm that could convert geo-to-me and me-to-geo.

对于基于代理的编程环境,我需要它,它具有自己的基于minX,minY,maxX,maxY的坐标系统,就像Turf表示bboxes一样.例如,它也可以用于在地理坐标和画布中的像素之间进行转换.

I need this for an agent based programming environment that has its own coord system based on minX, minY, maxX, maxY, just as Turf expresses bboxes. It would also work for transforming between geo coords and pixels in a canvas, for example.

我在Turf中找不到这样的坐标变换,但是我可能会错过它,或者有一种简单的方法可以用Turf原语来完成它.

I couldn't find such a coord transform in Turf but I may be missing it, or there may be an easy way to do it with Turf primitives.

有没有办法使用Turf进行这种坐标转换?

Is there a way to use Turf for such a coord transform?

推荐答案

我将使用 proj4js 处理投影转换. 您的画布可以用伪墨卡托([x,y])表示,而草皮将继续在 WGS84 ([lon,lat]).

I'd use proj4js which handles projection conversions. Your canvas can be represented in Pseudo-Mercator ([x,y]) while turf will continue working in WGS84 ([lon, lat]).

const xyCoordsToLatLong = (xy_pair) => {
    return proj4(PSEUDO_MERC_DATUM, WGS84_DATUM, xy_pair);
}

const latLongCoordsToXY = (latlong_pair) => {
    return proj4(WGS84_DATUM, PSEUDO_MERC_DATUM, latlong_pair);
}

然后,bbox [0,0,500,200]的画布将表示为[0, 0, 0.004491576420597608, 0.0017966305679443192].

Then, a canvas of bbox [0,0,500,200] would be represented as [0, 0, 0.004491576420597608, 0.0017966305679443192].

完整演示此处.

这篇关于turfjs可以在地​​理坐标和应用程序坐标之间提供坐标转换吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆