當前位置: 首頁>>代碼示例>>Python>>正文


Python measure.Distance方法代碼示例

本文整理匯總了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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:22,代碼來源:test_measure.py

示例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 
開發者ID:dulacp,項目名稱:django-accounting,代碼行數:16,代碼來源:distance_filters.py

示例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 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:6,代碼來源:conversion.py

示例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)') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:11,代碼來源:test_measure.py

示例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))) 
開發者ID:CroceRossaItaliana,項目名稱:jorvik,代碼行數:12,代碼來源:geo.py


注:本文中的django.contrib.gis.measure.Distance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。