point_in_polygon
Tests whether a point lies in a polygon. The outer boundary is included; a hole and its boundary are excluded.
Syntax
text
point_in_polygon(point, outer_ring [, hole, ...])
point_in_polygon(point, polygon)Arguments
point— A two-coordinate Float64 pair.outer_ring— An outer Ring containing at least three finite points.hole— An optional hole Ring, with the same shape requirements.polygon— A Polygon whose first Ring is the outer boundary and whose later Rings are holes.
All coordinates must use one consistent space, such as longitude/latitude or projected coordinates. Geometry declarations validate shapes without validating topology.
Returned value
A Bool indicating whether the point is inside under these boundary rules. SQL NULL propagates.
Examples
Inside an outer ring
sql
SELECT point_in_polygon(
tuple(1, 1),
CAST('[[0,0],[2,0],[2,2],[0,2]]' AS Ring)
)
FORMAT csv;text
trueA hole and an outer boundary
sql
CREATE TABLE regions (area Polygon);
INSERT INTO regions VALUES (CAST(
'[[[0,0],[4,0],[4,4],[0,4]],[[1,1],[3,1],[3,3],[1,3]]]'
AS Polygon
));sql
SELECT point_in_polygon(tuple(2, 2), area) AS in_hole,
point_in_polygon(tuple(0, 2), area) AS on_outer_boundary
FROM regions
FORMAT csv;text
false,true