0

I am trying to query all from a table of points, all of the points that are inside a certain polygon. I have tried to use st_contains() and for some reason it just won't work. To made it simple, I have made a table with the points (1,1),(0,0),(100,100) I have used:

GeomFromText('Point(0 0)')

This is my query:

SELECT id, astext(point) FROM points WHERE st_within(point,GeomFromText('Polygon(10 10, 10 -10, -10 -10, -10 10, 10 10)'))

I have also found this question, which made me feel confident that there is something very big that I'm missing...

Please, tell me what I'm doing wrong... Thanks :)

Community
  • 1
  • 1
Mr. Nun.
  • 775
  • 11
  • 29
  • Already asked and answered on [gis](http://gis.stackexchange.com/questions/77269/does-mysql-has-function-which-will-return-the-points-inside-polygon). – hd1 Jul 18 '14 at 20:42
  • Hi @hd1, thank you for your answer.I have seen this questions, but there is still something wrong with my code and I can't figure out what... – Mr. Nun. Jul 19 '14 at 22:35

2 Answers2

0

There are two methods to determine if a point is within a polygon (winding number or the even odd rule).

  1. https://www.youtube.com/watch?v=AHs2Ugxo7-8
  2. http://en.wikipedia.org/wiki/Even%E2%80%93odd_rule

This depends how you wish to treat a polygon.

VMai
  • 10,156
  • 9
  • 25
  • 34
Ed Heal
  • 59,252
  • 17
  • 87
  • 127
0

Apparently, it is very important that the "Polygon Creation String" will use at least 2 sets of parentheses, even if it's a 1-line polygon. for example: GOOD Polygon Creation:

GeomFromText('Polygon((10 10,10 -10,-10 -10,10 10))')

BAD Polygon Creation:

GeomFromText('Polygon(10 10,10 -10,-10 -10,10 10)')
Mr. Nun.
  • 775
  • 11
  • 29