I was checking the best way to cut linestrings by points.
The scenario is: lots of streets, need the segments cut by intersect points, kind of this:
linestrings (full uncuted by points) table
st_intersection points table
I need to get the independent linestring segments cut by the intersection points table.
I'm using PostGIS functions, and found several approaches, but every one of them has giving me some kind of issue.
Here's what I already tested:
Line table: 1 row , st_memunion of 1200 lines Point table: 1700 rows (points)
What's bad: really takes really lot of time and memory flush. Can't create multiple tables at same time cause memory just can't handle it. And the result is dirty and messy. Instead of giving me the correct row number, and I need to clean it up later (well explained here Split lines at intersection points)
CREATE TABLE lines_with_messy_result AS ( SELECT ((ST_DUMP(ST_SPLIT(a.geom,b.ix))).geom) as geom FROM st_union_lines a INNER JOIN lots_of_points b ON ST_INTERSECTS(a.geom, b.ix) ); --then need to clean this up create table lines_segments_cleaned as ( SELECT DISTINCT ON (ST_AsBinary(geom)) geom FROM lines_with_messy_result );
source of this way/approach: https://stackoverflow.com/questions/25753348/how-do-i-divide-city-streets-by-intersection-using-postgis
Same lines/points table. Still messy results and need to clean this up. Still lots of time to finish query.
--messy table Create table messy_lines_segments as Select row_number() over() as id, (st_dump(st_split(input.geom, blade.ix))).geom as geom from st_union_lines input inner join lots_of_points blade on st_intersects(input.geom, blade.ix); --then cleaning the messy table delete from messy_lines_segments a where exists ( select 1 from messy_lines_segments b where a.id != b.id and st_coveredby(b.geom,a.geom) );
source of this way / approach : Split lines at intersection points
I also found this function: https://github.com/Remi-C/PPPP_utilities/blob/master/postgis/rc_Split_Line_By_Points.sql
which has the good thing that it does not leave a messy_result that then I need to clean it up. But you do need st_memunion from both sides (lines table and points table)
It's kind of:
create table osm.calles_cortadas_03segmentos_sanluis as ( SELECT result.geom FROM osm.calles_cortadas_01uniones_sanluis AS line, osm.calles_cortadas_00intersecciones_sanluis AS point, rc_split_line_by_points( input_line:=line.geom ,input_points:=point.ix ,tolerance:=4 ) AS result );
But its also super-long hours for getting the results. And I also tried with longer tables (10k lines, 14k points) and I just get memory out issues.
I also tried Esri's ArcGIS with also bad results...
So, what's the best way of getting this done with PostGIS geom functions?
I mean, without stepping into topology.
Or what's your best recommendation?