Created
November 20, 2017 13:47
-
-
Save tcoupin/075523125d40dee1b3358fea7fd2f62a to your computer and use it in GitHub Desktop.
PlPgsql buffer+voronoi on lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop table if exists zone_buffer; | |
with | |
lines as ( | |
select pid, the_geom the_geom from itineraires | |
),--end with lines | |
voronoi as ( | |
select the_geom | |
from ( | |
select (st_dump(ST_VoronoiPolygons((select st_union(the_geom) from lines)))).geom the_geom | |
) tmp | |
),--end with voronoi | |
voronoiwithpid as ( | |
select pid, (case when st_isvalid(the_geom) then the_geom else st_buffer(st_buffer(the_geom,0.001),-0.001) end) the_geom | |
from ( | |
select l.pid, v.the_geom from voronoi v inner join itineraires l on st_intersects(l.the_geom, v.the_geom) and st_intersects((select st_union(geom) from (select * from st_dumppoints(l.the_geom)) tmp ),v.the_geom) | |
) tmp | |
),--end with voronoiwithpid | |
buffer as ( | |
select pid, st_union(the_geom) the_geom | |
from (select pid, st_buffer(the_geom, 500) the_geom from lines) tmp | |
group by pid | |
)--end with buffer | |
select b.pid, st_union(st_intersection(b.the_geom, v.the_geom)) the_geom | |
into zone_buffer | |
from buffer b, voronoiwithpid v | |
where st_intersects(b.the_geom, v.the_geom) and b.pid = v.pid | |
group by b.pid; | |
CREATE INDEX zone_buffer_geom_idx | |
ON zone_buffer | |
USING gist | |
(the_geom); | |
select Populate_Geometry_Columns((f_table_schema || '.' || f_table_name )::regclass) from geometry_columns where srid=0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment