Ticket #18039: 18039-1.diff

File 18039-1.diff, 5.0 KB (added by Claude Paroz, 13 years ago)

Transform with no SRID raises Exception

  • django/contrib/gis/geos/geometry.py

    diff --git a/django/contrib/gis/geos/geometry.py b/django/contrib/gis/geos/geometry.py
    index c56eeb3..f411d5a 100644
    a b  
    33 inherit from this object.
    44"""
    55# Python, ctypes and types dependencies.
    6 import warnings
    76from ctypes import addressof, byref, c_double
    87
    98# super-class for mutable list behavior
    class GEOSGeometry(GEOSBase, ListMixin):  
    507506                return
    508507
    509508        if (srid is None) or (srid < 0):
    510             warnings.warn("Calling transform() with no SRID set does no transformation!",
    511                           stacklevel=2)
    512             warnings.warn("Calling transform() with no SRID will raise GEOSException in v1.5",
    513                           FutureWarning, stacklevel=2)
    514             return
     509            raise GEOSException("Calling transform() with no SRID set is not supported")
    515510
    516511        if not gdal.HAS_GDAL:
    517512            raise GEOSException("GDAL library is not available to transform() geometry.")
  • django/contrib/gis/geos/tests/test_geos.py

    diff --git a/django/contrib/gis/geos/tests/test_geos.py b/django/contrib/gis/geos/tests/test_geos.py
    index a8372b4..a6b50df 100644
    a b class GEOSTest(unittest.TestCase, TestDataMixin):  
    891891            gdal.HAS_GDAL = old_has_gdal
    892892
    893893    def test23_transform_nosrid(self):
    894         """ Testing `transform` method (no SRID) """
    895         # Raise a warning if SRID <0/None.
    896         import warnings
    897         print "\nBEGIN - expecting Warnings; safe to ignore.\n"
     894        """ Testing `transform` method (no SRID or negative SRID) """
    898895
    899         # Test for do-nothing behavior.
    900         try:
    901             # Keeping line-noise down by only printing the relevant
    902             # warnings once.
    903             warnings.simplefilter('once', UserWarning)
    904             warnings.simplefilter('once', FutureWarning)
    905 
    906             g = GEOSGeometry('POINT (-104.609 38.255)', srid=None)
    907             g.transform(2774)
    908             self.assertEqual(g.tuple, (-104.609, 38.255))
    909             self.assertEqual(g.srid, None)
    910 
    911             g = GEOSGeometry('POINT (-104.609 38.255)', srid=None)
    912             g1 = g.transform(2774, clone=True)
    913             self.assertTrue(g1 is None)
    914 
    915             g = GEOSGeometry('POINT (-104.609 38.255)', srid=-1)
    916             g.transform(2774)
    917             self.assertEqual(g.tuple, (-104.609, 38.255))
    918             self.assertEqual(g.srid, -1)
    919 
    920             g = GEOSGeometry('POINT (-104.609 38.255)', srid=-1)
    921             g1 = g.transform(2774, clone=True)
    922             self.assertTrue(g1 is None)
    923 
    924         finally:
    925             warnings.simplefilter('default', UserWarning)
    926             warnings.simplefilter('default', FutureWarning)
     896        g = GEOSGeometry('POINT (-104.609 38.255)', srid=None)
     897        self.assertRaises(GEOSException, g.transform, 2774)
    927898
    928         print "\nEND - expecting Warnings; safe to ignore.\n"
     899        g = GEOSGeometry('POINT (-104.609 38.255)', srid=None)
     900        self.assertRaises(GEOSException, g.transform, 2774, clone=True)
    929901
     902        g = GEOSGeometry('POINT (-104.609 38.255)', srid=-1)
     903        self.assertRaises(GEOSException, g.transform, 2774)
    930904
    931         # test warning is raised
    932         try:
    933             warnings.simplefilter('error', FutureWarning)
    934             warnings.simplefilter('ignore', UserWarning)
    935 
    936             g = GEOSGeometry('POINT (-104.609 38.255)', srid=None)
    937             self.assertRaises(FutureWarning, g.transform, 2774)
    938 
    939             g = GEOSGeometry('POINT (-104.609 38.255)', srid=None)
    940             self.assertRaises(FutureWarning, g.transform, 2774, clone=True)
    941 
    942             g = GEOSGeometry('POINT (-104.609 38.255)', srid=-1)
    943             self.assertRaises(FutureWarning, g.transform, 2774)
    944 
    945             g = GEOSGeometry('POINT (-104.609 38.255)', srid=-1)
    946             self.assertRaises(FutureWarning, g.transform, 2774, clone=True)
    947         finally:
    948             warnings.simplefilter('default', FutureWarning)
    949             warnings.simplefilter('default', UserWarning)
    950 
     905        g = GEOSGeometry('POINT (-104.609 38.255)', srid=-1)
     906        self.assertRaises(GEOSException, g.transform, 2774, clone=True)
    951907
    952908    def test23_transform_nogdal(self):
    953909        """ Testing `transform` method (GDAL not available) """
  • docs/ref/contrib/gis/geos.txt

    diff --git a/docs/ref/contrib/gis/geos.txt b/docs/ref/contrib/gis/geos.txt
    index a82ac87..9fceda3 100644
    a b is returned instead.  
    542542   Prior to 1.3, this method would silently no-op if GDAL was not available.
    543543   Now, a :class:`~django.contrib.gis.geos.GEOSException` is raised as
    544544   application code relying on this behavior is in error. In addition,
    545    use of this method when the SRID is ``None`` or less than 0 now generates
    546    a warning because a :class:`~django.contrib.gis.geos.GEOSException` will
    547    be raised instead in version 1.5.
     545   use of this method when the SRID is ``None`` or less than 0 now also generates
     546   a :class:`~django.contrib.gis.geos.GEOSException`.
    548547
    549548
    550549``Point``
Back to Top