我有PostGIS的Postgres的,我需要線串轉換爲點將線串轉換爲點數組?
我已與此answer檢查的陣列,我的問題是相似的,但也是我需要從這個
聚集到陣列
Linestring((3.584731 60.739211,3.590472 60.738030,3.592740 60.736220))
這個
["3.584731 60.739211","3.590472 60.738030","3.592740 60.736220"]
我該怎麼辦呢?
我有PostGIS的Postgres的,我需要線串轉換爲點將線串轉換爲點數組?
我已與此answer檢查的陣列,我的問題是相似的,但也是我需要從這個
聚集到陣列
Linestring((3.584731 60.739211,3.590472 60.738030,3.592740 60.736220))
這個
["3.584731 60.739211","3.590472 60.738030","3.592740 60.736220"]
我該怎麼辦呢?
好了,我不知道你爲什麼會需要這一點,但在這裏你去:
WITH
route_sequence AS (
SELECT id, path
FROM (
VALUES
(1, 'Linestring(3.584731 60.739211,3.590472 60.738030,3.592740 60.736220)'),
(2, 'Linestring(3.584731 60.739211,3.590472 60.738030,3.592740 60.736220)')
) AS route_sequence(id, path)
),
rstemp AS (
SELECT
route_sequence.id,
array_agg(
ST_X(points.geom)::CHARACTER VARYING
|| ' '
|| ST_Y(points.geom)::CHARACTER VARYING
ORDER BY points.path[1] ASC
) AS coordinates
FROM route_sequence, ST_DumpPoints(path) as points(path, geom)
GROUP BY route_sequence.id
)
SELECT *
FROM rstemp
;
我很好奇,想知道你爲什麼會在這裏需要一個數組。也許有另一種方式。你爲什麼不能保留由ST_DumpPoints
生成的初始geom
?
昨天在午夜我已經創建選擇,我需要,無論如何感謝您的答案(我會嘗試一下,也許它會工作得更快) 爲什麼我需要數組?這將被序列化爲json python for api,從這個json兩個移動應用程序(ios和android)將在地圖上創建多義線,所以這就是它 我現在將發佈我的示例 P.S.對不起,我的英語 –
好吧,那有道理:) –
WITH points_text AS (SELECT
(st_dumppoints(path)).geom AS points,
(st_dumppoints(path)).path AS points_path,
rs.id,
rcc.checkpoint_id,
rcc.route_id,
rcc."order",
rcc.is_forward,
rcc.is_primary
FROM route_cacheed_checkpoint AS rcc
JOIN route_sequence AS rs ON rs.id = ANY (rcc.next_rsq)
WHERE rcc.date = (DATE '2016-04-28') AND rcc.is_primary = TRUE)
SELECT
array_agg(to_char(ST_X(points), 'FM99.9999990') || to_char(ST_Y(points), '99.9999990') ORDER BY points_path) AS path,
pt.checkpoint_id,
pt.route_id,
pt."order",
pt.is_forward AS is_forward_direction,
pt.is_primary
FROM points_text AS pt
GROUP BY pt.id, pt.checkpoint_id, pt.route_id, pt."order", pt.is_forward, pt.is_primary
ORDER BY pt.is_forward DESC, pt."order";
你試過了什麼? –
我有選擇'WITH rstemp如(SELECT st_dumppoints(st_astext(路徑))AS路徑,ID FROM route_sequence) SELECT rcc.order, rcc.checkpoint_id, rcc.route_id, rcc.is_forward, ARRAY_AGG(ST_X (rstemp.path.geom)) FROM route_cached_checkpoint AS RCC JOIN route_sequence AS RS ON rs.id = ANY(rcc.next_rsq) JOIN rstemp ON rstemp.id = rs.id WHERE rcc.date =(DATE「2016 -04-27');' –
我建議你[創建一個函數](http://www.postgresql.org/docs/9.5/static/sql-createfunction.html)來做到這一點。 –