【问题标题】:Furthest distance between any two points with GeoDjangoGeoDjango 任意两点之间的最远距离
【发布时间】:2010-12-05 03:20:29
【问题描述】:

我有一个Point 对象的集合。我想找到任意两点之间的最远距离。想象一个包含所有这些点的圆圈。我想知道那个圆的直径。我如何在 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

??再说一遍,这些单位是什么?

【问题讨论】:

  • 从纯几何的角度来看,包含一组点的圆的直径只是最大距离的上限。如果您有 3 个点都位于仅相距 0.01 度的圆上,则最大距离比所述圆的直径小 100 倍以上。

标签: django gis geodjango


【解决方案1】:

好的,我想通了。

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

【讨论】:

    猜你喜欢
    • 2015-10-24
    • 1970-01-01
    • 1970-01-01
    • 2021-07-27
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多