我正在尋找一個偏移函數來測試移動的對象觸及其他可移動和固定的對象在空間中。
爲了測試這個,我需要看看他們的邊界矩形是否相交。MySQL的幾何偏移測試
我想測試兩個可移動的物體接觸,像這樣: 表汽車
- ID:整數(AUTOINC主)
- 矩形:LINESTRING
- ...
表位置
- ID:整數(AUTOINC主)
- car_id:整數
- car_date:日期
- car_pos:點
- ...
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));
但是這不起作用,怎麼了?
48小時使用相同的別名兩次。 – Johan 2011-03-09 23:02:30
除此之外它沒關係?酥油我接近了! – Johan 2011-03-09 23:02:55
好的,修正了在代碼中,可悲的是它仍然不起作用: - < – Johan 2011-03-09 23:24:09