'Testing the `distance` GeoQuerySet method on geodetic coordnate systems.'

@no_spatialite
def test03b_distance_method(self):

    if oracle:
        tol = 2
    else:
        tol = 5
    ls = LineString(((150.902, (-34.4245)), (150.87, (-34.5789))))
    if (oracle or connection.ops.geography):
        distances = [1120954.92533513, 140575.720018241, 640396.662906304, 60580.9693849269, 972807.955955075, 568451.8357838, 40435.4335201384, 0, 68272.3896586844, 12375.0643697706, 0]
        qs = AustraliaCity.objects.distance(ls).order_by('name')
        for (city, distance) in zip(qs, distances):
            self.assertAlmostEqual(distance, city.distance.m, 0)
    else:
        self.assertRaises(ValueError, AustraliaCity.objects.distance, ls)
        self.assertRaises(ValueError, AustraliaCity.objects.distance, ls.wkt)
    if (connection.ops.postgis and (connection.ops.proj_version_tuple() >= (4, 7, 0))):
        spheroid_distances = [60504.0628957201, 77023.9489850262, 49154.8867574404, 90847.4358768573, 217402.811919332, 709599.234564757, 640011.483550888, 7772.00667991925, 1047861.78619339, 1165126.55236034]
        sphere_distances = [60580.9693849267, 77144.0435286473, 49199.4415344719, 90804.7533823494, 217713.384600405, 709134.127242793, 639828.157159169, 7786.82949717788, 1049204.06569028, 1162623.7238134]
    else:
        spheroid_distances = [60504.0628825298, 77023.948962654, 49154.8867507115, 90847.435881812, 217402.811862568, 709599.234619957, 640011.483583758, 7772.00667666425, 1047861.7859506, 1165126.55237647]
        sphere_distances = [60580.7612632291, 77143.7785056615, 49199.2725132184, 90804.4414289463, 217712.63666124, 709131.691061906, 639825.959074112, 7786.80274606706, 1049200.46122281, 1162619.7297006]
    hillsdale = AustraliaCity.objects.get(name='Hillsdale')
    qs = AustraliaCity.objects.exclude(id=hillsdale.id).distance(hillsdale.point, spheroid=True)
    for (i, c) in enumerate(qs):
        self.assertAlmostEqual(spheroid_distances[i], c.distance.m, tol)
    if postgis:
        qs = AustraliaCity.objects.exclude(id=hillsdale.id).distance(hillsdale.point)
        for (i, c) in enumerate(qs):
            self.assertAlmostEqual(sphere_distances[i], c.distance.m, tol)
