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:好的,我要試試這個另一種方式:
>>> 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.01度,那麼最大距離比所述圓的直徑小100倍。 – jva 2009-10-27 15:02:56