本文整理匯總了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)))