Sometimes the outcome of a predicate is not intuitive, so you should test special cases to make sure you are getting the results
you want. For example, in order for a geometry to contain another geometry (
a.ST_Contains(b)=1), or for a geometry to be within another geometry (
b.ST_Within(a)=1), the interior of a and the interior of b must intersect, and no part of b can intersect the exterior of a. However, there
are some cases where you would expect a geometry to be considered contained or within another geometry, but it is not.
For example, the following return 0 (a is red) for
Case one and two are obvious; the purple geometries are not completely within the red squares. Case three and four, however, are not as obvious. In both of these cases, the purple geometries are only on the boundary of the red squares. ST_Contains does not consider the purple geometries to be within the red squares, even though they appear to be within them.
ST_Covers and ST_CoveredBy are similar predicates to ST_Contains and ST_Within. The difference is that ST_Covers and ST_CoveredBy do not require the interiors of the two geometries to intersect. Also, ST_Covers and ST_CoveredBy often have more intuitive results than ST_Contains and ST_Within.
If your predicate tests return a different result for cases than desired, consider using the ST_Relate method to specify the exact relationship you are testing for.
Discuss this page in DocCommentXchange.
|Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1|