Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: Invalid GIS data provided to function st_geometryfromtext

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?

like image 676
neubert Avatar asked Dec 30 '15 06:12

neubert


1 Answers

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);
like image 56
codejunkie Avatar answered Nov 02 '22 17:11

codejunkie