# Should I join all of my polygons to make a single polygon for point-in-polygon search?

I have a set of of polygons. Sometimes they are completely disconnected (like separate patches). Other times, two sides of two polygons may touch each other (when the polygons are adjacent like on a chess board). The polygons never cross each other. In other words, their intersection is always empty.

I need to check if a point is contained in any one of those polygons. Is there a way I can build a single geometry using these polygons and check if the point is in it?

Currently I'm building a long `WHERE` close with `OR` conditions and do something like the below:

``````st_contains(st_GeomFromText('POLYGON(("+polygon+"))'), st_GeomFromText(CONCAT('POINT()')))
``````

How about `ST_Contains()` or `ST_Within()`?

https://dev.mysql.com/doc/refman/5.7/en/spatial-relation-functions-object-shapes.html

Perhaps you need `AND ST_Distance(...) > 0`?

More likely, you want `AND NOT ST_Touches(...)`.

I need to check if a point is contained in any one of those polygons. Is there a way I can build a single geometry using these polygons and check if the point is in it?

No, don't do that. It's slower to test a big geom than the small ones. Put all the polygons in the a table.

Example,

``````CREATE TABLE t ( geom geometry NOT NULL );
ALTER TABLE t ADD SPATIAL INDEX(g);
INSERT INTO t VALUES
(ST_GeomFromText('Polygon((0 0,0 5,5 5,5 0,0 0))'))
;
``````

Query,

``````SELECT ST_AsText(geom)
FROM t
WHERE MBRIntersects( geom, Point(1,1) );
``````

vs

``````SELECT ST_AsText(geom)
FROM t
WHERE MBRIntersects( geom, Point(15,15) ); -- no polygon that covers this.
``````