Commit 4ed10675 authored by Justin Bronn's avatar Justin Bronn
Browse files

[1.2.X] Enabled area calculations for geography columns.

Backport of r14189 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14190 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 3c8bc8c6
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -48,7 +48,10 @@ class GeoQuerySet(QuerySet):
            s['procedure_args']['tolerance'] = tolerance
            s['select_field'] = AreaField('sq_m') # Oracle returns area in units of meters.
        elif backend.postgis or backend.spatialite:
            if not geo_field.geodetic(connection):
            if backend.geography:
                # Geography fields support area calculation, returns square meters.
                s['select_field'] = AreaField('sq_m')
            elif not geo_field.geodetic(connection):
                # Getting the area units of the geographic field.
                s['select_field'] = AreaField(Area.unit_attname(geo_field.units_name(connection)))
            else:
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ class Zipcode(models.Model):
    code = models.CharField(max_length=10)
    poly = models.PolygonField(geography=True)
    objects = models.GeoManager()
    def __unicode__(self): return self.name
    def __unicode__(self): return self.code

class County(models.Model):
    name = models.CharField(max_length=25)
+9 −0
Original line number Diff line number Diff line
@@ -76,3 +76,12 @@ class GeographyTest(TestCase):
            self.assertEqual(num_poly, len(c.mpoly))
            self.assertEqual(name, c.name)
            self.assertEqual(state, c.state)

    def test06_geography_area(self):
        "Testing that Area calculations work on geography columns."
        from django.contrib.gis.measure import A
        # SELECT ST_Area(poly) FROM geogapp_zipcode WHERE code='77002';
        ref_area = 5439084.70637573
        tol = 5
        z = Zipcode.objects.area().get(code='77002')
        self.assertAlmostEqual(z.area.sq_m, ref_area, tol)
+0 −1
Original line number Diff line number Diff line
@@ -216,7 +216,6 @@ only the following additional :ref:`spatial lookups <spatial-lookups>` are
available for geography columns:

* :lookup:`bboverlaps`
* :lookup:`exact`, and :lookup:`same_as`
* :lookup:`coveredby`
* :lookup:`covers`
* :lookup:`intersects`