MySQL spatial geometry validate wkt

一笑奈何 提交于 2019-12-14 03:55:20

问题


In MySQL < 5.7 the spatial functions returned NULL when given invalid WKT, eg:

mysql> select astext(geomfromtext('polygon()'));

+-----------------------------------+
| astext(geomfromtext('polygon()')) |
+-----------------------------------+
| NULL                              |
+-----------------------------------+
1 row in set (0.00 sec)

But with newer MySQL the same input gives:

ERROR 3037 (22023): Invalid GIS data provided to function st_geometryfromtext.

Is there a way of checking whether the WKT is valid before sending it to the geometry functions? Alternatively is there a setting to force the geometry functions to produce NULL rather than error for invalid input?


回答1:


there are two functions provided by MySQL to test validity of geometries, but both take an already formed geometry as input.

ST_IsValid(ST_GeomFromText(?)); returns a boolean

ST_Validate(ST_GeomFromText(?)); returns the GEOM or null if invalid.

there is nothing I know of that parses WKT in MySQL, nor is there a setting that will switch it back to <5.7 behaviour.



来源:https://stackoverflow.com/questions/39285560/mysql-spatial-geometry-validate-wkt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!