postgis常用操作手冊


查詢所有函數:

SELECT * FROM pg_proc;

更新坐標系st_setsrid,查看坐標系:st_srid

創建空間索引:

CREATE INDEX [indexname] ON [tablename] USING GIST ( [geometryfield] );
example:create index idx_poi5_geom on poi5 using gist(geom);

使用空間查詢:
select count(*) from poi5 a,poi5 b
where a.pid='20080243019'
and st_within(b.geom,st_buffer(a.geom,0.001));
執行計划:

如果不使用空間索引執行計划:

兩個geometry之間關系:within、disjoint、intersects、union、intersection,difference

St_within(geom A,geom B)返回A是否處於B中
St_disjoint(geom A,geom B)返回A是否不在B中
St_intersects(geom A,geom B)返回A是否和B有接觸
St_union(geom A,geom B)返回A+B兩個幾何的合並
St_intersection(geom A,geom B)返回A和B的交集
St_difference(geom A,geom B)返回A與B不相交的部分幾何
select
st_difference(
st_buffer(
st_geomfromtext('Point(116 39)'),0.7),
st_buffer(
st_geomfromtext('Point(117 39)'),0.7)) geom

  

判斷幾何是否空:st_isempty(geom A)

幾何類型轉換:

wkt轉geometry:st_geomfromtext(wkt)
select st_geomfromtext('Point(122 33)')
geometry轉wkt:st_astext(geometry)
select st_astext(st_geomfromtext('Point(122 33)'))
geometry轉geojson:st_asgeojson(geometry)
select st_asgeojson(st_geomfromtext('Point(122 33)'))
geojson轉geometry:st_geomfromgeojson(geojson)
select 
st_geomfromgeojson(
st_asgeojson(st_geomfromtext('Point(122 33)')))
geometry轉geohash:st_geohash(geometry)
select st_geohash(st_geomfromtext('Point(116 39)'))
geohash轉geometry:st_geomfromgeohash
select st_geomfromgeohash('wwfmzesx7yvjugxr3nzv')

  

獲取幾何信息:

得到幾何類型:st_geometrytype(geometry A)
根據經緯度,獲取兩點距離(單位:米):st_distance_sphere(point a,point b)
select
st_distance_sphere(st_geomfromtext('Point(116 39)'),
st_geomfromtext('Point(117 39)'))

  

如果兩個幾何在指定范圍內,則返回true,否則false:st_dwithin(geom A,geom B)

select count(*) from poi5 a,poi5 b
where a.pid='20080243019'
and st_dwithin(b.geom,a.geom,0.001);

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM