SQL:从两列lat,long_中更新新列作为几何点

问题描述 投票:0回答:2

背景

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

  • lat纬度
  • long_经度

我尝试过的

我正在尝试创建一个将Pointlat组合在一起的几何数据类型列[C0

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

long_

我得到的错误

但出现以下错误:

ALTER TABLE hospitals_healthcenters_jointed_to_evacuationzones
  ADD       shape Point
  ;

UPDATE  hospitals_healthcenters_jointed_to_evacuationzones
  SET   shape = Point("long_", "lat")
sql geospatial latitude-longitude alter-table
2个回答
1
投票

假设您使用的是PostgreSQL

使用PostGIS扩展名

已安装扩展名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 ,对于具有纬度经度的点,存在PostGIS数据类型。

添加列:

geography

为每个记录更新列ALTER TABLE hospitals_healthcenters_jointed_to_evacuationzones ADD COLUMN geo_point GEOGRAPHY(POINT,4326); (基于列geo_pointlong中的现有坐标:]

lat_

UPDATE hospitals_healthcenters_jointed_to_evacuationzones SET geo_point = 'SRID=4326;POINT(' || long || ' ' || lat_ || ')'; 的数据值以文本形式给出,请参见以下示例和说明:

'SRID = point; POINT(4326)'

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

使用本机数据类型

没有安装PostGIS,您仍然具有geometric类型-71.104 42.315。这种类型的值是使用几何转换函数point构造的。

添加列:

point

更新每条记录的点(基于point(double precision, double precision)类型的列ALTER TABLE hospitals_healthcenters_jointed_to_evacuationzones ADD COLUMN geo_point POINT; double中的现有坐标:] >>

long

如果安装并应使用PostGIS

,此(本机)几何点以后可以转换为geographic点。

0
投票
lat_
© www.soinside.com 2019 - 2024. All rights reserved.