I have a reference polygon "R", and others polygons (in grey).
I want to separate each grey polygon in multiple polygons, depending on the distance to R with different Buffers :
- The red line is R with a 5 meters buffer
- The green line is R with a 20 meters buffer
- The purple line is R with a 50 meters buffer
I don't know how to achieve this simply, because in this case, the smaller grey polygon should be split into 3 polygons, and I'm able to split it in only 2 in one query.
If I have 3 buffer, should I do 3 different queries to fill my table, or is there a way to do it in one time ?
The criteria for the splitting is the distance to R.
The small grey polygon can be split in 3 polygons, determined by : - The area before the red line - The area between red and green line - The area after the green line
My full query is : -- 5m zone
create table splited_polygons as
select p.id, p.nom, 5 as distance, ST_Intersection(ST_MakeValid(ST_Buffer(h.geom::geography, 5)::geometry), ST_MakeValid(p.geom)) as geom
from polygons p, hydro h;
-- 5m-20m zone
insert into splited_polygons (id, nom, distance, geom)
select p.id, p.nom, 20 as distance, ST_Intersection(ST_MakeValid(p.geom), ST_Difference(ST_Buffer(h.geom::geography, 20)::geometry, ST_Buffer(h.geom::geography, 5)::geometry)) as geom
from polygons p, hydro h;
-- 20m-50m zone
insert into splited_polygons (id, nom, distance, geom)
select p.id, p.nom, 50 as distance, ST_Intersection(ST_MakeValid(p.geom), ST_Difference(ST_Buffer(h.geom::geography, 50)::geometry, ST_Buffer(h.geom::geography, 20)::geometry)) as geom
from polygons p, hydro h;
-- > 50m zone
insert into splited_polygons (id, nom, distance, geom)
select p.id, p.nom, 100 as distance, ST_Difference(ST_MakeValid(p.geom), ST_Buffer(h.geom::geography, 50)::geometry) as geom
from polygons p, hydro h;