mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
gis: Fixed #7579; no longer attempt to transform input geometries if GeometryField
has its SRID set to -1.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7840 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
597b07117a
commit
ccd5f52ee7
@ -120,13 +120,15 @@ class GeometryField(SpatialBackend.Field):
|
|||||||
|
|
||||||
def get_srid(self, geom):
|
def get_srid(self, geom):
|
||||||
"""
|
"""
|
||||||
Has logic for retrieving the default SRID taking into account
|
Returns the default SRID for the given geometry, taking into account
|
||||||
the SRID of the field.
|
the SRID set for the field. For example, if the input geometry
|
||||||
|
has no SRID, then that of the field will be returned.
|
||||||
"""
|
"""
|
||||||
if geom.srid is None or (geom.srid == -1 and self._srid != -1):
|
gsrid = geom.srid # SRID of given geometry.
|
||||||
|
if gsrid is None or self._srid == -1 or (gsrid == -1 and self._srid != -1):
|
||||||
return self._srid
|
return self._srid
|
||||||
else:
|
else:
|
||||||
return geom.srid
|
return gsrid
|
||||||
|
|
||||||
### Routines overloaded from Field ###
|
### Routines overloaded from Field ###
|
||||||
def contribute_to_class(self, cls, name):
|
def contribute_to_class(self, cls, name):
|
||||||
@ -171,12 +173,10 @@ class GeometryField(SpatialBackend.Field):
|
|||||||
|
|
||||||
def get_db_prep_save(self, value):
|
def get_db_prep_save(self, value):
|
||||||
"Prepares the value for saving in the database."
|
"Prepares the value for saving in the database."
|
||||||
if isinstance(value, SpatialBackend.Geometry):
|
if value is None:
|
||||||
return SpatialBackend.Adaptor(value)
|
|
||||||
elif value is None:
|
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
raise TypeError('Geometry Proxy should only return Geometry objects or None.')
|
return SpatialBackend.Adaptor(self.get_geometry(value))
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
"Using the WKTField (oldforms) to be our manipulator."
|
"Using the WKTField (oldforms) to be our manipulator."
|
||||||
|
@ -27,3 +27,7 @@ class Feature(models.Model):
|
|||||||
geom = models.GeometryField()
|
geom = models.GeometryField()
|
||||||
objects = models.GeoManager()
|
objects = models.GeoManager()
|
||||||
def __unicode__(self): return self.name
|
def __unicode__(self): return self.name
|
||||||
|
|
||||||
|
class MinusOneSRID(models.Model):
|
||||||
|
geom = models.PointField(srid=-1) # Minus one SRID.
|
||||||
|
objects = models.GeoManager()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import os, unittest
|
import os, unittest
|
||||||
from models import Country, City, State, Feature
|
from models import Country, City, State, Feature, MinusOneSRID
|
||||||
from django.contrib.gis import gdal
|
from django.contrib.gis import gdal
|
||||||
from django.contrib.gis.db.backend import SpatialBackend
|
from django.contrib.gis.db.backend import SpatialBackend
|
||||||
from django.contrib.gis.geos import *
|
from django.contrib.gis.geos import *
|
||||||
@ -302,6 +302,12 @@ class GeoModelTest(unittest.TestCase):
|
|||||||
self.assertAlmostEqual(wgs_pnt.x, sa.point.x, 6)
|
self.assertAlmostEqual(wgs_pnt.x, sa.point.x, 6)
|
||||||
self.assertAlmostEqual(wgs_pnt.y, sa.point.y, 6)
|
self.assertAlmostEqual(wgs_pnt.y, sa.point.y, 6)
|
||||||
|
|
||||||
|
# If the GeometryField SRID is -1, then we shouldn't perform any
|
||||||
|
# transformation if the SRID of the input geometry is different.
|
||||||
|
m1 = MinusOneSRID(geom=Point(17, 23, srid=4326))
|
||||||
|
m1.save()
|
||||||
|
self.assertEqual(-1, m1.geom.srid)
|
||||||
|
|
||||||
# Oracle does not support NULL geometries in its spatial index for
|
# Oracle does not support NULL geometries in its spatial index for
|
||||||
# some routines (e.g., SDO_GEOM.RELATE).
|
# some routines (e.g., SDO_GEOM.RELATE).
|
||||||
@no_oracle
|
@no_oracle
|
||||||
|
Loading…
x
Reference in New Issue
Block a user