ST_Intersects(g1,g2)

Returns 1 (TRUE) if any part of two geometries intersect or touch at a single point.

Parameters

Parameter Type Description
g1 geometry Defines a geospatial area using the WKT notation
g2 geometry Defines a geospatial area using the WKT notation

Returns

Boolean

Example

SELECT * FROM geospock.default.largetable AS large
WHERE ST_Intersects(ST_Point(large.longitude, large.latitude), ST_Polygon('POLYGON((1 0, 1 5, 20 5, 20 0, 1 0))'))

Usage

For some queries, you may need to analyze the point where a recorded geometry (stored as e.g. a linestring in a dataset) intersects with a geometry shape in a query. To optimize these queries, you should specify a bounding box or a bounding geometry for the points associated with each event, for example:

SELECT * from geospock.default.largetable large 
WHERE ST_Intersects(ST_LineFromText(large.linestring), ST_LineFromText('LINESTRING(-50 33, -40 39, -40 40, -41 40)') 
AND large.latitude BETWEEN 33.50 AND 33.60 AND large.longitude BETWEEN 135.10 AND 135.20

An example query using POLYGON and ST_Intersects:

SELECT * FROM geospock.default.largetable AS large
WHERE ST_Intersects(ST_Point(large.longitude, large.latitude), ST_GeometryFromText('POLYGON((10 10, 10 20, 20 10, 10 10))'))