Python django.contrib.gis.measure.Distance() Examples
The following are 8
code examples of django.contrib.gis.measure.Distance().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.contrib.gis.measure
, or try the search function
.
Example #1
Source File: test_measure.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #2
Source File: test_measure.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #3
Source File: distance_filters.py From django-accounting with MIT License | 5 votes |
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
Example #4
Source File: conversion.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def from_db_value(self, value, expression, connection, context): if value is not None: value = Distance(**{self.distance_att: value}) return value
Example #5
Source File: conversion.py From openhgsenti with Apache License 2.0 | 5 votes |
def from_db_value(self, value, expression, connection, context): if value is not None: value = Distance(**{self.distance_att: value}) return value
Example #6
Source File: test_measure.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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)')
Example #7
Source File: test_measure.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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)')
Example #8
Source File: geo.py From jorvik with GNU General Public License v3.0 | 5 votes |
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)))