postgresql数据库中存储经纬度或电子围栏

在postgresql数据库中,如果字段类型是geometry或者是(Type),我们要更新该字段为经纬度(坐标),可以尝试采取以下脚本:

1.存经纬度

update device set shape = ST_GeomFromText(‘POINT(108.658463 34.1437)’, 4610) where id=‘a6a2c56a-5f7d-48a9-a213-f2c4360e4f3b’

如需展示轮廓,则获取一组几何坐标

update building set shape = ST_GeomFromText(‘POLYGON((121.415703 31.172893,121.415805 31.172664,121.416127 31.172751,121.41603 31.172976,121.415703 31.172893))’,4610) where objectid = 81

2.存空间信息

update device set shape = st_GeomFromText('[["13540590.2738545,3488536.66830615","13540666.5189164,3488577.10006504","13540730.989878,3488491.09500687","13540637.9626006,3488450.56659938","13540630.8489416,3488453.01866445","13540590.2738545,3488536.66830615"]',3857) where id=‘a6a2c56a-5f7d-48a9-a213-f2c4360e4f3b’

存储后:0106000020110F00000100000001030000000100000005000000226078DDA33B6841D2E096074D674441141DEA27765B6841418B152B406544413F4E50775F5E6841F78D4FC2C54C44410B5670C6EB3968410BEC19DB343D4441226078DDA33B6841D2E096074D674441

页面展现:

 

 

3.查看

 select id,st_astext(shape ) from  device  

参考文章:https://blog.csdn.net/rosejeck/article/details/82962511

posted @ 2021-10-27 10:50  徐徐图之  阅读(2390)  评论(0编辑  收藏  举报