Introduction to PostGIS 之 Spatial clustering(二)

上一篇中主要介绍了ST_SnapToGrid,现在我们用前几篇文中的features表来做下应用:

简要介绍下用到的方法:

geometry ST_Collect(geometry[] g1_array);把一系列geometries组合为单个ST_Geometry(旧版本称为GEOMETRYCOLLECTION).

geometry ST_Multi(geometry g1);把g1转化为一个MULTI* geometry。

和前几篇方法一样,连接数据库,打开查询可视化框,添加如下SQL:

SELECT ST_Multi(ST_Collect(the_geom)) As the_geom , ST_astext(ST_Multi(ST_Collect(the_geom)))
FROM features
GROUP BY ST_SnapToGrid(ST_Transform(the_geom,2327),2000,2000)

      把features中的点集聚到2000*2000 平方米的格子中,ST_Transform(the_geom,2327)是把坐标系统从4326转换为2327,因为4326的测量单位是度,2327(这里我随便找了个xi‘an 80的坐标系统)应该是米。ST_astext(ST_Multi(ST_Collect(the_geom))没多大用,只是在QGIS便于编辑样式。

更改网格大小为5000*5000:

SELECT ST_Multi(ST_Collect(the_geom)) As the_geom , ST_astext(ST_Multi(ST_Collect(the_geom)))
FROM features
GROUP BY ST_SnapToGrid(ST_Transform(the_geom,2327),5000,5000)

原文地址:https://www.cnblogs.com/shitao/p/2109620.html