[postgis-users] How to calculate the symmetric difference oflinestrings and polygons (i.e. linestrings which do notintersect polygons)

Nicolas Ribot nicolas.ribot at gmail.com
Sun Feb 20 05:28:15 PST 2011


On 1 February 2011 00:55, Randall, Eric <ERandall at eriecountygov.org> wrote:
> I guess what I meant was:
>
> select st_difference(streets,st_intersection(streets,forests)) as streets
> from streets, forests
> where st_intersects(streets,forests)
> union
> select streets
> from streets, forests
> where not st_intersects(streets,forests)
>

Isn't it something like:

select st_difference(
	streets.geometry,
	st_intersection(
		streets.geometry,
		forests.geometry)) as streets
from streets, forests
where st_intersects(streets.geometry,forests.geometry)
UNION
select streets.geometry
from streets
where streets.gid not in
(select streets.gid from streets, forests
where st_intersects(streets.geometry,forests.geometry));

Otherwise, the negation of st_intersects in the second query returns
false positives

Nicolas



More information about the postgis-users mailing list