如何将点文本转换为几何 [英] How to convert point text to geometry

查看:91
本文介绍了如何将点文本转换为几何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在数据库中安装了postgis.现在我在我的数据库中有1个区域,例如((-79.4609576808001,43.9726680183837)) 我希望该区域转换为几何类型.我在Google上进行了搜索,发现St_geomfromText会将文本转换为几何类型.

I have installed postgis in my DB. Now i have 1 regions in my DB like ((-79.4609576808001,43.9726680183837)) I want this region to convert to geometry type. I have searched on google and found that St_geomfromText will convert text to geometry type.

我的查询如下:

SELECT ST_GeomFromText(region,4326) from "erpAssets";

但这给了错误,就是说没有函数与st_geomfromtext相匹配

But it is giving error it is saying that no function matches for st_geomfromtext

推荐答案

您还可以使用ST_MakePoint,它可能更干净,因为您不必将纬度和经度值连接为文本.与ST_SetSrid结合使用,可将坐标参考系统设置为4326,例如

You can also use ST_MakePoint which is probably cleaner as you don't have to concatenate latitude and longitude values as text. Use it in conjunction with ST_SetSrid to set the coordinate reference system to 4326, eg,

Select ST_SetSrid(ST_MakePoint(lon, lat),4326) from sometable;

将返回几何类型.请注意,顺序是lon/lat(x/y),这引起了很多混乱,原因是人们在日常讲话中说lat/lon.

will return a geometry type. Note the order is lon/lat (x/y), a cause of lots of confusion, due to people saying lat/lon in everyday speech.

当您使用众所周知的文本(WKT)格式的几何图形时,例如

ST_GeomFromText通常更有用

ST_GeomFromText is generally more useful when you have a geometry in Well-known text (WKT) format, eg,

Select ST_GeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))', 4326);

如果您的数据实际上是((-79.4609576808001,43.9726680183837)格式,并且您不想像我上面建议的那样将其拆分,则用于ST_GeomFromText的正确格式是:

If your data is actually in the form ((-79.4609576808001,43.9726680183837)) and you don't want to split it up as I suggested above, the correct format to use use with ST_GeomFromText for a point is:

Select ST_GeomFromText('POINT(-79.4609576808001 43.9726680183837)', 4326)

SRID是可选的,但建议使用.

where the SRID is optional, but recommended.

有关更多信息,请参见 http://en.wikipedia.org/wiki/Well_Known_Text .

See http://en.wikipedia.org/wiki/Well_Known_Text for more information.

这篇关于如何将点文本转换为几何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆