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

相关推荐
MonolithIoT1 小时前
实战方案|设备备件无人值守仓库:连续化产线运维备件 7×24 小时数字化管控方案
运维·网络·数据库
瞬间&永恒~1 小时前
【MySQL】4-6:在同一个主机上使用 systemd 运行多个 MySQL服务器
服务器·数据库·mysql
心机之蛙qee1 小时前
Redis的主从、哨兵及集群
数据库·redis·缓存
gwf2162 小时前
磨损均衡算法(Wear Leveling)——SSD如何让每块闪存“公平退休“?
运维·数据库·人工智能·python·嵌入式硬件·算法·智能硬件
AAA@峥2 小时前
CentOS7 源码编译安装 MySQL5.7|SQL 基础操作 + 备份恢复完整实战
运维·数据库·sql·centos
xixingzhe22 小时前
spring ai简单使用skills
数据库·人工智能·spring
Fu2067213 小时前
数据库第三次作业
数据库
AI多Agent协作实战派3 小时前
AI多Agent协作系统实战(二十三):Agent读HEARTBEAT.md不读AGENTS.md——openclaw的文件加载之谜
前端·数据库·人工智能·uni-app
jun_bai4 小时前
postgresql数据库免安装版安装到windows系统
数据库·postgresql
weixin_538601974 小时前
智能体测开Day33
数据库·oracle