Anonymous avatar Anonymous committed 1c4a769

gis: Fixed #7579; no longer attempt to transform input geometries if `GeometryField` has its SRID set to -1.

Comments (0)

Files changed (3)


     def get_srid(self, geom):
-        Has logic for retrieving the default SRID taking into account 
-        the SRID of the field.
+        Returns the default SRID for the given geometry, taking into account
+        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 geom.srid
+            return gsrid
     ### Routines overloaded from Field ###
     def contribute_to_class(self, cls, name):
     def get_db_prep_save(self, value):
         "Prepares the value for saving in the database."
-        if isinstance(value, SpatialBackend.Geometry):
-            return SpatialBackend.Adaptor(value)
-        elif value is None:
+        if value is None:
             return None
-            raise TypeError('Geometry Proxy should only return Geometry objects or None.')
+            return SpatialBackend.Adaptor(self.get_geometry(value))
     def get_manipulator_field_objs(self):
         "Using the WKTField (oldforms) to be our manipulator."


     geom = models.GeometryField()
     objects = models.GeoManager()
     def __unicode__(self): return
+class MinusOneSRID(models.Model):
+    geom = models.PointField(srid=-1) # Minus one SRID.
+    objects = models.GeoManager()


 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.db.backend import SpatialBackend
 from django.contrib.gis.geos import *
         self.assertAlmostEqual(wgs_pnt.x, sa.point.x, 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))
+        self.assertEqual(-1, m1.geom.srid)
     # Oracle does not support NULL geometries in its spatial index for
     # some routines (e.g., SDO_GEOM.RELATE).
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.