Spatial Datatype (geometry) to GeoJSON

后端 未结 3 1776
醉话见心
醉话见心 2021-02-09 05:21

I want to convert geom (geometry) datatype to GeoJSON. How could I do that?

For example, the geometry in WKT:

    POLYGON((4552         


        
3条回答
  •  孤街浪徒
    2021-02-09 06:03

    If you have access to PostgreSQL/PostGIS, you can use ST_GeomFromText to read in the geometry and ST_AsGeoJSON to save the geometry as a GeoJSON:

    SELECT ST_AsGeoJSON(ST_GeomFromText('POLYGON((455216.346127297 
     4288433.28426224,455203.386722146 4288427.76317716,455207.791765017
     4288417.51116228,455220.784166744 4288423.30230044,455216.346127297
     4288433.28426224))'));
    

    , which generates:

    -------------------------------------------------------------------------------
    
     {"type":"Polygon","coordinates":[[[455216.346127297,4288433.28426224],
    [455203.386722146,4288427.76317716],[455207.791765017,4288417.51116228],
    [455220.784166744,4288423.30230044],[455216.346127297,4288433.28426224]]]}
    
        (1 row)
    

提交回复
热议问题