postgis 常用函数

88 篇文章 3 订阅
70 篇文章 0 订阅

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);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值