跨表查询统计
1 | SELECT xcz_item.code,xcz_region."name","type","count"(xcz_item.code) AS count |
跨表条件统计
1 | SELECT DISTINCT a.code,a.name, |
图形操作
- 空间查询
1
2SELECT count(*) FROM njq_dk WHERE st_intersects(geom,st_geomfromtext('MULTIPOLYGON(((120.92 29.37,120.93 29.37,120.93 29.38,120.92 29.37,120.92 29.37)))',4326))
SELECT count(*) FROM njq_dk WHERE st_intersects(geom,st_geomfromtext('POLYGON((120.92 29.37,120.93 29.37,120.93 29.38,120.92 29.37,120.92 29.37))',4326)) - 创建空间索引
1
2
3
4create extension pg_trgm;
update pg_opclass set opcdefault = true where opcname='gin_trgm_ops';
CREATE index on njq_dk USING gist (geom);
CREATE index on njq_dk USING gin (geom gin_trgm_ops); - 外包多边形
1
select ST_AsText(ST_ConvexHull(ST_Collect(geom))) FROM xcz_region
- 外包矩形
1
select ST_AsText(st_Envelope(ST_Collect(geom))) FROM xcz_region
- 中心点(面质心)
1
select st_astext(st_centroid(geom)) FROM xcz_region
- 面上点(和面lable位置一致)
1
select st_astext(st_PointOnSurface(geom)) FROM xcz_region