如何在 postgreSQl 中获取三个 3Dpoint 的中心?
How can I get center of three 3Dpoint in potgreSQl?
如何在 postgreSQl 中获取三个 3Dpoint 的中心?
p1 (110 120 10)
p2 (150 90 8)
p3 (165 95 11)
PostGIS 无法执行此操作(请参阅 this enhancement request)。
PostGIS 能做的最好的事情只是二维质心(通过 ST_Centroid(geom)
):
SELECT ST_AsText(ST_Centroid('MULTIPOINT Z(110 120 10,150 90 8,165 95 11)'));
st_astext
------------------------------------------
POINT(141.666666666667 101.666666666667)
但是,点的质心算法相当简单。只需平均所有维度的坐标值:
SELECT ST_AsText(ST_MakePoint(avg(ST_X(geom)), avg(ST_Y(geom)), avg(ST_Z(geom))))
FROM (
SELECT 1 AS id, 'POINT Z (110 120 10)'::geometry AS geom
UNION SELECT 2 AS id, 'POINT Z (150 90 8)'::geometry AS geom
UNION SELECT 3 AS id, 'POINT Z (165 95 11)'::geometry AS geom
) AS f;
st_astext
--------------------------------------------------------------
POINT Z (141.666666666667 101.666666666667 9.66666666666667)
其他几何类型有更复杂的算法。
如何在 postgreSQl 中获取三个 3Dpoint 的中心? p1 (110 120 10) p2 (150 90 8) p3 (165 95 11)
PostGIS 无法执行此操作(请参阅 this enhancement request)。
PostGIS 能做的最好的事情只是二维质心(通过 ST_Centroid(geom)
):
SELECT ST_AsText(ST_Centroid('MULTIPOINT Z(110 120 10,150 90 8,165 95 11)'));
st_astext
------------------------------------------
POINT(141.666666666667 101.666666666667)
但是,点的质心算法相当简单。只需平均所有维度的坐标值:
SELECT ST_AsText(ST_MakePoint(avg(ST_X(geom)), avg(ST_Y(geom)), avg(ST_Z(geom))))
FROM (
SELECT 1 AS id, 'POINT Z (110 120 10)'::geometry AS geom
UNION SELECT 2 AS id, 'POINT Z (150 90 8)'::geometry AS geom
UNION SELECT 3 AS id, 'POINT Z (165 95 11)'::geometry AS geom
) AS f;
st_astext
--------------------------------------------------------------
POINT Z (141.666666666667 101.666666666667 9.66666666666667)
其他几何类型有更复杂的算法。