PostGIS: multipolygon bounding box

SELECT id, ST_Box2D(areas) AS bbox FROM mytable;

In this example, the table table "mytable" contains two columns: " id " is a unique line identification number and " areas " is a geometry field containing one MULTIPOLYGON for each row.


This is great for multithreads containing only one polygon, but some lines have very polyhedral polygons, so the bounding box does not matter if the polygon contains one polygon in Europe and one in Canada, for example.

So, I need a way to get one box2d per polygon for each multipolygon, but I haven't found it yet. More precisely, my goal is to return one multipolygon per line containing one box2d per polygon.


First example

  • id : 123
  • area : multipolygon containing only one oval polygon in Australia
  • therefore, bbox should return a multipolygon containing only one rectangle (bounding box) in Australia

Second example

  • id : 321
  • area : multipolygon containing one circle in Paris, one circle in Toronto
  • therefore, bbox should return a multipolygon containing one rectangle in Paris, one rectangle in Toronto
+3
source share
2 answers

Hello

ST_Dump (http://postgis.org/documentation/manual-1.5/ST_Dump.html)

. , . , .

, , :

SELECT (ST_Dump (the_geom)). geom from mytable.

, .

, .

/

, ? , , bboxes, ( , ), bboxes - :

newTable SELECT ID, BOX2D ((ST_Dump (the_geom)). Geom) myBox from originamTable

, , , ST_Dump .

+5

(, ) . PostGIS ST_GeometryN(geometry,int) (: http://postgis.refractions.net/docs/ST_GeometryN.html). ST_NumGeometries.

:

- - the_geom, gid 1 - , st_numgeometries ( , 1 0):

=> select st_box2d(st_geometryn(the_geom, 1)) from tl_2009_06075_cousub00 \
 where gid = 1;

                                st_box2d                                 
-------------------------------------------------------------------------
 BOX(-123.173828125 37.6398277282715,-122.935707092285 37.8230590820312)
(1 row)

=> select st_box2d(st_geometryn(the_geom, 2)) from tl_2009_06075_cousub00 \
 where gid = 1;

                                  st_box2d                                  
----------------------------------------------------------------------------
 BOX(-122.612289428711 37.7067184448242,-122.281776428223 37.9298248291016)
(1 row)
+1

Source: https://habr.com/ru/post/1768921/


All Articles