我有一个带有SRID 3857数据的几何字段的PostGIS表。我想将几何质心作为纬度/经度坐标,但似乎无法正确转换值:
SELECT
ST_X(ST_CENTROID(geometry)),
ST_Y(ST_CENTROID(geometry)),
ST_X(ST_TRANSFORM(ST_CENTROID(geometry),3857)) AS LONG,
ST_Y(ST_CENTROID(ST_TRANSFORM(geometry,3857))) AS LAT
FROM my_table
=> -8220067.19453888107、4997528.08142071683,-8220067.19453888107、4997528.08142071683
答案 0 :(得分:5)
您正在使用{/ 3}}(伪墨卡托),它不是经度/纬度,而是米。
要获取经度/纬度值,您需要使用3857 projection:
db=# SELECT
ST_X(ST_Centroid(geometry)),
ST_Y(ST_Centroid(geometry)),
ST_X(ST_Centroid(ST_Transform(geometry, 4326))) AS long,
ST_Y(ST_Centroid(ST_Transform(geometry, 4326))) AS lat
FROM my_table;
st_x | st_y | long | lat
-------------------+------------------+-------------------+------------------
-8220067.19453888 | 4997528.08142072 | -73.8421199734375 | 40.8994922746749
(1 row)