空间表转为geojson

  1. 把空间表转为geojson
WITH cc_c AS (
SELECT name,name_2,name_3,st_transform(st_simplify(st_transform(geom,3857), 7827),4326) from countries_4326_s  
),
 features AS (
    SELECT
        st_asgeojson (cc_c.*) :: json AS feature
    FROM
        cc_c
) SELECT
    json_build_object (
        'type',
        'FeatureCollection',
        'features',
        json_agg (features.feature)
    )
FROM
    features
WITH cc_c AS (
    SELECT
        NAME,
        name_2,
        name_3,
        st_transform (
            st_simplify (
                st_transform (geom, 3857),
                7827
            ),
            4326
        )
    FROM
        countries_4326_s
),
 features AS (
    SELECT
        st_asgeojson (cc_c.*) :: json AS feature
    FROM
        cc_c
) SELECT
    json_build_object (
        'type',
        'FeatureCollection',
        'features',
        json_agg (features.feature)
    )
FROM
    features
原文地址:https://www.cnblogs.com/lishanyang/p/15723455.html