在Turfjs中找到LineString与多边形边界相交的坐标 [英] Find co-ordinates where LineString intersects a Polygon border in turfjs

查看:1333
本文介绍了在Turfjs中找到LineString与多边形边界相交的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Turfjs中是否可以确定LineString与多边形边界相交的坐标?

Is there a way in Turfjs to determine the co-ordinates at which a LineString intersects with the border of a polygon?

有多种方法可以确定一个点是否在多边形内,还有多种方法可以确定一个点是否在一条直线上,依此类推,但我似乎无法找出一种方法来询问这条线在什么时候与该多边形的边界相交" .

There's a number of ways to find out if a point is within a polygon and a number of ways to find out if a point is on a line and so on, but I can't seem to figure out a way to ask "at what point does this line intersect this polygon's border".

我可以使用线相交算法枚举多边形中的点以找到该点,但是我想知道是否还有其他草皮"方式.

I could enumerate the points in the polygon using a line intersection algorithm to find that point but I was wondering if there's a more "turf" way of doing this.

对于上下文,我已经加载了GPX轨道,并希望估计轨道进入/退出定义区域的位置/时间.

For context, I've loaded a GPX track and want to estimate the location/time at which the track enters/exits a defined area.

由于GPX磁道仅以特定间隔记录位置,因此通常情况是在时间tN记录的pN在区域之外,而在时间tN + 1记录的pN + 1在区域内. 如果我可以得到线(pN,pN + 1)与多边形边界相交的点,则可以估算出轨迹穿过多边形的确切时间.

Because a GPX track only records locations at specific intervals it usually the case that pN recorded at time tN is outside the area and pN+1 recorded at time tN+1 is inside the area. If I can get the point at which line (pN, pN+1) intersects the polygon's border I can estimate the exact time the track crosses into the polygon.

推荐答案

最终,turfjs似乎没有执行此操作的API.

Ultimately, turfjs does not seem to have an API for doing this.

我能够通过枚举GeoJSON对象中的点来构造线段序列,从而得到想要的答案,然后我使用了

I was able to get the answer I wanted by enumerating the points in the polygon from the GeoJSON object to construct a sequence of line segments and then I used maxogden/geojson-js-utils linesIntersect function to test for intersection points.

这篇关于在Turfjs中找到LineString与多边形边界相交的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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