-3
CREATE FUNCTION INPolygon(pnt varchar(50),poly varchar(500)) RETURNS int(1)
DETERMINISTIC
BEGIN
DECLARE x, y, p1x, p1y, p2x, p2y float(20, 16) DEFAULT 0;
DECLARE counter,i INT DEFAULT 1;
DECLARE touches float(20,16);
DECLARE intersect int DEFAULT 0;
set counter = substrCount(poly,"#") + 1;
set x = trim(strSplit(pnt,',',1));
set y = trim(strSplit(pnt,',',2));
while i <= counter DO
set p1x = strSplit(strSplit(poly,'#',i), ',', 1);
set p1y = strSplit(strSplit(poly,'#',i), ',', 2);
set p2x = strSplit(strSplit(poly, '#', i+1), ',', 1);
set p2y = strSplit(strSplit(poly, '#', i+1), ',', 2);
IF ((x = p1x AND y = p1y) OR (x = p2x AND y = p2y)) THEN
RETURN 1;
END IF;
IF (p1y = p2y and p1y = y and x > MIN(p1x, p2x) and x < MAX(p1x, p2x)) THEN
return 1;
END IF;
IF (y > MIN(p1y, p2y) AND y <= MAX(p1y,p2y) AND x <= MAX(p1x, p2x) AND p1y != p2y) THEN
set touches = (y - p1y) * (x - p1x)/(p2y - p1y) + x;
IF touches = x THEN
return 1;
END IF;
IF p1x = p2x OR x <= touches THEN
set intersect = intersect+1;
END IF;
END IF;
END WHILE;
RETURN intersect % 2;
END
我拋出一個錯誤說MySQL的函數創建語句拋出錯誤
您的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,以在'p2x'附近使用正確的語法並且x < MAX(p1x,p2x))然後返回1;萬一; IF(Y> MIN(P1Y,P2Y)和y」的線19
如何錯誤消息繼續?有趣的部分是失蹤。 –
在'p2x'附近使用並且x MIN(p1y,p2y)AND y'在第19行 –
DynamicDeveloper
也許發生這種情況的原因是您嘗試將一個字符串轉換爲float x ... – steven