2009-10-08 4 views
0

나는 Point 개체가 있습니다. 나는 두 점 사이의 가장 먼 거리를 찾고 싶다. 이 모든 점들을 감싸는 원을 상상해보십시오. 그 원의 지름을 알고 싶습니다. GeoDjango에서 어떻게해야합니까?GeoDjango가있는 두 점 사이의 가장 먼 거리

편집 : 이것은 내가 지금까지 무엇을 가지고 :

>>> r=Route.objects.get(pk=1) 
>>> a=Airport.objects.filter(routebase__route=r) 

>>> # this route represents a few hundred miles flight into mexico and back 
>>> a 
[<Airport: MMDO>, <Airport: KELP>, <Airport: KELP>, <Airport: MMCU>] 

>>> # a multipoint object with all the airports 
>>> mpoint = a.collect() 

>>> # a polygon that represents a ring around the multipoint 
>>> p = mpoint.envelope 

>>> #now I just need to get the diameter of this envelope 
>>> p.length 
19.065994262694986 

???

그 단위는 무엇입니까? 이게 내가 따라하는 가치 일까?

EDIT2 : OK I이 다른 방법으로 시도거야 :

>>> r=Route.objects.get(pk=1) 
>>> a=Airport.objects.filter(routebase__route=r) 

>>> # this route represents a few hundred miles flight into mexico 
>>> a 
[<Airport: MMDO>, <Airport: KELP>, <Airport: MMCU>] 

>>> # a multipoint object with all the airports 
>>> mpoint = a.collect() 

>>> # get the center point of the route polygon and get the 
>>> # distance between each point and the centroid 
>>> # the largest should be the diameter of the ring, right? 
>>> cen = mpoint.centroid 

>>> dist = [] 
>>> for p in mp: 
     dist.append(LineString(p, cen).length) 

>>> dis 
[0.54555421739245946, 
0.61638306853425906, 
0.53442640535933494, 
0.54555421739245946] 

>>> max(dist) 
0.61638306853425906 

을 ?? 다시,이 단위들은 무엇입니까?

+0

점 집합을 둘러싼 원의 직경이 순수한 기하학적 관점에서 볼 때 최대 거리의 상한선에 불과합니다. 모든 점이 0.01도 떨어져 서클에 놓여있는 3 점을 가지고 있다면 최대 거리는 상기 원의 지름보다 100 배 이상 작습니다. – jva

답변

2

좋아요, 알아 냈습니다.

def overall_distance(route): 
    a = Airport.objects.filter(routebase__route=route).distinct() 
    mp = a.collect() 
    ct = mp.envelope.centroid 
    na = a.distance(ct) 

    dist = [] 
    for p in na: 
     dist.append(p.distance) 

    diameter = max(dist) * 2 

    return diameter.nm 
관련 문제