MCPcopy
hub / github.com/django/django / test_distance_lookups

Method test_distance_lookups

tests/gis_tests/distapp/tests.py:131–155  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

129
130 @skipUnlessDBFeature("supports_distances_lookups")
131 def test_distance_lookups(self):
132 # Retrieving the cities within a 20km 'donut' w/a 7km radius 'hole'
133 # (thus, Houston and Southside place will be excluded as tested in
134 # the `test02_dwithin` above).
135 for model in [SouthTexasCity, SouthTexasCityFt]:
136 stx_pnt = self.stx_pnt.transform(
137 model._meta.get_field("point").srid, clone=True
138 )
139 qs = model.objects.filter(point__distance_gte=(stx_pnt, D(km=7))).filter(
140 point__distance_lte=(stx_pnt, D(km=20)),
141 )
142 cities = self.get_names(qs)
143 self.assertEqual(cities, ["Bellaire", "Pearland", "West University Place"])
144
145 # Doing a distance query using Polygons instead of a Point.
146 z = SouthTexasZipcode.objects.get(name="77005")
147 qs = SouthTexasZipcode.objects.exclude(name="77005").filter(
148 poly__distance_lte=(z.poly, D(m=275))
149 )
150 self.assertEqual(["77025", "77401"], self.get_names(qs))
151 # If we add a little more distance 77002 should be included.
152 qs = SouthTexasZipcode.objects.exclude(name="77005").filter(
153 poly__distance_lte=(z.poly, D(m=300))
154 )
155 self.assertEqual(["77002", "77025", "77401"], self.get_names(qs))
156
157 @skipUnlessDBFeature("supports_distances_lookups", "supports_distance_geodetic")
158 def test_geodetic_distance_lookups(self):

Callers

nothing calls this directly

Calls 7

get_namesMethod · 0.95
excludeMethod · 0.80
DClass · 0.50
transformMethod · 0.45
get_fieldMethod · 0.45
filterMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected