返回 LINESTRING 的百分比(SQL Server 2008 地理)

发布于 2024-12-18 10:15:15 字数 905 浏览 3 评论 0原文

我想在 SQL 2008 R2 中创建一个函数,给定 3 个参数(@path geography、@start_pct float、@end_pct float),将返回基于 @ 长度百分比的线串路径

例如
@start_pct = 0@end_pct = 0.5时,返回@path的前半部分,当@start_pct = 0.5时@end_pct = 1,它将返回 @path 的后半部分,当 @start_pct = 0.25@end_pct = 0.75,它将返回@path的中间50%,但是 - @start_pct@end_pct可以是

我尝试过的任何内容(0 到 1 之间):我使用 STPointN 循环遍历每组点,并计算我的兴趣点是否位于该部分内。在我看来,逻辑似乎是合理的,但它没有返回预期的结果(我知道结果)

我有以下症结点:

  1. 计算 @path 上 2 点之间的点
  2. 我将生成的线串存储为字符串 (nvarchar(max)) 但我 认为它可能会耗尽空间(我正在使用的一些路径有一个 很多点)。我想在最后使用 STLineFromText 将其转换回地理。

在发布我的令人尴尬的业余代码之前,我有一种感觉,这应该有点简单,也许我把它复杂化了。

以前有人这样做过吗?他们可以帮忙吗?

编辑:实际上 - 刚刚解决了它,但看起来仍然比应有的复杂得多。回到办公室后将发布代码。

I want to create a function in SQL 2008 R2 that, given 3 parameters (@path geography, @start_pct float, @end_pct float), will return a linestring based on percentage of length of @path.

For example
when @start_pct = 0 and @end_pct = 0.5, it will return the first half of @path, when @start_pct = 0.5 and @end_pct = 1, it will return the last half of @path, when @start_pct = 0.25 and @end_pct = 0.75, it will return middle 50% of @path, but - @start_pct and @end_pct could be anything (between 0 and 1)

I have tried: I looped through each set of points using STPointN and calculated whether my points of interest lied within that section. In my head it, the logic seemed sound, but it's not returning the expected results (of which I know the result)

I have the following sticking points:

  1. Calculating a point which lies between 2 points on @path
  2. I was storing my resulting linestring as a string (nvarchar(max)) but I
    think it may run out of space (some of the paths I am using have a
    lot of points). I wanted to use STLineFromText at the end to
    convert it back to a geography.

Before I post my embarrassingly amateur code, I have a feeling that this should be somewhat easy and perhaps I'm over complicating it.

Has anyone done this before and could they lend a hand?

Edit: Actually - just solved it, but still seems far more complicated than it should be. Will post code when back in office.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文