Fixed #11827: Can now calculate extent in Oracle on tables with one point.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11577 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
dbd6f512ee
commit
62180a6b44
|
@ -32,11 +32,20 @@ elif SpatialBackend.oracle:
|
||||||
|
|
||||||
def convert_extent(clob):
|
def convert_extent(clob):
|
||||||
if clob:
|
if clob:
|
||||||
# Oracle returns a polygon for the extent, we construct
|
# Generally, Oracle returns a polygon for the extent -- however,
|
||||||
# the 4-tuple from the coordinates in the polygon.
|
# it can return a single point if there's only one Point in the
|
||||||
poly = SpatialBackend.Geometry(clob.read())
|
# table.
|
||||||
shell = poly.shell
|
ext_geom = SpatialBackend.Geometry(clob.read())
|
||||||
ll, ur = shell[0], shell[2]
|
gtype = str(ext_geom.geom_type)
|
||||||
|
if gtype == 'Polygon':
|
||||||
|
# Construct the 4-tuple from the coordinates in the polygon.
|
||||||
|
shell = ext_geom.shell
|
||||||
|
ll, ur = shell[0][:2], shell[2][:2]
|
||||||
|
elif gtype == 'Point':
|
||||||
|
ll = ext_geom.coords[:2]
|
||||||
|
ur = ll
|
||||||
|
else:
|
||||||
|
raise Exception('Unexpected geometry type returned for extent: %s' % gtype)
|
||||||
xmin, ymin = ll
|
xmin, ymin = ll
|
||||||
xmax, ymax = ur
|
xmax, ymax = ur
|
||||||
return (xmin, ymin, xmax, ymax)
|
return (xmin, ymin, xmax, ymax)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import os, unittest
|
import os, unittest
|
||||||
from django.contrib.gis.db.backend import SpatialBackend
|
from django.contrib.gis.db.backend import SpatialBackend
|
||||||
from django.contrib.gis.tests.utils import no_mysql, no_oracle, no_postgis
|
from django.contrib.gis.tests.utils import no_mysql, no_oracle, no_postgis, no_spatialite
|
||||||
from django.contrib.gis.shortcuts import render_to_kmz
|
from django.contrib.gis.shortcuts import render_to_kmz
|
||||||
from models import City
|
from models import City
|
||||||
|
|
||||||
|
@ -27,3 +27,9 @@ class GeoRegressionTests(unittest.TestCase):
|
||||||
}]
|
}]
|
||||||
kmz = render_to_kmz('gis/kml/placemarks.kml', {'places' : places})
|
kmz = render_to_kmz('gis/kml/placemarks.kml', {'places' : places})
|
||||||
|
|
||||||
|
@no_spatialite
|
||||||
|
def test03_extent(self):
|
||||||
|
"Testing `extent` on a table with a single point, see #11827."
|
||||||
|
pnt = City.objects.get(name='Pueblo').point
|
||||||
|
ref_ext = (pnt.x, pnt.y, pnt.x, pnt.y)
|
||||||
|
self.assertEqual(ref_ext, City.objects.filter(name='Pueblo').extent())
|
||||||
|
|
Loading…
Reference in New Issue