MySQL:提供给函数 st_geometryfromtext 的无效 GIS 数据
MySQL: Invalid GIS data provided to function st_geometryfromtext
这是我的代码:
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);
每当我 运行 我得到一个 "MySQL: Invalid GIS data provided to function st_geometryfromtext" 错误。
这个returns同样的错误:
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);
有什么想法吗?
您需要将第一个点和最后一个点指定为相同。
试试这个。
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);
和
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);
这是我的查询
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'
如果你看到第一个多边形的点,都是一样的,它不是有效的多边形
mysql 5.7 抛出无效 GIS 错误,但 mysql 8 未抛出错误
删除第一个多边形解决了我的问题
这是我的代码:
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);
每当我 运行 我得到一个 "MySQL: Invalid GIS data provided to function st_geometryfromtext" 错误。
这个returns同样的错误:
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);
有什么想法吗?
您需要将第一个点和最后一个点指定为相同。
试试这个。
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);
和
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);
这是我的查询
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'
如果你看到第一个多边形的点,都是一样的,它不是有效的多边形
mysql 5.7 抛出无效 GIS 错误,但 mysql 8 未抛出错误
删除第一个多边形解决了我的问题