如何使用PostGIS扩展名正确存储LAT/长值

发布于 2025-02-10 10:59:27 字数 1119 浏览 0 评论 0原文

描述

我是从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅 2025-02-17 10:59:27

看起来经度和纬度被交换

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文