postgresql计算两点距离

postgresql计算两点距离

下面两种方法:

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)

以上语句记得先在数据库中 安装postgis扩展模块
相关推荐
©️2020 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客 返回首页