使用 SQL 2008 空间函数,如何构造表示两个(或多个)POINT 实例之间的线的 LINESTRING?

发布于 2024-07-11 23:23:12 字数 397 浏览 5 评论 0原文

定义几个点如下:

declare @p1 geography, @p2 geography
set @p1 = 'POINT(1 2)'
set @p2 = 'POINT(6 8)'

现在我想获得这两点之间的最短线。 我可以使用什么函数来获取这条线? (即,它应该输出 LINESTRING(1 2, 6 8) 或 LINESTRING(6 8, 1 2))

我知道我可以通过将点格式化为 WKT,进行一些字符串操作,然后将其解析回来来做到这一点,但这似乎很荒谬。 当然有某种方法可以直接从一系列点构造线串吗?

(对于“几何”类型,我可以使用 @p2.STUnion(@p1).STConvexHull(),但没有适用于地理类型的 STConvexHull()。)

Define a couple of points as follows:

declare @p1 geography, @p2 geography
set @p1 = 'POINT(1 2)'
set @p2 = 'POINT(6 8)'

Now I'd like to obtain the shortest line between these two points. What function can I use to get this line? (i.e., it should output a LINESTRING(1 2, 6 8) or LINESTRING(6 8, 1 2))

I know I could do this by formatting the points as WKT, doing a bit of string manipulation, and then parsing it back, but that seems ridiculous. Surely there's some way to construct a linestring directly from a series of points?

(With "geometry" types, I can use @p2.STUnion(@p1).STConvexHull(), but there's no STConvexHull() for a geography type.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟若柳尘 2024-07-18 23:23:13

在 T-SQL 中有两种方法可以实现:

declare @p1 geography = 'POINT(1 2)', @p2 geography = 'POINT(6 8)';

-- using geometry
SELECT geography::Parse(geometry::Parse(@p2.STUnion(@p1).ToString()).STConvexHull().ToString())

-- using lat, long methods
SELECT geography::Parse('LINESTRING('+str(@p1.Long)+' '+str(@p1.Lat)+','+str(@p2.Long)+' '+str(@p2.Lat)+')')

There are two ways to do it in T-SQL:

declare @p1 geography = 'POINT(1 2)', @p2 geography = 'POINT(6 8)';

-- using geometry
SELECT geography::Parse(geometry::Parse(@p2.STUnion(@p1).ToString()).STConvexHull().ToString())

-- using lat, long methods
SELECT geography::Parse('LINESTRING('+str(@p1.Long)+' '+str(@p1.Lat)+','+str(@p2.Long)+' '+str(@p2.Lat)+')')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文