场景: 在往mysql表中字段是GEOMETRY类型存数据的时候遇到了了标题的问题
SQL如下:
SELECT ST_GeomFromGeoJSON('{"type":"MultiPolygon", "coordinates": [[[[113.404943, 23.172859], [113.40675, 23.172847], [113.406783, 23.171849], [113.404847, 23.171435], [113.404772, 23.172563]]]]}') AS POLYGON;
修改后:
SELECT ST_GeomFromGeoJSON('{"type":"MultiPolygon", "coordinates": [[[[113.404943, 23.172859], [113.40675, 23.172847], [113.406783, 23.171849], [113.404847, 23.171435], [113.404772, 23.172563],[113.404943, 23.172859]]]]}') AS POLYGON;
问题是什么呢,传入的坐标范围需要是一个封闭的, 即第一个坐标,一定要是最后一个坐标, 成为一个闭环
判断某个坐标是否在这个坐标内
示例:
SELECT st_intersects ( ST_GEOMFROMTEXT ( 'POINT(53.172859 113.404943)', 4326 ), p.vertices ) FROM POLYGON p