[postgis-users] ST_Difference and ST_Buffer queries

L Bogert-O'Brien dlawbob at ncf.ca
Tue Aug 31 16:31:23 PDT 2010


Hi,

When I used ST_Difference to clip one polygon from another where part 
of the border of the polygon used for clipping is coincident with 
part of the border of the one that is being clipped, I got a border 
left which was not part of the main part of the polygon I wanted to keep.

A simple example:
I want to clip this:

|
|            xxxxxxx
|            xxxxxxx
|            xxxxxxx
|            xxxxxxx
|            xxxxxxx
|            xxxxxxx
------------------------------------

With this:
|
|     oooooooooooooo
|     oooooooooooooo
|     oooooooooooooo
|
|
|
-------------------------------------

And I get this result:
|
|            xxxxxxx
|
|
|            xxxxxxx
|            xxxxxxx
|            xxxxxxx
------------------------------------

Instead of this desired result:
|
|
|
|
|            xxxxxxx
|            xxxxxxx
|            xxxxxxx
------------------------------------

Of course my borders are not this simple and it doesn't always keep 
the whole coincident border opposite from the main part that I want 
to keep, so I suppose even though they look coincident in QGIS, they 
may not be exactly the same.

I did try buffering the clipping polygon with a small number 
(0.0000002) and it seemed to get rid of most of the coincident 
borders, but of course that way the clipping polygon is no longer its 
original size. (Note that buffering with 0.0 on the results of the 
ST_Difference had no effect.  I thought this might help when reading 
the documentation for ST_Intersection to get rid of the non-polygon 
parts.)  In addition, since I am using a lat/long Spatial Reference 
System (NAD83: srid=4629), I guess I should transform it to something 
like Lambert (eg. srid=3348) before doing the buffering, since there 
would be quite a difference in the actual amount of buffering 
depending on the latitude.  Is that right?

Does anyone have an alternate suggestion that would get rid of these 
unwanted borders, that would not involve changing the size of the 
polygon used for clipping?

Thanks for your assistance.

Loretta






More information about the postgis-users mailing list