Here’s my code:
SET @poly = 'Polygon((-98.07697478272888 30.123832577126326, -98.07697478272888 30.535734310413392, -97.48302581787107 30.535734310413392, -97.48302581787107 30.123832577126326))'; SELECT name FROM county_shapes WHERE MBRContains(ST_GeomFromText(@poly), SHAPE);
Whenever I run that I get a “MySQL: Invalid GIS data provided to function st_geometryfromtext” error.
This returns the same error:
SELECT name FROM county_shapes WHERE MBRContains(ST_GeomFromText('Polygon((-98.07697478272888 30.123832577126326, -98.07697478272888 30.535734310413392, -97.48302581787107 30.535734310413392, -97.48302581787107 30.123832577126326))'), SHAPE);
Any ideas?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You need to specify the first and last point as same.
Try this.
SET @poly = 'Polygon((-98.07697478272888 30.123832577126326, -98.07697478272888 30.535734310413392, -97.48302581787107 30.535734310413392, -97.48302581787107 30.123832577126326, -98.07697478272888 30.123832577126326,))'; SELECT name FROM county_shapes WHERE MBRContains(ST_GeomFromText(@poly), SHAPE);
AND
SELECT name FROM county_shapes WHERE MBRContains(ST_GeomFromText('Polygon(( -98.07697478272888 30.123832577126326, -98.07697478272888 30.535734310413392, -97.48302581787107 30.535734310413392, -97.48302581787107 30.123832577126326, -98.07697478272888 30.123832577126326))'), SHAPE);
Method 2
This was my query
SELECT * FROM my_table WHERE ST_Within(point(`lon`, `lat`),ST_GeomFromText('MultiPolygon(((-58.5832214 -34.5365410,-58.5832214 -34.5365410,-58.5832214 -34.5365410,-58.5832214 -34.5365410,-58.5832214 -34.5365410)),((-58.5887184 -34.6642799,-58.2893410 -34.6642799,-58.2893410 -34.5280609,-58.5887184 -34.5280609,-58.5887184 -34.6642799,-58.5887184 -34.6642799),(-58.4351311 -34.5975914,-58.4347000 -34.5976410,-58.4346085 -34.5977516,-58.4348602 -34.5979195,-58.4351311 -34.5975914,-58.4351311 -34.5975914)))'))>'0'
If you see the first polygon’s points, all are same, its not a valid polygon
mysql 5.7 was throwing invalid GIS error, but mysql 8 was not throwing error
removing the first polygon solved my problem
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0