So, I will prepare a cake for you - fruit platter, using PostGis tools, as you requested, if I correctly understood the question, and as I mentioned, the responsibility for the operation of the PostGis oven is borne by her creative team.
I will ask not to be offended by anyone in my humorous style and to understand it as a game!
The original file is sliced fruit and simple shapes (hereinafter referred to as fruit), see Figure 1 below.
Here is my recipe, and I will be helped in this by dear programmers, whom you will learn about later.
Let's begin, and for this we will create a dough in which our fruits will be laid, for which run the script:
create table poly_extent as
SELECT st_setsrid(ST_Buffer(ST_Envelope(ST_Extent(geom)),0.05),4326) as geom from poly;
See the result in Figure 2 below
Now, if there are few fruits, like in my picture, create the border of the external buffer on the fruit, or if there are many fruits, create the border of the negative buffer, for which run the script:
create table poly_buff_dump as
SELECT ((ST_Dump(ST_Boundary(ST_Union(ST_Buffer((geom),0.01, 'join=mitre mitre_limit=5.0'))))).geom) geom from poly;
And slice the buffer lines around each fruit
update poly_buff_dump SET geom=ST_RemovePoint(geom, ST_NPoints(geom)-1)
See the result in Figure 3 below
(Actually, I thought that as a result I would get broken lines (such as in a circle), but if the figures are difficult, sometimes breaks are obtained, incorrect ones, for example, one side of the rectangle fell off, etc.)
Then you need to divide the obtained lines in a convenient way for you into equal segments and extract points from them
create table poly_buff_dump_pt as
SELECT (ST_DumpPoints((geom))).geom geom from poly_buff_segm;
Result, see Figure 4 below
Now run the Voronoi tool, in this place I used the tool suggested by the link MickyT :https://gis.stackexchange.com/a/172246/120129
, as a result of which you will have created tables with the name “voronoi” for the fact that “my first assistant” is separate from the chef thanks from the chef! :-).
The second way in this step is to run the ST_VoronoiPolygons function.
Result, see Figure 5 below
Now, cut off the extra parts by running the script:
create table poly_voronoi_cut as
SELECT ST_Intersection (a.geom, b.geom) geom
from voronoi a INNER JOIN poly_extent b ON ST_Intersects (a.geom,b.geom);
Result, see Figure 6 below.
Now run the script in order to align the geodata type in LineString:
create table poly_voronoi_dump as
(ST_Dump(geom)).geom as geom
And now I will ask "my second mate" to take up my duties and mix the cake wel (Jeff - https://gis.stackexchange.com/a/785/120129), leveling it in a single layer, and for that, thanks to me for it!
CREATE TABLE poly_overlay_cut AS
SELECT geom FROM ST_Dump((
SELECT ST_Polygonize(geom) AS geom FROM (
SELECT ST_Union(geom) AS geom FROM (
SELECT ST_ExteriorRing(geom) AS geom FROM poly_voronoi_dump) AS lines
) AS noded_lines
Now it’s time for me to get to work, for which I run the script:
create table poly_voronoi_union as
SELECT b.id, (ST_ConvexHull(ST_Union(a.geom, b.geom))) geom
from poly_overlay_cut a INNER JOIN poly_buff_dump b ON ST_Intersects(a.geom,b.geom)
group by b.id, a.geom, b.geom;
and another script:
create table poly_voronoi_union_area as
SELECT ST_Union(ST_ConvexHull(ST_BuildArea(geom))) as geom from poly_voronoi_union
group by id;
see figure 7 below
As you can see in the picture, our cuts have small layers, which can be removed, as an option using ST_SnapToGrid (or in another way):
And finally, we will cut out our baked fruit from our pie, I even got a little tired standing by the oven, :-)
create table polygon_voronoi_result as
(ST_Dump(ST_Difference(a.geom, b.geom))).geom as geom
FROM poly_voronoi_union_area_snap as a JOIN poly b ON ST_Intersects(a.geom, b.geom);
Result see figure 8
Everything from this day, now everyone will learn to bake delicious pies - fruit platter. Help yourself All, and choose the pieces you, likeenough for everyone.
(P.S. It’s a pity that I really can’t feed all people, not with electronic cakes, but with real cakes, perhaps hunger would end on Earth ...)
With you was Mr. good and fair Baker, thank you all and good luck, :-)... OS.