Hi Folks,<br><br>I few weeks ago I asked this list how to generate, given a country border and some arbitrary polygons lying within it, the geometry within the country border where the arbitrary polygons do NOT lie. Regina, as usual, provided a thoughtful reply. However, I'm now revisiting this topic and am seeing some odd behavior from ST_Difference.<br>
<br>Hoping for some clarification from those in the know. I also noticed in the archives some others were confused by the results of ST_Difference. So perhaps I just don't understand the results correctly.<br><br>- I have VMAP country borders stored as polygons in table A, along with the country name.<br>
- I have a number of MULTIPOLYGONS stored in table B that exist, geographically, in various countries over the world. I've tripled checked that the MULTIPOLYGONS are all valid and clean and have no self intersections etc etc.<br>
<br>What I want is to generate the geometry that represents China minus the MULTIPOLYGONS that lie within it. Easy enough, right?<br><br>I swear the query would look just like this:<br><br>SELECT ST_Difference(A.the_geom, B.the_geom), A.country_name FROM A, B WHERE A.country_name='China' AND ST_Overlaps(b.the_geom, a.the_geom) GROUP BY A.country_name;<br>
<br>Logically, this subtracts the MULTIPOLYGONS from the Geometry represented by China and for the sake of query speed restricts the operation to only where the two overlap.<br><br>The result I get is simply all of China as a single polygon.<br>
<br>Any ideas or thoughts as to why this isn't working? I know Regina will come back with a clever LEFT JOIN, and I swear I've tried a bunch of them to no avail as well but I keep coming back to this simple query that I think should work.<br>
<br>Many Thanks.<br>-dylan<br><br clear="all"><br>