2016-04-08 30 views
1

我是GeoIndex的新手。目前我有1600個地理標記圖像,我正在使用GeoIndex查找我的點(或我的當前位置)的某個半徑範圍內的所有圖像,所有圖像都正常工作,它返回與查詢匹配的點。但是,由於每個圖片都有唯一的網址,因此我需要能夠維護地理座標和網址之間的關聯。使用GeoIndex引用

例如:

def find_distance(index,myLocation,arraySearch,radius): 

    myUrlArray = [] 
    for coords in arraySearch: 
     index.add_point(GeoPoint(coords[0],coords[1])) 

    for point,distance in index.get_nearest_points(myLocation,radius,'km'): 
     print point 

myLocation傳遞在作爲放慢參數爲是稱爲arraySearch其含有以下列格式從JSON文件中讀取數據的數組:在運行時

arraySearch = [(latitudecoordinate,longitudecoordinate,url)] 

以上功能我得到以下輸出:

Point(54.573307, -5.998721) 
Point(54.600225, -5.920579) 
Point(54.598671, -5.918605) 
Point(54.598671, -5.918605) 
Point(54.598671, -5.918605) 
Point(54.598671, -5.918605) 
Point(54.598671, -5.918605) 
Point(54.598671, -5.918605) 
Point(54.601469, -5.921652) 
Point(54.601493, -5.920901) 

理想情況下,我想:

(Point(x,y),URL) 

在此先感謝!

編輯以糾正代碼的縮進錯誤

回答

1

然後你只需要包括在ref插槽在object structure可用的網址:

def find_distance(index,myLocation,arraySearch,radius): 

    myUrlArray = [] 
    for value in arraySearch: 
     index.add_point(GeoPoint(value[0],value[1], ref=value[2])) 

    for point,distance in index.get_nearest_points(myLocation,radius,'km'): 
     print point, point.ref 

由於Point對象不包括在此屬性他們的__repr__方法,您需要將其添加到您的print聲明如上。

+0

啊太棒了!非常感謝Héctor! – McCourt2364

+0

不客氣!它有用嗎?恐怕我沒有測試過。另外,我建議根據您的問題對Geoindex代碼進行更改:https://github.com/gusdan/geoindex/pull/2 –

+1

是的!工作很好!我同意你提出的改變! – McCourt2364