如何从 geojson 对象查询?

How to query from geojson object?

在下面贴出的查询中我想查询以下信息

    ST_Transform(ST_SetSRID(ST_GeomFromGeoJSON(feature->>'geometry'),4326),25832) AS LIDARDataPolygonsAsGeometry

featuresCollection 是一个 geojson 对象。

如何从 geojson 对象查询?

    query="""   
            WITH data AS (
                SELECT '{featuresCollection}'::json AS featuresCollection
            )
            SELECT 
                LIDARDataPolygonsAsGeometry,
            FROM (
                SELECT 
                    ST_Transform(ST_SetSRID(ST_GeomFromGeoJSON(feature->>'geometry'),4326),25832) AS LIDARDataPolygonsAsGeometry
                
            FROM (SELECT json_array_elements(featuresCollection->'features') AS feature 
                    FROM data) AS f) j
            GROUP BY LIDARDataPolygonsAsGeometry
        """.format(table=config['PostgreDB']['table_name_test'], width=config['Grid']['cell_width'], height=config['Grid']['cell_height'],bufferRadius=config['Grid']['buffer_radius'],featuresCollection=featuresCollection)

只需在子查询中解压缩您的特征集合,提取几何图形并应用您想要的转换,例如来自名为 t 的 table,其列 geojson 包含 GeoJSON 字符串:

SELECT 
 ST_Transform(
  ST_SetSRID(
    ST_GeomFromGeoJSON(feature->>'geometry'),4326),25832)  
FROM (SELECT json_array_elements(geojson->'features') AS feature FROM t) data;