PostGis的几个简单应用算法

PostGis的几个简单应用算法

2.根据点在数据库里查询在哪个多边形中

SELECT 
id,
geom
from dt_cy 
where 
ST_Contains(geom, st_geometryfromtext("POINT(113.458729 34.816974)",4326));          

3.使用knn(最近邻法),计算距离多边形最近的点

select 
*
from 
teatcyd 
ORDER BY teatcyd.geom <-> (SELECT geom from dt_cy where gid =74833) limit 1

4.创建索引(通用索引)提升查询效率

CREATE INDEX teatcyd_geom_idx ON teatcyd USING GIST (shape);