博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
postgresql计算两点距离(经纬度地理位置)
阅读量:4041 次
发布时间:2019-05-24

本文共 1427 字,大约阅读时间需要 4 分钟。

转自:

postgresql计算两点距离

jpa中写法,加上::geography转化经纬度的坐标计算,\\作为转译符

@Query(value = "select f from bc_contact f where f.data_end='2' and " +            " ST_Distance(ST_SetSRID(f.point,4326)\\:\\:geography," +            " ST_SetSRID(ST_MakePoint(:lon,:lat),4326)\\:\\:geography) < :distance ",nativeQuery = true)    List
nearbyList(@Param("lon") double lon,@Param("lat") double lat,@Param("distance") double distance) ;

 

 

下面两种方法:

select 

ST_Distance(
    ST_SetSRID(ST_MakePoint(115.97166453999147,28.716493914230423),4326)::geography,
    ST_SetSRID(ST_MakePoint(106.00231199774656,29.719258550486572),4326)::geography
),
ST_Length(
    ST_MakeLine(
        ST_MakePoint(115.97166453999147,28.716493914230423),
        ST_MakePoint(106.00231199774656,29.719258550486572)
    )::geography
)
备注:

ST_GeomFromText('LINESTRING(115.97166453999147 28.716493914230423,106.00231199774656 29.719258550486572)')与

ST_MakeLine(
    ST_MakePoint(115.97166453999147,28.716493914230423),
    ST_MakePoint(106.00231199774656,29.719258550486572)
)等价

ST_GeomFromText('POINT(115.97166453999147 28.716493914230423)',4326)与

ST_SetSRID(ST_MakePoint(115.97166453999147,28.716493914230423),4326)等价

ST_SetSRID(ST_MakePoint(115.97166453999147,28.716493914230423),4326)::geography与

Geography(ST_SetSRID(ST_MakePoint(115.97166453999147,28.716493914230423),4326))、
ST_GeographyFromText('SRID=4326;POINT(115.97166453999147 28.716493914230423)')等价
(::geography是postgis中的转换类型语法,把geometry转成geography)

 

转载地址:http://mradi.baihongyu.com/

你可能感兴趣的文章
慢慢欣赏linux 内核模块引用
查看>>
kprobe学习
查看>>
慢慢欣赏linux phy驱动初始化2
查看>>
慢慢欣赏linux CPU占用率学习
查看>>
2020年终总结
查看>>
Homebrew指令集
查看>>
React Native(一):搭建开发环境、出Hello World
查看>>
React Native(二):属性、状态
查看>>
JSX使用总结
查看>>
React Native(四):布局(使用Flexbox)
查看>>
React Native(七):Android双击Back键退出应用
查看>>
Android自定义apk名称、版本号自增
查看>>
adb command not found
查看>>
Xcode 启动页面禁用和显示
查看>>
【剑指offer】q50:树中结点的最近祖先
查看>>
二叉树的非递归遍历
查看>>
【leetcode】Reorder List (python)
查看>>
【leetcode】Linked List Cycle (python)
查看>>
【leetcode】Linked List Cycle (python)
查看>>
【leetcode】Candy(python)
查看>>