Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Enabled area calculations for geography columns.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14189 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 120aae2209a50641f51e1f6bc4fe383fb42757fb 1 parent c7384af
Justin Bronn jbronn authored
5 django/contrib/gis/db/models/query.py
View
@@ -48,7 +48,10 @@ def area(self, tolerance=0.05, **kwargs):
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:
2  django/contrib/gis/tests/geogapp/models.py
View
@@ -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 django/contrib/gis/tests/geogapp/tests.py
View
@@ -76,3 +76,12 @@ def test05_geography_layermapping(self):
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)
1  docs/ref/contrib/gis/model-api.txt
View
@@ -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`
Please sign in to comment.
Something went wrong with that request. Please try again.