I've been exploring the PostGIS ST_Difference function. Most OGC compliant spatial databases have this function or a similar one and it behaves more
or less the same in all so hopefully this story has implications beyond PostGIS.
This is one of those explorations where you metaphorically stare at a function or a stick for that matter and wonder how far can this thing get me with what I know already.
It happened with intersections as well
until I had exhausted all the uses I could think of for using intersections with what I already knew. Intersections also turned out to be much
easier to comprehend than differences.
SQL in general is another tool that I use often, but for some reason as simple as SQL is, I haven't quite
exhausted all its uses. I suppose because it provides a convenient bus for pushing more complicated function calculations
around.
Now if only SQL could push function pointers around as easily as it does data I could do more slick things with it.
What does ST_Difference do?
First there are 2 forms of Differences defined in the OGC specs and PostGIS has both. ST_Difference(geom1,geom2) and ST_SymDifference(geom1,geom2).
ST_Difference takes geom1 and subtracts that
portion of geom2 that is part of geom1 (the intersection) or as the PostGIS ST_Difference docs say in a more mathematically accurate way
Returns a geometry that represents the point set difference of Geometry A with
Geometry B. If you are a bitwise groupey - you may prefer the IBM DB2 definition of ST_difference The spatial equivalent of the logical AND NOT (all bits of A AND NOT bits of B)
St_SymDifference returns that portion of geom1 and geom2 that does not intersect. In theory, it can be formed with other operations for example
ST_Difference(ST_Union(geom1,geom2), ST_Intersection(geom1,geom2)) or ST_Union(ST_Difference(geom1,geom2), ST_Difference(geom2,geom1))
Continue reading "Spatial Differences"