从PostGIS中的几何获取坐标?


Answers:



71

使用ST_AsText查看点对象:

SELECT ST_AsText(the_geom) 
       FROM myTable;

要查看XY和geom对象:

SELECT ST_X(the_geom), ST_Y(the_geom), ST_AsText(the_geom) 
       FROM myTable;

3
我相信ST_X和ST_Y仅适用于积分。它们不适用于多边形或线。
Devdatta Tengshe

你是对的Devdatta。它仅适用于积分。ST_X —返回点的X坐标;如果不可用,则返回NULL。输入必须是一点。我已经更新了我的答案。
阿拉贡

7
对于多边形/线,请使用st_x(st_centroid(the_geom))
Steve Bennett

11

带有UTM中的表格

SELECT 
ST_X(table.geometry) AS X1, --point x
ST_Y(table.geometry) AS Y1, --point y
ST_X(ST_TRANSFORM(table.geometry,4674)) AS LONG, -- longitude point x SIRGAS 2000
ST_Y(ST_TRANSFORM(table.geometry,4674)) AS LAT, --latitude point y SIRGAS 2000
ST_ASTEXT(table.geometry) AS XY, --wkt point xy
ST_ASTEXT(ST_TRANSFORM(table.geometry,4674)) AS LongLat --using st_transform to get wkt with longitude and latitude (4674 is the SIRGAS 2000 SRC by south america)
FROM
table 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.