Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 17 » SQL Anywhere Server - Spatial Data Support » Spatial types and functions » ST_Geometry type

ST_Contains method

Tests if a geometry value spatially contains another geometry value.

Name Type Description



The other geometry value that is to be compared to the geometry-expression.

  • BIT

    Returns 1 if the geometry-expression contains geo2, otherwise 0.


The ST_Contains method tests if the geometry-expression completely contains geo2 and there is one or more interior points of geo2 that lies in the interior of the geometry-expression.

geometry-expression.ST_Contains( geo2 ) is equivalent to geo2.ST_Within( geometry-expression ).

The ST_Contains and ST_Covers methods are similar. The difference is that ST_Covers does not require intersecting interior points.

Note If the geometry-expression contains circularstrings, then these are interpolated to line strings.
Note This method cannot be used with geometries in round-Earth spatial reference systems.
  • SQL/MM (ISO/IEC 13249-3: 2006)



The following example tests if a polygon contains a point. The polygon completely contains the point, and the interior of the point (the point itself) intersects the interior of the polygon, so the example returns 1.

SELECT NEW ST_Polygon( 'Polygon(( 0 0, 2 0, 1 2, 0 0 ))' )
	.ST_Contains( NEW ST_Point( 1, 1 ) )

The following example tests if a polygon contains a line. The polygon completely contains the line, but the interior of the line and the interior of the polygon do not intersect (the line only intersects the polygon on the polygon's boundary, and the boundary is not part of the interior), so the example returns 0. If ST_Covers was used in place of ST_Contains, ST_Covers would return 1.

SELECT NEW ST_Polygon( 'Polygon(( 0 0, 2 0, 1 2, 0 0 ))' )
	.ST_Contains( NEW ST_LineString( 'LineString( 0 0, 1 0 )' ) )

The following example lists the ShapeIDs where the given polygon contains each Shape geometry. This example returns the result 16,17,19. ShapeID 1 is not listed because the polygon intersects that row's Shape point at the polygon's boundary.

FROM SpatialShapes
WHERE NEW ST_Polygon( NEW ST_Point( 0, 0 ), 
                      NEW ST_Point( 8, 2 ) ).ST_Contains( Shape ) = 1