Jump to content

How to findout if a point is in polygon area or not


beyzad

Recommended Posts

Hi there.

I got a table named `area` that has a POLYGON field.

There are some rows with specified area in table.

Now i want to check if a point ("59.5594597, 36.3556769" for example) is within the polygons or not.

 

searched a lot and none works.

my polygon has 102 points in case of need.

Thanks.

Link to comment
Share on other sites

Just now, requinix said:

Looks like you want ST_CONTAINS.

Used that. also used within. none works.

In this page: http://www.justskins.com/forums/point-in-polygon-99698.html

a guy said:

Quote

"Currently, MySQL does not implement these functions according to the
specification. Those that are implemented return the same result as the
corresponding MBR [minimal bounding rectangle]-based functions. This
includes functions in the following list other than Distance() and
Related()."

The minimal bounding rectangle of your polygon is POLYGON((0.8 0.8, 0.8
2.6, 2.6 2.6, 2.6 0.8, 0.8 0.8)). This rectangle includes all three
points. Apparently MySQL will implement proper geometric comparisons
"when they get around to it"; don't ask me why, since the basic
point-in-polygon test only takes around 10 lines of code.
 

Not sure if these functions works fine for polygons with 100+ points or not ...

Link to comment
Share on other sites

Example (Mysql 5.7)

point table

mysql> SELECT name
    ->      , x
    ->      , y
    ->      , ST_AsText(loc) as loc
    -> FROM point;
+------+------+------+------------+
| name | x    | y    | loc        |
+------+------+------+------------+
| A    |    1 |    1 | POINT(1 1) |
| B    |    5 |    6 | POINT(5 6) |
| C    |    2 |    8 | POINT(2 8) |
+------+------+------+------------+

Then

mysql> SET @p1 = 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))';

mysql> SELECT name FROM point where ST_CONTAINS(ST_GEOMFROMTEXT(@p1), loc);
+------+
| name |
+------+
| A    |
| C    |
+------+

 

polygon.PNG

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.