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
我正在抛出错误
您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在“p2x”和x&lt;附近使用正确的语法。 MAX(p1x,p2x))然后返回1;万一; IF(y> MIN(p1y,p2y)和y'在第19行
答案 0 :(得分:1)
您不能像这样使用min()
和max()
。使用LEAST()和GREATEST()获取2列的最低值和最高值。从
MIN()
的细分
MIN(p1y, p2y)
到
LEAST(p1y, p2x)
和
MAX(p1y, p2y)
到
GREATEST(p1y, p2y)