<div dir="ltr"><div><div><div><div>Hey all,<br><br></div>It's been a couple of days that I'm trying to compute the difference (like the geoprocessing difference with QGIS) between two geometry (polygon) tables. These tables (let's call them A and B) contain polygons where :<br></div> - polygon from A can be intersected by one or more polygon from B<br></div> - polygon from A can have no spatial relationship with polygon from B (no intersection)<br><br></div><div>To realize this difference I've joined the two tables with a "LEFT OUTER JOIN" so even if I don't have any intersection between A and B I should get the geometry from A.<br><br></div><div>Below it's an example of the SQL query :<br>*********************************<br>SELECT A.id, <br> COALESCE(<br> ST_Difference(<br> A.the_geom, <br> ST_Union(B.the_geom) <br> ), <br> A.the_geom <br> ) As the_geom <br>FROM A <br>LEFT JOIN B ON A.the_geom && B.the_geom<br>AND ST_Intersects(A.the_geom, B.the_geom)<br>GROUP BY A.id;</div><div>*********************************<br><br></div><div>The difference between objects from table A that are intersected by one or more objects from B is correct. But I don't get the objects from A that are not intersected by B. I don't understand why as I use a "LEFT OUTER JOIN" and the COALESCE function.<br><br></div><div></div><div>Could you please tell me what I'm doing wrong or what I don't understand ?<br><br></div><div>Thanks for your help.<br><br>Arnaud<br></div><div><br></div><div><div><div><div><div><div><div><br>-- <br><div class="gmail_signature"><div dir="ltr">--------------------------------------------------------------------<br>Arnaud Vandecasteele<br>SIG - WebMapping - Spatial Ontology - GeoCollaboration<br><br>Web Site<br><a href="http://geotribu.net/" target="_blank">http://geotribu.net/</a><br><a href="http://about.me/arnaud_vandecasteele" target="_blank">http://about.me/arnaud_vandecasteele</a><br><br></div></div>
</div></div></div></div></div></div></div></div>