postgresql基于postgis常用空间函数

1、st_astext 空间二进制转文本

select st_astext(geo) from <table>

2、ST_AsGeoJSON 空间数据转geojson格式

select ST_AsGeoJSON(geom) from <table> limit 10

3、ST_Transform 坐标转换

select st_transform(geom,3857) from mytable

4、st_srid 查询数据表坐标系

select st_srid(geom) from mytable

5、ST_GeomFromText 文本转二进制

select ST_GeomFromText('POINT(119.976900368929 31.8078044056892)',3857)

6、计算线路长度(米)

SELECT patrolid, st_length(ST_Transform(geom,3857))

FROM public.patrolrecord where patrolid='3d4f8e0d-e759-469f-b78e-50f6445b56c9'

ST_Area(ST_Transform(geom,3857))

7、空间相交计算

判断点是否在面内:

select ST_DWithin(ST_SetSRID(ST_MakePoint(117.272031,31.868486),4326),(SELECT geom from mytable where xzqhcode='340103009'),0)

8、矩形查询

_st_intersects(st_transform(ST_MakeEnvelope(" + leftTopX + "," + leftTopY + "," + rightBottomX + "," + rightBottomY + ",4326" + "),4326),geom)

9、多边形查询

SELECT gid,year,cc,gb,ec,name,type,cc,gb,ec,name,type,st_astext(geom) wkt FROM mytable where ST_Intersects(st_geometryfromtext('wkt',4326), geom) and year='2017'

10、根据已存在经纬度字段更新geometry字段

update mytable set geom =ST_SetSRID(ST_MakePoint(longitude,altitude),4326) where id=138

11、查询两点之间的距离(获取面状要素几何中心)

select jdm,st_distance(ST_Centroid(geom),ST_GeomFromText('POINT(117.12927656982 31.9223723088035)',4326),true) as distance from mytable order by distance asc limit 5

12、合并多个几何对象

update mytable set geom=SELECT st_union(geom) from tb_duty_area where (uid=49 or uid =107) WHERE uid=363

相关推荐
小嵌同学2 分钟前
Linux:malloc背后的实现细节
大数据·linux·数据库
R瑾安17 分钟前
mysql安装(压缩包方式8.0及以上)
数据库·mysql
代码的余温22 分钟前
MySQL Cluster核心优缺点
数据库·mysql
Mr.Entropy2 小时前
请求超过Spring线程池的最大线程(处理逻辑)
数据库·sql·spring
GBASE2 小时前
“G”术时刻:南大通用GBase 8c数据库权限管理场景实践(二)
数据库
wearegogog1233 小时前
MySQL中实施排序(sorting)及分组(grouping)操作
数据库·mysql
2301_803554523 小时前
MySQL 主从读写分离架构
数据库·mysql·架构
正在走向自律3 小时前
Ubuntu系统下Python连接国产KingbaseES数据库实现增删改查
开发语言·数据库·python·ubuntu·kingbasees·ksycopg2
没有bug.的程序员4 小时前
Redis 内存管理机制:深度解析与性能优化实践
java·数据库·redis·性能优化·内存管理机制
小蒜学长4 小时前
基于SpringBoot+Vue的健身房管理系统的设计与实现(代码+数据库+LW)
java·数据库·vue.js·spring boot·后端