简体   繁体   English

如何从以下 json 数组类型创建线串几何?

[英]How to create from a the following json array type a linestring geometry?

I want to create a LineString geometry with sql statements in postgresql :我想在 postgresql 中使用 sql 语句创建 LineString 几何:

'LINESTRING(11.617730473115067 48.19782098770711, ..., ..., 11.618709999927699 48.19985004114398)' 'LINESTRING(11.617730473115067 48.19782098770711, ..., ..., 11.618709999927699 48.19985004114398)'

from the following JSON Code :来自以下 JSON 代码:

{ "type": [ "LineString", "LineString" ], "coordinates": [ [ 11.617730473115067, 48.19782098770711 ], [ 11.617959999927661, 48.19828004114453 ], [ 11.617999999927662, 48.1983600411445 ], [ 11.618139999927674, 48.19867004114437 ], [ 11.61840999992768, 48.19925004114419 ], [ 11.618709999927699, 48.19985004114398 ] ] } { “类型”:[ “线段形式”, “线段形式”], “坐标”:[[11.617730473115067,48.19782098770711],[11.617959999927661,48.19828004114453],[11.617999999927662,48.1983600411445],[11.618139999927674,48.19867004114437],[11.61840999992768,48.19925004114419] [ 11.618709999927699, 48.19985004114398 ] }

How can i split this JSON Array und concatante to the LineString Text.如何将此 JSON 数组和连接拆分为 LineString 文本。

You can try this :你可以试试这个:

SELECT 'LINESTRING(' || string_agg(e.elt->>0 || ',' || e.elt->>1, ',' ORDER BY e.id) || ')'
  FROM json_array_elements(your_json_code->'coordinates') WITH ORDINALITY AS e(elt, id)

This query builds the LINESTRING() with the elements in the order of the json array associated to the key 'coordinates'此查询以与键“坐标”关联的 json 数组的顺序使用元素构建 LINESTRING()

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

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