插入WKT后,PostGIS会自动转换吗? [英] Does PostGIS automatically convert upon inserting WKT?

查看:331
本文介绍了插入WKT后,PostGIS会自动转换吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对PostGIS还是很陌生,所以请多多包涵.

I'm quite new to PostGIS so bear with me.

假设我有一个定义如下的表:

Suppose I have a table defined as follows:

CREATE TABLE gtest (name varchar, geom geometry);

首先,要插入的内容是:

At first, to insert, I was doing something like:

INSERT INTO gtest
VALUES (
    'Polygon',
    ST_GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))',4326)
);

然后我发现仅通过执行以下操作仍可以工作:

I then discovered that it still works by only doing this:

INSERT INTO gtest
VALUES (
    'Polygon',
    'SRID=4326;POLYGON((0 0,1 0,1 1,0 1,0 0))'
);

当我执行查询时未将geom值转换回WKT时,它们均已正确编码.如果我将该列转换为EWKT,则同样,一切都将正确显示.

When I do a query without converting the geom values back into WKT, they are both encoded properly. Same if I convert the column to EWKT, everything displays properly.

幕后是否正在进行转换?如果我不调用ST_GeomFromText()进行插入,使用该列的所有其他功能是否可以正常工作?

Is there a conversion going on behind the scenes? And if I insert without calling ST_GeomFromText(), will all other functions using the column work fine?

谢谢

推荐答案

有几种自动转换为geometry类型的类型.

There are several automatic cast to and from the geometry type.

您可以在PostgreSQL中键入\dC,您将看到所有可用的演员表,包括:

You can type \dC in PostgreSQL and you will see all available casts, including:

                                     List of casts
     Source type         |         Target type         |      Function      |   Implicit?
-------------------------+-----------------------------+--------------------+---------------
text                     | geometry                    | geometry           | yes

doc 或此由于强制转换是隐式的,这意味着您无需指定即可使用它.请注意,您可以使用::geometry:

Since the cast in implicit, it means you don't have to specify it to use it. Note that you can "force" it using ::geometry:

select st_asText('SRID=4326;POLYGON((0 0,1 0,1 1,0 1,0 0))'::geometry);
           st_astext
--------------------------------
 POLYGON((0 0,1 0,1 1,0 1,0 0))
(1 row)

关于列的可用性,该列的类型为geometry,因此该列中的任何内容均为geometry,并且可由需要geometry的任何函数使用.数据如何到达那里(自动转换,转换,从其他几何图形中提取等)不再重要.

Regarding the column usability, the column is of type geometry so anything that is in this column is a geometry and can be used by any function requiring a geometry. How the data got there (automatic cast, conversion, extraction from another geometry etc) is not relevant anymore.

这篇关于插入WKT后,PostGIS会自动转换吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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