rnirnber
rnirnber

Reputation: 615

MySQL geo-spatial query

After some research, it appears that ST_Contains determines whether the second argument is present inside the first argument as a polygon.

What function is available for querying all points inside a polygon from a points table?

Upvotes: 1

Views: 646

Answers (1)

beaver
beaver

Reputation: 17657

Here is an example of spatial query in MySql where I retrieve all points (features to be drawn on a map) inside a rectangle:

SELECT * FROM `features` 
WHERE CONTAINS(GeomFromText('POLYGON((6.71813 45.25942,
7.42126 45.25942,
7.42126 45.02695,
6.71813 45.02695,
6.71813 45.25942))'), coord);

field features.coord is of type point (see https://dev.mysql.com/doc/refman/5.7/en/spatial-datatypes.html)

Upvotes: 1

Related Questions