0

I have found the following mysql spatial functions which can check a given lattitude and longtitude is inside the polygon or not.

1 - MBR_Contains

2 - MBR_Within

Please guide me, which will give fast and accurate result to check a given point is inside or outside of the polygon in MySql server by the query itself.

Also Suggest me, If you found any better solution than this ( It should be checked by query in Mysql Server.)?

Regards, ArunRaj

ArunRaj
  • 1,780
  • 2
  • 26
  • 48
  • Hey ArunRaj, do you want to simply find locations within a specific distance, i.e. would a circle also work as a circumference or do you require it to be a ploygon? – Daan Feb 28 '14 at 12:13
  • @Daan : Hi Daan, Thanks for the reply. FYI, I am not calculating distance. For my Usecase, I need to **check a point(lat, lng)** whether it is inside or outside the **POLYGON**. – ArunRaj Feb 28 '14 at 12:35

1 Answers1

1

They're likely the same (in terms of speed), but you should run your own tests using both functions.

That said, Assuming you can use MySQL 5.6.1, you should refrain from the MBR functions and use the ST functions:

ST_Contains()
ST_Within()

The reason, MBR stands for minimum bounding rectangle, therefore a point can be within the minimum bounding rectangle, but not actually within the Polygon. The ST methods are exact to the shape and will give you a more precise answer.

Edit, Addressing which one should I use? I believe you can use either as you're testing a point within a polygon, but again test on a point you know to be in a polygon for safety.

Jon Bellamy
  • 3,333
  • 20
  • 23
  • Just for curious, Is it possible to construct the ST_Contains() method with HibernateSpatial API ? – ArunRaj Mar 01 '14 at 04:28
  • 1
    @user2959196 Honestly, I'm not entirely sure and I don't use NHibernate but I'd be surprised if current versions do not allow you to as they've supported Spatial Types from quite an early time. – Jon Bellamy Mar 01 '14 at 07:49