我应该如何在不使用 PostGIS 的情况下在 Postgres 中表示纬度和经度?

yaz*_*com 12 postgresql

我应该如何在不使用 PostGIS 的情况下在 Postgres 中表示纬度和经度?我使用的系统不允许 SQL passthrough,所以我不能使用 POSTGIS。

Tom*_*omH 14

您可以在没有 postgis 的情况下使用内置的 POINT 数据类型。


Jac*_*las 6

您还可以为latitude和使用单独的列,longitude或者创建您自己的类型。无论哪种方式,约束允许的值都可能是好的,在这个例子中,如果类型用于多个表,我还使用来避免重复约束:

create domain latitude_t as double precision not null 
                                             check(value>=-90 and value<=90);
create domain longitude_t as double precision not null 
                                              check(value>-180 and value<=180);

create type geocoord_t as (latitude latitude_t, longitude longitude_t);

create table my_table(id serial, geocoord geocoord_t);

insert into my_table(geocoord) values ((31.778175,35.22995));

select id, (geocoord).* from my_table;
 id | latitude  | longitude
----+-----------+-----------
  1 | 31.778175 |  35.22995
Run Code Online (Sandbox Code Playgroud)


小智 5

对于非 GIS 应用程序,我只使用列,正如 Jack 所建议的那样,尽管我不关心检查值。在附加列中还指定数据 (IE NAD27 )是一个好主意,因为数据对于正确解释值很重要。