Answer the question
In order to leave comments, you need to log in
How to determine whether a point belongs to a polygon in mysql?
You must select the id of the polygon to which the point belongs.
Mysql has the MBRWithin function which is supposed to do this.
Everything is defined well if the polygon is a rectangle, but if the polygon has a complex shape,
the point will always be inside the described rectangle.
It is necessary to check up in a polygon.
//Base
CREATE TABLE IF NOT EXISTS `cities` (
`id` int(11) NOT NULL,
`name` text NOT NULL,
`g` geometry DEFAULT NULL
);
// Geometry
SET @g = 'POLYGON ((50.4415440837958 30.559938127990726), (50.4411294575134 30.560313846725332), (50.44358926678977 30.56884328067007), (50.44398696208372 30.56849997647087), (50.4415440837958 30.559938127990726))';
UPDATE `cities` SET `g` = PolygonFromText(@g) WHERE `cities`.`id` = 1;
//Check point
SET @poi = "POINT(50.441338 30.565152)',0";
SELECT id FROM `cities` WHERE MBRWithin(GeomFromText(@poi), g ) = 1 LIMIT 1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question