简体   繁体   English

将 Postgres 几何格式转换为 WKT

[英]convert Postgres geometry format to WKT

I have a Postgres table which stores polygon geometry in its specific format in one of the column, something like this-我有一个 Postgres 表,它在其中一列中以特定格式存储多边形几何,就像这样 -

0103000020E61000000100000004000000B8627F336B1554405DD602FFA2733A40B8627FA7601554403851F8EBC7723A40B8627FC38F15544036D539E90B733A40B8627F336B1554405DD602FFA2733A40

I know how to convert this single value to WKT using ST_AsText which will give me POLYGON((Lat Long)).我知道如何使用ST_AsText将这个单一值转换为 WKT,这会给我 POLYGON((Lat Long))。 But I want to convert whole column into WKT format.但我想将整列转换为 WKT 格式。

How to achieve this?如何实现这一目标?

Thanks!谢谢!

Have you tried this?你试过这个吗?

SELECT ST_AsText(your_geom_column) FROM your_table

In the following examples I'll show you a few ways to serialise your geometries - data sample with two points encoded as 4326 (WGS84):在以下示例中,我将向您展示几种序列化几何的方法 - 两个点的数据样本编码为 4326 (WGS84):

CREATE TEMPORARY TABLE tmp (geom GEOMETRY);
INSERT INTO tmp VALUES ('SRID=4326;POINT (1 2)'),
                       ('SRID=4326;POINT (2 4)');

Geometries as WKB (default):几何图形作为WKB (默认):

SELECT geom FROM tmp;
                        geom                        
----------------------------------------------------
 0101000020E6100000000000000000F03F0000000000000040
 0101000020E610000000000000000000400000000000001040

Geometries as WKT and EWKT (EWKT = WKT with an explicit Spatial Reference System):作为WKTEWKT几何(EWKT = WKT 具有显式空间参考系统):

SELECT ST_AsText(geom),ST_AsEWKT(geom) FROM tmp;
 st_astext  |      st_asewkt       
------------+----------------------
 POINT(1 2) | SRID=4326;POINT(1 2)
 POINT(2 4) | SRID=4326;POINT(2 4)

In case you fancy GeoJSON ..如果您喜欢GeoJSON ..

SELECT ST_AsGeoJSON(geom) FROM tmp;
             st_asgeojson             
--------------------------------------
 {"type":"Point","coordinates":[1,2]}
 {"type":"Point","coordinates":[2,4]}

.. or even GML .. 甚至GML

SELECT ST_AsGML(geom) FROM tmp;
                                     st_asgml                                      
-----------------------------------------------------------------------------------
 <gml:Point srsName="EPSG:4326"><gml:coordinates>1,2</gml:coordinates></gml:Point>
 <gml:Point srsName="EPSG:4326"><gml:coordinates>2,4</gml:coordinates></gml:Point>

.. the Google Earth enthusiasts also have their fun! .. 谷歌地球爱好者也有他们的乐趣! Geometries as KML几何图形作为KML

SELECT ST_AsKML(geom) FROM tmp;
                   st_askml                    
-----------------------------------------------
 <Point><coordinates>1,2</coordinates></Point>
 <Point><coordinates>2,4</coordinates></Point>

And the list goes on..!而这样的例子不胜枚举..! In the PostGIS documentation there are other fancy ways to serialise geometries.PostGIS documentation还有其他奇特的方法来序列化几何图形。

Demo: db<>fiddle演示: db<>fiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM