ST_MAKELINE discarding duplicate points even if not consecutive

我们两清 提交于 2020-03-04 23:21:35

问题


Consider this simplified example:

SELECT ST_MAKELINE([
  ST_GEOGPOINT(5, 51),
  ST_GEOGPOINT(5, 52),
  ST_GEOGPOINT(5, 51)
])

I would expect this to construct a line with three points, that doubles back on itself. Instead, what I'm getting is:

LINESTRING(5 51, 5 52)

It seems that BigQuery is discarding duplicate points, even if they are not consecutive. This is messing up my distance calculation, which involves taking the ST_LENGTH of the resulting linestring.

As a workaround, I'm constructing a series of linestrings, each of two consecutive points, then summing the distance of those. But it's awkward and verbose.

Is there a way to create the linestring without dropping duplicate points?


回答1:


What happens is BigQuery GIS discards duplicate overlapping edges (not vertices).

E.g. you can have line string A, B, C, A and if A, B, and C are not on a single line, nothing is discarded, A is present twice in the line. But if two edges exactly overlap - the overlapping section is discarded.

On the other hand, here there are no duplicate vertices, but second edge completely overlaps the first one, so it is ignored:

SELECT ST_MAKELINE([
  ST_GEOGPOINT(5, 51),
  ST_GEOGPOINT(5, 53),
  ST_GEOGPOINT(5, 52)
])

LINESTRING(5 51, 5 52, 5 53)

There is currently no way to avoid this behavior - BigQuery Geography represents a point set, and as sets go, when you union two identical sets you get just one copy of this set.



来源:https://stackoverflow.com/questions/58234223/st-makeline-discarding-duplicate-points-even-if-not-consecutive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!