[postgis-users] Delete lines with other lines
Nicolas Ribot
nicolas.ribot at gmail.com
Mon Feb 6 08:39:46 PST 2012
> Hi
>
> I'm looking for a way to deletes lines (table_A) with others lines
> (table_B).
>
> I attach an image.
>
> I'm near the final result with the following query but "more than one row
> returned by a subquery...")
>
> delete from table_A a WHERE o.the_geom IN
> (select st_linemerge (ST_Difference(a.the_geom, b.the_geom))
> FROM table_B b, (SELECT distinct (st_union
> (ST_Intersection(b.the_geom, a.the_geom))) as the_geom
> FROM table_A a, table_B b
> WHERE
> (ST_Intersects(a.the_geom, b.the_geom) ) ) b);
>
After some exchange with Martin, the purpose is to "remove" older
parts of linestrings from one table (original) if they are coincident
with new linestring coming from another table (cutter) (replace old
parts by new parts):
1°) keep "original" linestring segments that are not covered by table
B "cutter" segments:
drop table fragments;
create temporary table fragments as
select o.gid, st_multi(st_difference(o.geom, c.geom)) as geom
from original o, cutter c
where st_contains(o.geom, c.geom)
or st_overlaps(o.geom, c.geom);
2°) delete cut linestrings from "original":
delete from original where gid in (select gid from fragments);
3°) Insert cutter linestrings and cut segments
-- insertion des fragments dans original
insert into original (gid, geom) (select gid, geom from fragments);
-- insertion des cutter
insert into original (geom) (select geom from cutter);
Attributes are not taken into account here. They probably should be.
Nicolas
More information about the postgis-users
mailing list