[英]Create new column with coordinates from centroids using st_transform in PostGIS / PostgreSQL
I have geometry data that I'm trying to transform to lon lat and store in a new column.我有几何数据,我试图将其转换为 lon lat 并存储在新列中。 I have created a new column called 'coordinates' and written the following query:我创建了一个名为“坐标”的新列并编写了以下查询:
UPDATE places_centroids
SET coordinates = st_y(st_transform(new_centroid, 4326)) AS lat,
st_x(st_transform(new_centroid, 4326)) AS lon;
But it returns: ERROR: ERROR: syntax error at or near LINE 2: ...coordinates = st_y(st_transform(new_centroid, 4326)) AS lat,但它返回:错误:错误:第 2 行或附近的语法错误:...坐标 = st_y(st_transform(new_centroid, 4326)) AS lat,
However, it works fine when i writing the query with a select statement:但是,当我使用 select 语句编写查询时,它工作正常:
SELECT st_y(st_transform(new_centroid, 4326)) AS lat,
st_x(st_transform(new_centroid, 4326)) AS lon
FROM places_centroids;
Can anyone see what's wrong with my query?任何人都可以看到我的查询有什么问题吗?
You can create two columns, lat and lng for example of type double precision and do this:您可以创建两列,lat 和 lng,例如双精度类型,然后执行以下操作:
UPDATE places_centroids
SET lat = st_y(st_transform(new_centroid, 4326)),
lng= st_x(st_transform(new_centroid, 4326));
or define coordinates as the native point type:或将坐标定义为本地点类型:
UPDATE places_centroids
SET coordinates = point(st_y(st_transform(new_centroid, 4326)),
st_x(st_transform(new_centroid, 4326)));
I personally prefer to store in two columns.我个人更喜欢存储在两列中。
Best regards,此致,
Bjarni比亚尼
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.