MySQL: A spatial query to determine if a latitude / longitude point is within a given boundary

I am working on a Google map search feature. The vision of this is to determine if a point (geolocation) is inside the polygon or not, as shown in the figure below?

enter image description here

I am using mysql 5.6.20 with a spatial extension, I know that it has useful built-in geometry functions, so I will be allowed to directly request geocoded locations from the database.

My goal was to become familiar with geospatial functions, so I wrote experimental sql.

for a given geolocation of the point: POINT (100.52438735961914 13.748889613522605)

, , : (100.49503326416016 13.766897133254545,100.55940628051758 13.746555203977,100.56266784667969 13.72170897580617,100.48885345458984 13.739051587150175)

sql:

SELECT ST_Within(
ST_GEOMFROMTEXT('POINT(100.52438735961914 13.748889613522605)'),
ST_GEOMFROMTEXT('POLYGON(100.49503326416016 13.766897133254545,
100.55940628051758 13.746555203977,100.56266784667969 13.72170897580617,
100.48885345458984 13.739051587150175)'))
As geoFenceStatus

, , :

geoFenceStatus
===============
null

, "null". , "1" ,

, sql.

+4
1

, , . :

  • - LINESTRING, , .. .

  • , .. POLYGON((x1 y1, x2 y2.......xn yn, x1 y1)). , .

. Wikipedia WKT.

, :

SELECT ST_Within(ST_GEOMFROMTEXT('POINT(100.52438735961914 13.748889613522605)'),
             ST_GEOMFROMTEXT('POLYGON((100.49503326416016 13.766897133254545, 100.55940628051758 13.746555203977,100.56266784667969 13.72170897580617, 100.48885345458984 13.739051587150175,
             100.49503326416016 13.766897133254545))'))
As geoFenceStatus

.

+6

All Articles