简体   繁体   中英

MySQL POLYGON query no results

Database table with a POINT datatype. I can't get any results from a MySQL POLYGON query. Any idea what I am doing wrong? The polygon is closed.

id  location
1   POINT(-37.816652 144.964595)    
2   POINT(-37.788132 144.931183)
3   POINT(-37.811291 144.985916)
4   POINT(-37.8389571 144.9656531000001)
5   POINT(-37.851038 144.993205)
6   POINT(-37.8029679 144.9501126)

/* 
 north = -37.711586434367305
 east = 145.45740074179685
 south = -37.92854972934211
 west = 144.6142000582031
*/

SELECT * FROM `properties` WHERE Contains (GeomFromText('POLYGON((145.45740074179685, -37.711586434367305, 144.6142000582031, -37.711586434367305, 144.6142000582031, -37.92854972934211, 145.45740074179685, -37.92854972934211, 145.45740074179685, -37.711586434367305))'), location)

SELECT * FROM `properties` WHERE Contains (PolygonFromText('POLYGON((145.45740074179685, -37.711586434367305, 144.6142000582031, -37.711586434367305, 144.6142000582031, -37.92854972934211, 145.45740074179685, -37.92854972934211, 145.45740074179685, -37.711586434367305))'), location)

You seem to have got your cordinates in the wrong order.

GeomFromText('POLYGON((-37.711586434367305,145.45740074179685,
  -37.711586434367305, 144.6142000582031,  ....)))

Also Contains has been deprecated. better to use MBRContains.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM