如何使用PostGIS扩展名正确存储LAT/长值
描述
我是从 Google地理编码结果进入地理列。但是根据lat/long的不同,查询返回的值与插入的值不同。我在做什么错或失踪?
repro
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE TABLE "public"."test_location" (
"name" text,
"location" GEOGRAPHY (point)
);
INSERT INTO "public"."test_location" ("name", "location")
VALUES
('test 1', ST_POINT (32.714476, -117.151735)),
('test 2', ST_POINT (36.1450444, -85.4788305));
SELECT
name,
ST_AsText (location)
FROM
"public"."test_location";
-- output:
-- |-----------------------------------------|
-- | name | ST_AsText |
-- |-----------------------------------------|
-- | test 1 | POINT(32.714476 -62.848265) | --> expected POINT(32.714476 -117.151735)
-- | test 2 | POINT(36.1450444 -85.4788305) |
-- |-----------------------------------------|
DROP TABLE "public"."test_location";
Description
I'm storing lat/long from google geocoding results into a geography column. But depending on the lat/long, the query returns different values than the one inserted. What am I doing wrong or missing?
Repro
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE TABLE "public"."test_location" (
"name" text,
"location" GEOGRAPHY (point)
);
INSERT INTO "public"."test_location" ("name", "location")
VALUES
('test 1', ST_POINT (32.714476, -117.151735)),
('test 2', ST_POINT (36.1450444, -85.4788305));
SELECT
name,
ST_AsText (location)
FROM
"public"."test_location";
-- output:
-- |-----------------------------------------|
-- | name | ST_AsText |
-- |-----------------------------------------|
-- | test 1 | POINT(32.714476 -62.848265) | --> expected POINT(32.714476 -117.151735)
-- | test 2 | POINT(36.1450444 -85.4788305) |
-- |-----------------------------------------|
DROP TABLE "public"."test_location";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来经度和纬度被交换
st_point(经度,纬度)
经度的范围为-180至180
Latitude的范围为-90至90
It looks like longitude and latitude are exchanged
ST_POINT(longitude, latitude)
Longitude has range -180 to 180
Latitude has range -90 to 90