Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit ccd5f52ee7fd5383752ab78ec469039c22100cbe 1 parent 597b071
Justin Bronn authored July 05, 2008
16  django/contrib/gis/db/models/fields/__init__.py
@@ -120,13 +120,15 @@ def get_geometry(self, value):
120 120
 
121 121
     def get_srid(self, geom):
122 122
         """
123  
-        Has logic for retrieving the default SRID taking into account 
124  
-        the SRID of the field.
  123
+        Returns the default SRID for the given geometry, taking into account
  124
+        the SRID set for the field.  For example, if the input geometry
  125
+        has no SRID, then that of the field will be returned.
125 126
         """
126  
-        if geom.srid is None or (geom.srid == -1 and self._srid != -1):
  127
+        gsrid = geom.srid # SRID of given geometry.
  128
+        if gsrid is None or self._srid == -1 or (gsrid == -1 and self._srid != -1):
127 129
             return self._srid
128 130
         else:
129  
-            return geom.srid
  131
+            return gsrid
130 132
 
131 133
     ### Routines overloaded from Field ###
132 134
     def contribute_to_class(self, cls, name):
@@ -171,12 +173,10 @@ def get_db_prep_lookup(self, lookup_type, value):
171 173
 
172 174
     def get_db_prep_save(self, value):
173 175
         "Prepares the value for saving in the database."
174  
-        if isinstance(value, SpatialBackend.Geometry):
175  
-            return SpatialBackend.Adaptor(value)
176  
-        elif value is None:
  176
+        if value is None:
177 177
             return None
178 178
         else:
179  
-            raise TypeError('Geometry Proxy should only return Geometry objects or None.')
  179
+            return SpatialBackend.Adaptor(self.get_geometry(value))
180 180
 
181 181
     def get_manipulator_field_objs(self):
182 182
         "Using the WKTField (oldforms) to be our manipulator."
4  django/contrib/gis/tests/geoapp/models.py
@@ -27,3 +27,7 @@ class Feature(models.Model):
27 27
     geom = models.GeometryField()
28 28
     objects = models.GeoManager()
29 29
     def __unicode__(self): return self.name
  30
+
  31
+class MinusOneSRID(models.Model):
  32
+    geom = models.PointField(srid=-1) # Minus one SRID.
  33
+    objects = models.GeoManager()
8  django/contrib/gis/tests/geoapp/tests.py
... ...
@@ -1,5 +1,5 @@
1 1
 import os, unittest
2  
-from models import Country, City, State, Feature
  2
+from models import Country, City, State, Feature, MinusOneSRID
3 3
 from django.contrib.gis import gdal
4 4
 from django.contrib.gis.db.backend import SpatialBackend
5 5
 from django.contrib.gis.geos import *
@@ -302,6 +302,12 @@ def test11_lookup_insert_transform(self):
302 302
         self.assertAlmostEqual(wgs_pnt.x, sa.point.x, 6)
303 303
         self.assertAlmostEqual(wgs_pnt.y, sa.point.y, 6)
304 304
 
  305
+        # If the GeometryField SRID is -1, then we shouldn't perform any
  306
+        # transformation if the SRID of the input geometry is different.
  307
+        m1 = MinusOneSRID(geom=Point(17, 23, srid=4326))
  308
+        m1.save()
  309
+        self.assertEqual(-1, m1.geom.srid)
  310
+
305 311
     # Oracle does not support NULL geometries in its spatial index for
306 312
     # some routines (e.g., SDO_GEOM.RELATE).
307 313
     @no_oracle

0 notes on commit ccd5f52

Please sign in to comment.
Something went wrong with that request. Please try again.