Django

Code

Changeset 7840

Show
Ignore:
Timestamp:
07/05/08 11:59:51 (5 months ago)
Author:
jbronn
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/db/models/fields/__init__.py

    r7836 r7840  
    121121    def get_srid(self, geom): 
    122122        """ 
    123         Has logic for retrieving the default SRID taking into account  
    124         the SRID of the field. 
    125         """ 
    126         if geom.srid is None or (geom.srid == -1 and self._srid != -1): 
     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. 
     126        """ 
     127        gsrid = geom.srid # SRID of given geometry. 
     128        if gsrid is None or self._srid == -1 or (gsrid == -1 and self._srid != -1): 
    127129            return self._srid 
    128130        else: 
    129             return geom.srid 
     131            return gsrid 
    130132 
    131133    ### Routines overloaded from Field ### 
     
    172174    def get_db_prep_save(self, value): 
    173175        "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: 
    177177            return None 
    178178        else: 
    179             raise TypeError('Geometry Proxy should only return Geometry objects or None.'
     179            return SpatialBackend.Adaptor(self.get_geometry(value)
    180180 
    181181    def get_manipulator_field_objs(self): 
  • django/branches/gis/django/contrib/gis/tests/geoapp/models.py

    r6886 r7840  
    2828    objects = models.GeoManager() 
    2929    def __unicode__(self): return self.name 
     30 
     31class MinusOneSRID(models.Model): 
     32    geom = models.PointField(srid=-1) # Minus one SRID. 
     33    objects = models.GeoManager() 
  • django/branches/gis/django/contrib/gis/tests/geoapp/tests.py

    r7836 r7840  
    11import os, unittest 
    2 from models import Country, City, State, Feature 
     2from models import Country, City, State, Feature, MinusOneSRID 
    33from django.contrib.gis import gdal 
    44from django.contrib.gis.db.backend import SpatialBackend 
     
    302302        self.assertAlmostEqual(wgs_pnt.x, sa.point.x, 6) 
    303303        self.assertAlmostEqual(wgs_pnt.y, sa.point.y, 6) 
     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) 
    304310 
    305311    # Oracle does not support NULL geometries in its spatial index for