Search code examples
postgresqlpostgis

How to check if polygon in one table intersect with point and radius from second table?


How can I check if polygon in one table intersect with point and radius from second table ?

  • first table we have field (name: area) ,type geometry which contains polygon.
  • second table we have 2 fields:
    • field (name: pt) ,type: geometry which contains point
    • field (name: radius) ,type: int

The geometry values in WKB format

I want to check if the polygon intersect with the circle (point + radius).

How can I do it ?


Solution

  • You can use the ST_Distance function to find the distance between the polygon and the point. If the distance between them is less than the radius, then the polygon would intersect with a circle around the point with that radius.

    Example query:

    SELECT *
    FROM polygon_table, circle_table
    WHERE ST_Distance(polygon_table.area, circle_table.pt) <= circle_table.radius;