问题
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