问题
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