SQL:从两列lat,long_中将新列更新为几何点 背景我尝试过的我遇到错误使用PostGIS扩展使用本地数据类型

背景

我有一个具有以下属性的表hospitals_healthcenters_jointed_to_evacuationzones

  • lat纬度
  • long_经度

我尝试过的

我正在尝试创建结合了Pointlat的几何数据类型列long_

我使用了发现的以下代码:

ALTER TABLE hospitals_healthcenters_jointed_to_evacuationzones
  ADD       shape Point
  ;

UPDATE  hospitals_healthcenters_jointed_to_evacuationzones
  SET   shape = Point("long_","lat")

我遇到错误

但是出现以下错误:

ERROR:  function point(character varying,numeric) does not exist
LINE 4: SET     shape = Point("long_","lat");
                        ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883
Character: 157
SODOU619157158 回答:SQL:从两列lat,long_中将新列更新为几何点 背景我尝试过的我遇到错误使用PostGIS扩展使用本地数据类型

假设您正在使用PostgreSQL

使用PostGIS扩展

在安装扩展名为 PostGIS 的情况下,具有纬度经度的点的geography数据类型。

>

要添加列:

ALTER TABLE hospitals_healthcenters_jointed_to_evacuationzones
  ADD COLUMN geo_point GEOGRAPHY(POINT,4326);

要为每条记录更新geo_point列(基于longlat_列中的现有坐标):

UPDATE hospitals_healthcenters_jointed_to_evacuationzones
  SET geo_point = 'SRID=4326;POINT(' || long || ' ' || lat_ || ')';

point的数据值以文本形式给出,请参见以下示例和说明:

  

'SRID = 4326; POINT(-71.104 42.315)'

  • 空间参考系统ID (SRID)被指定为WGS 844326(与GPS使用的相同,请参见Wikipedia
  • 地理坐标被指定为-71.104 42.315描述的POINT类型,其顺序完全相同:经度,后跟 space 作为分隔符,后跟纬度

使用本地数据类型

在未安装PostGIS的情况下,您仍然具有 geometric 类型point。 这种类型的值是使用几何转换函数point(double precision,double precision)构造的。

要添加列:

ALTER TABLE hospitals_healthcenters_jointed_to_evacuationzones
  ADD COLUMN geo_point POINT;

要更新每条记录的点(基于double类型的列longlat_中的现有坐标):

UPDATE hospitals_healthcenters_jointed_to_evacuationzones
  SET geo_point = point(long,lat_);

如果已安装并应使用 PostGIS ,则此(本机)几何点可以稍后转换为地理点。

,
 ALTER TABLE hospitals_healthcenters_jointed_to_evacuationzones
     ADD COLUMN shape geometry(Point,4326);

    UPDATE  hospitals_healthcenters_jointed_to_evacuationzones
      SET   shape = st_Setsrid(st_Point("long_"::double precision,"lat"::double precision),4326);
本文链接:https://www.f2er.com/3001707.html

大家都在问