如何从ST_Extent检索边界框的角?


16

有什么方法可以获取我们从ST_Extent得到的边界框角的纬度/经度吗?

select ST_Extent(geom) from tableName;

Answers:


25

ST_Extent返回由xmin,ymin,xmax,ymax(左下,右上坐标)组成的框:

osm=# select st_extent(way) from planet_osm_point;
                            st_extent                                
-------------------------------------------------------------------------
 BOX(2259828.73261444 5412478.55751597,3301031.7673783 6147766.43413396)

要检索与左下角对应的点,可以构建一个由左下角X坐标(st_xmin)和左下角Y坐标(st_ymin)组成的点,例如:

osm=# select st_astext(st_makepoint(st_xmin(st_extent(way)), st_ymin(st_extent(way)))) 
      from planet_osm_point;
            st_astext                 
------------------------------------------
 POINT(2259828.73261444 5412478.55751597)

请注意,由于st_extent返回一个边界框,它会将SRID去除了几何图形,因此您可能希望将其添加到新创建的点(我正在使用900913来匹配我的OSM数据的SRID):

osm=# select st_asewkt(st_setsrid(st_makepoint(st_xmin(st_extent(way)), st_ymin(st_extent(way))), 900913)) 
      from planet_osm_point;
            st_astext                 
------------------------------------------
 SRID=900913;POINT(2259828.73261444 5412478.55751597)
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.