本文整理汇总了Python中django.contrib.gis.measure.Distance方法的典型用法代码示例。如果您正苦于以下问题:Python measure.Distance方法的具体用法?Python measure.Distance怎么用?Python measure.Distance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.gis.measure
的用法示例。
在下文中一共展示了measure.Distance方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testInit
# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import Distance [as 别名]
def testInit(self):
"Testing initialization from valid units"
d = Distance(m=100)
self.assertEqual(d.m, 100)
d1, d2, d3 = D(m=100), D(meter=100), D(metre=100)
for d in (d1, d2, d3):
self.assertEqual(d.m, 100)
d = D(nm=100)
self.assertEqual(d.m, 185200)
y1, y2, y3 = D(yd=100), D(yard=100), D(Yard=100)
for d in (y1, y2, y3):
self.assertEqual(d.yd, 100)
mm1, mm2 = D(millimeter=1000), D(MiLLiMeTeR=1000)
for d in (mm1, mm2):
self.assertEqual(d.m, 1.0)
self.assertEqual(d.mm, 1000.0)
示例2: distance
# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import Distance [as 别名]
def distance(dist):
if isinstance(dist, Distance):
d = dist.m
unit = "m"
if d > 1000:
d = dist.km
unit = "km"
ctx = {
'distance': float('%.2g' % d),
'unit': unit,
}
return u"%(distance)s %(unit)s" % ctx
示例3: from_db_value
# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import Distance [as 别名]
def from_db_value(self, value, expression, connection, context):
if value is not None:
value = Distance(**{self.distance_att: value})
return value
示例4: testUnitsStr
# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import Distance [as 别名]
def testUnitsStr(self):
"Testing conversion to strings"
d1 = D(m=100)
d2 = D(km=3.5)
self.assertEqual(str(d1), '100.0 m')
self.assertEqual(str(d2), '3.5 km')
self.assertEqual(repr(d1), 'Distance(m=100.0)')
self.assertEqual(repr(d2), 'Distance(km=3.5)')
示例5: vicini
# 需要导入模块: from django.contrib.gis import measure [as 别名]
# 或者: from django.contrib.gis.measure import Distance [as 别名]
def vicini(self, queryset, km):
"""
Filtra una QuerySet per tutti gli oggetti simili vicini, nei pressi di x KM.
:param km: Raggio di ricerca in kilometri.
:return: Una ricerca filtrata.
"""
if not self.locazione:
return queryset.none()
return queryset.filter(locazione__geo__distance_lte=(self.locazione.geo, Distance(km=km)))