2009-12-28 54 views

回答

3

據我所知,緩衝功能not yet implemented在MySQL:

這些功能在MySQL不 實施。他們可能會在未來的版本中出現 。

* Buffer(g,d) 

    Returns a geometry that represents all points whose distance from the geometry value g is less than or equal to a distance of d. 

如果我理解你的問題吧,你甚至可能不會需要一個空間函數來執行此查詢,您可以使用「常規」 SQL查詢和Euclidean distance

select * 
from gistable g 
where SQRT(POW(circleCenterPT.x - point.x,2) + POW(circleCenterPT.y - point.y,2)) < radius 

希望這有助於。


編輯: 性能肯定會與此查詢的問題。

至於MySQL中的空間函數,似乎最新的快照包含了諸如緩衝區或距離等新功能。 你可能想試一試:

+1

事實上,將公式放入查詢中可能會起作用...但也會非常慢(表掃​​描)。添加邊界矩形將有所幫助,但我寧願數據庫爲我處理這些細節。 :)儘管如此,我認爲MySQL還沒有幫助的功能。 – jsight 2010-01-17 03:32:54

1

即使你使用了PostGIS,你並不需要使用ST_Buffer功能,但執行相當於此(僞代碼)的操作的ST_Expand

-- expand bounding box with 'units' in each direction 
envelope.xmin -= units; 
envelope.ymin -= units; 
envelope.xmax += units; 
envelope.ymax += units; 
-- also Z coordinate can be expanded this way 

在PostGIS的語法,SQL查詢通常看起來如下:

SELECT AsText(geom) FROM mypoints 
WHERE 
    -- operator && triggers use of spatial index, for better performance 
    geom && ST_Expand(ST_GeometryFromText('POINT(10 20)', 1234), 5) 
AND 
    -- and here is the actual filter condition 
    Distance(geom, ST_GeometryFromText('POINT(10 20)', 1234)) < 5 

查找PostGIS的用戶郵件列表Buffer vs Expand解釋。

因此,理想情況下是複製類似MySQL的行爲。我根本不是MySQL專家,但我認爲即使沒有ST_Expand函數也是可行的。

這裏是如何模仿ST_Expand功能:

CONCAT('POLYGON((', 
    X(GeomFromText('POINT(10 20)')) - 5, ' ', Y(GeomFromText('POINT(10 20)')) - 5, ',', 
    X(GeomFromText('POINT(10 20)')) + 5, ' ', Y(GeomFromText('POINT(10 20)')) - 5, ',', 
    X(GeomFromText('POINT(10 20)')) + 5, ' ', Y(GeomFromText('POINT(10 20)')) + 5, ',', 
    X(GeomFromText('POINT(10 20)')) - 5, ' ', Y(GeomFromText('POINT(10 20)')) + 5, ',', 
    X(GeomFromText('POINT(10 20)')) - 5, ' ', Y(GeomFromText('POINT(10 20)')) - 5, '))' 
); 

然後這個結果與查詢這樣的組合:

SELECT AsText(geom) FROM mypoints 
WHERE 
    -- AFAIK, this should trigger use of spatial index in MySQL 
    -- replace XXX with the of expanded point as result of CONCAT above 
    Intersects(geom, GeomFromText(XXX)) 
AND 
    -- test condition 
    Distance(geom, GeomFromText('POINT(10 20)')) < 5 

如果舊的MySQL版本,其中遠程功能無法使用工作,那麼你可以使用amercader的基於SQRT的計算。

我希望它給你一些想法。

0

從MySQL 5.7.6開始。
ST_Distance_sphere(g1, g2[, radius])

返回球體上的兩個點和/或multipoints之間NULL的mimimum球面距離,以米爲單位,或任何幾何參數爲空或空

計算使用球形地球和配置半徑。可選的半徑參數應該以米爲單位給出。如果省略,則默認半徑爲6,370,986米。如果半徑參數存在但不是正數,則會發生ER_WRONG_ARGUMENTS錯誤