GeoDjango,两点之间的距离

时间:2013-09-17 10:51:05

标签: python django geo geodjango

我有以下型号:

class City(models.Model):
    name = models.CharField(null=False, blank=False, max_length=200)
    coordinates = models.PointField(null=False, blank=False)
    objects = models.GeoManager()

我正在尝试使用以下内容找到上述两个城市之间的距离:

city1=City.objects.get(name='New York')
city2=City.objects.get(name='Boston')
city1.coordinates.distance(city2)

但是得到以下内容:

Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "/home/rok/apps/django-trunk/django/contrib/gis/geos/geometry.py", line 667, in distance
    raise TypeError('distance() works only on other GEOS Geometries.')
TypeError: distance() works only on other GEOS Geometries.

看结构和数据,似乎没问题:

>>> city1.coordinates.coords
(40.714623,-74.006605)
>>> city2.coordinates.coords
(42.360024, -71.060168)

我做错了什么?

0 个答案:

没有答案