返回 LINESTRING 的百分比(SQL Server 2008 地理)
我想在 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 循环遍历每组点,并计算我的兴趣点是否位于该部分内。在我看来,逻辑似乎是合理的,但它没有返回预期的结果(我知道结果)
我有以下症结点:
- 计算
@path
上 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:
- Calculating a point which lies between 2 points on
@path
- 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 useSTLineFromText
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论