1

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()')))
0

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(...).

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.