0

我正在寻找编写一个偏移函数来测试移动物体与空间中其他可移动和固定物体的接触。
为了对此进行测试,我需要查看它们的边界矩形是否相交。

我想测试两个可移动物体是否像这样接触:Table car
- id: integer (autoinc primary)
- rect: Linestring
- ...

表位置
- id: integer (autoinc primary)
- car_id: integer
- car_date: date
- car_pos: point
- ...

FUNCTION MyDB.OffsetRect(pLineString GEOMETRY, pOffset POINT) RETURNS geometry BEGIN
declare Result LineString;
declare P1 Point;
declare P2 point;
declare P3 point;
declare P4 point;
set Result = ENVELOPE(pLineString); /Make sure we are dealing with a rect/
set P1 = POINTN(Result,1);
set p1 = Point(X(p1)+X(pOffset),Y(p1)+Y(pOffset));
set P2 = POINTN(Result,2);
set p2 = Point(X(p2)+X(pOffset),Y(p2)+Y(pOffset));
set P3 = POINTN(Result,3);
set p3 = Point(X(p3)+X(pOffset),Y(p3)+Y(pOffset));
set P4 = POINTN(Result,4);
set p4 = Point(X(p4)+X(pOffset),Y(p4)+Y(pOffset));
set Result = LineString(p1,p2,p3,p4);
RETURN Result;
END

但是我被困在使用什么查询来查看两辆车是否及时相交。就像是。

SELECT location.id, location2.id FROM location
INNER JOIN car ON (car.id = location.car_id)
INNER JOIN location location2 ON (location.id <> location2.id)
INNER JOIN car car2 ON (car2.id = location2.car_id AND car.id <> car2.id)
WHERE location.car_date BETWEEN date_sub(now(),INTERVAL 1 DAY) AND date_add(now(),INTERVAL 1 DAY)
AND location2.car_date BETWEEN date_sub(now(),INTERVAL 1 DAY) and date_add(now(),INTERVAL 1 DAY)
AND      MBRIntersects(OffsetRect(car.rect,location.car_pos),OffsetRect(car2.rect,location2.car_pos));

但是这不起作用,有什么问题?

4

1 回答 1

1

相交..您的意思是在彼此相距 48 小时的时间内都停在同一个地方(您的时间范围是 48 小时)。

WHERE location .car_date BETWEEN date_sub(now(),INTERVAL 1 DAY) AND date_add(now(),INTERVAL 1 DAY)
AND location .car_date BETWEEN date_sub(now(),INTERVAL 1 DAY) 和 date_add(now(),INTERVAL 1天)

您连续两次使用相同的别名

于 2011-03-09T22:55:00.507 回答