Enabled area calculations for geography columns.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14189 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
c7384af061
commit
120aae2209
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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`
|
||||
|
|
Loading…
Reference in New Issue