如何将纬度/经度对转换为PostGIS地理类型? [英] How do I convert a latitude/longitude pair into a PostGIS geography type?

查看:108
本文介绍了如何将纬度/经度对转换为PostGIS地理类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一堆纬度/经度对加载到PostGIS地理类型中,以便能够按位置查询.

I'm trying to load a bunch of latitude/longitude pairs into a PostGIS geography type so as to be able to query by location.

尤其是我有一个带有浮动纬度和经度列以及一个geography(Point, 4326)列的表.我想做

In particular I have a table with float latitude and longitude columns and a geography(Point, 4326) column. I would like to do

update mytable set geography = ???

该文档似乎建议以下方法起作用:

The documentation appears to suggest that the following should work:

update mytable set geography = ST_GeogFromText('POINT(' || latitude || ' ' ||
                                                           longitude || ')');

不是.我不知道它将这一点解释为什么意思,但是它只允许经度在-90到90之间,因此显然不是经度.

It doesn't. I don't know what it's interpreting this point as meaning, but it only allows the longitude to lie between -90 and 90, so it's clearly not a longitude.

那我该怎么办?

推荐答案

...我的愚蠢.显然正确的顺序是经度,纬度.我愚蠢地认为两个坐标都具有相同的范围(-180到180),因此觉得有些微妙的事情正在发生.

...sigh. Stupidity on my part. Apparently the correct order is longitude, latitude. I was fooled into thinking that both coordinates had the same range (-180 to 180) so thought something more subtle was going on.

这篇关于如何将纬度/经度对转换为PostGIS地理类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆