convert Postgres geometry format to WKT

前端 未结 1 596
星月不相逢
星月不相逢 2020-12-19 19:44

I have a Postgres table which stores polygon geometry in its specific format in one of the column, something like this-

0103000020E61000000100000004000000B86         


        
相关标签:
1条回答
  • 2020-12-19 19:56

    Have you tried this?

    SELECT ST_AsText(your_geom_column) FROM your_table
    

    Example:

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

    Geometries as EWKT:

    db=# SELECT geom FROM tmp;
                        geom                    
    --------------------------------------------
     0101000000000000000000F03F0000000000000040
     010100000000000000000000400000000000001040
    

    Geometries as WKT:

    db=# SELECT ST_AsText(geom) FROM tmp;
     st_astext  
    ------------
     POINT(1 2)
     POINT(2 4)
    

    In case you fancy GeoJSON ..

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

    .. or even GML

    db=# SELECT ST_AsGML(geom) FROM tmp;    
                               st_asgml                            
    ---------------------------------------------------------------
     <gml:Point><gml:coordinates>1,2</gml:coordinates></gml:Point>
     <gml:Point><gml:coordinates>2,4</gml:coordinates></gml:Point>
    
    0 讨论(0)
提交回复
热议问题