我有一个返回一组点的查询:
point | weight
------------------------------+-------------------
POINT(-122.036623 37.578196) | 0.554083094555874
POINT(-122.033693 37.575257) | 0.641117478510029
POINT(-122.044285 37.575406) | 0.287249283667622
POINT(-122.038225 37.569244) | 1
POINT(-122.04517 37.583408) | 0.691260744985673
POINT(-122.040132 37.580424) | 0.748925501432665
POINT(-122.033158 37.583625) | 0.434097421203438
POINT(-122.059415 37.559942) | 0.531160458452722
POINT(-122.049714 37.574723) | 0.671919770773639
POINT(-122.049308 37.569589) | 0.644699140401146
POINT(-122.056148 37.569934) | 0.521848137535817
POINT(-122.055692 37.575972) | 0.263610315186246
POINT(-122.059211 37.580715) | 0.424068767908309
如何基于weight
计算作为点的加权平均值的点?
我可以在PostGIS中使用point.x和point.y。
答案 0 :(得分:3)
我不知道是否有内置函数,但您可以轻松计算加权平均值 - 它是X和Y的加权平均值。这将是:
select sum(st_x(point) * weight) / sum(weight),
sum(st_y(point) * weight) / sum(weight)
from (<your query>) q
您可以使用st_point()
将其重新转换为一个点。