如何从postgres DB中的geom列获取lat和long

时间:2017-04-20 05:57:10

标签: sql postgresql postgis

我在postgres DB中有一个名为“building_footprints”的表。

请参阅附图

Postgres table image

并在查询表下面运行

SELECT row_to_json(fc) FROM (
SELECT 'FeatureCollection' As type, array_to_json(array_agg(f)) As features FROM (
    SELECT 'Feature' As type, ST_AsGeoJSON(lg.the_geom)::json As geometry,
    row_to_json((gid, the_geom)) As properties FROM building_footprints As lg
) As f) As fc

查询结果是:

Query Output

我想将坐标value(coordinates":[[[[530500.00039933,545400.008863266],)转换为lat / long。

1 个答案:

答案 0 :(得分:0)

试试这个

SELECT id, the_geom , ST_X(the_geom::geometry), ST_Y(the_geom::geometry) FROM building_footprints;

你应该安装postgis扩展程序!

请参阅:https://gis.stackexchange.com/questions/57018/get-lon-lat-values-from-a-geography-data-type-in-postgis