简体   繁体   English

使用postgis选择转储的多部分几何到数组中

[英]Select dumped multipart geometries into array with postgis

i'm running the following query on a table of multipart polygons: 我在多部分多边形表上运行以下查询:

SELECT id, surface_cnrtd, array_agg(igeom)
FROM (select id, st_astext(st_pointonsurface(geom)) as surface_cnrtd, 
          st_dump(geom) as igeom from my_table where id = '10020080') sub
GROUP BY dauid, surface_cnrtd;

I would like to return a row with the (id i've indicated, a point geometry for the pointonsurface, an array of the path and geometries for each individual part of the multipart polygon). 我想返回一行(id我已经指出,一个点子几何表面的点几何,一个多边形多边形的每个单独部分的路径和几何的数组)。 I know that polygon 10020080 is mulitpart because if I change the query to this: 我知道多边形10020080是mulitpart,因为如果我将查询更改为:

SELECT id, surface_cnrtd, array_agg(igeom)
 FROM (select id, st_astext(st_pointonsurface(geom)) as surface_cnrtd, 
          (st_dump(geom)).path as igeom from my_table where id = '10020080') sub
 GROUP BY dauid, surface_cnrtd;

it returns this: 它返回:

('10020080', 'POINT(-54.3834654151038 47.6947475)', [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19]])

but when I run the original query my array has only the 1st geometry, like this: 但是当我运行原始查询时,我的数组只有第一个几何,如下所示:

('10020080', 'POINT(-54.3834654151038 47.6947475)', '{"({1},0103000020E61000000..........................BC0F110C64FE3E64740)"}

can anyone help me get the paths and the geometry of the dumped polygon into an array? 任何人都可以帮助我将转储多边形的路径和几何形状放入数组中吗?

You can put the first query into a CTE (aka WITH clause) and then aggregate the dumped geometries as you wish: 您可以将第一个查询放入CTE (也称为WITH子句),然后根据需要聚合转储的几何:

WITH j AS(
SELECT 1 AS id, 'POINT(-54.3834654151038 47.6947475)'::geometry AS surface_cnrtd,
   ST_Dump('MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),
           ((15 5, 40 10, 10 20, 5 10, 15 5)))') AS geom 
)
SELECT j.id, ST_AsText(j.surface_cnrtd), array_agg(j.geom)
FROM j
GROUP BY j.id, j.surface_cnrtd;


 id |              st_astext              |                                                                                                                                                                                array_agg                                                                                                                                                                                
----+-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1 | POINT(-54.3834654151038 47.6947475) | {"({1},010300000001000000040000000000000000003E40000000000000344000000000008046400000000000004440000000000000244000000000000044400000000000003E400000000000003440)","({2},010300000001000000050000000000000000002E4000000000000014400000000000004440000000000000244000000000000024400000000000003440000000000000144000000000000024400000000000002E400000000000001440)"}
(1 Zeile)

If you wanna stick to your syntax ... 如果你想坚持你的语法......

SELECT id, ST_AsText(surface_cnrtd), array_agg(igeom)
FROM (SELECT 1 AS id, 'POINT(-54.3834654151038 47.6947475)'::geometry AS surface_cnrtd, 
      ST_Dump('MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),
           ((15 5, 40 10, 10 20, 5 10, 15 5)))') as igeom) sub
GROUP BY id, surface_cnrtd;

id |              st_astext              |                                                                                                                                                                                array_agg                                                                                                                                                                                
----+-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1 | POINT(-54.3834654151038 47.6947475) | {"({1},010300000001000000040000000000000000003E40000000000000344000000000008046400000000000004440000000000000244000000000000044400000000000003E400000000000003440)","({2},010300000001000000050000000000000000002E4000000000000014400000000000004440000000000000244000000000000024400000000000003440000000000000144000000000000024400000000000002E400000000000001440)"}
(1 Zeile)

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

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