Ticket #13788: 13788_geos_transform.2.diff
File 13788_geos_transform.2.diff, 10.0 KB (added by , 14 years ago) |
---|
-
django/contrib/gis/geos/geometry.py
diff -r 35aeedea954d django/contrib/gis/geos/geometry.py
a b 4 4 """ 5 5 # Python, ctypes and types dependencies. 6 6 import re 7 import warnings 7 8 from ctypes import addressof, byref, c_double, c_size_t 8 9 9 10 # super-class for mutable list behavior … … 498 499 instead. 499 500 """ 500 501 srid = self.srid 501 if gdal.HAS_GDAL and srid: 502 # Creating an OGR Geometry, which is then transformed. 503 g = gdal.OGRGeometry(self.wkb, srid) 504 g.transform(ct) 505 # Getting a new GEOS pointer 506 ptr = wkb_r().read(g.wkb) 502 503 if ct == srid: 504 # short-circuit where source & dest SRIDs match 507 505 if clone: 508 # User wants a cloned transformed geometry returned. 509 return GEOSGeometry(ptr, srid=g.srid) 510 if ptr: 511 # Reassigning pointer, and performing post-initialization setup 512 # again due to the reassignment. 513 capi.destroy_geom(self.ptr) 514 self.ptr = ptr 515 self._post_init(g.srid) 506 return self.clone() 516 507 else: 517 raise GEOSException('Transformed WKB was invalid.') 508 return 509 510 if (srid is None) or (srid < 0): 511 warnings.warn("Calling transform() with no SRID set does no transformation!", 512 stacklevel=2) 513 warnings.warn("Calling transform() with no SRID will raise GEOSException in v1.5", 514 FutureWarning, stacklevel=2) 515 return 516 517 if not gdal.HAS_GDAL: 518 raise GEOSException("GDAL library is not available to transform() geometry.") 519 520 # Creating an OGR Geometry, which is then transformed. 521 g = gdal.OGRGeometry(self.wkb, srid) 522 g.transform(ct) 523 # Getting a new GEOS pointer 524 ptr = wkb_r().read(g.wkb) 525 if clone: 526 # User wants a cloned transformed geometry returned. 527 return GEOSGeometry(ptr, srid=g.srid) 528 if ptr: 529 # Reassigning pointer, and performing post-initialization setup 530 # again due to the reassignment. 531 capi.destroy_geom(self.ptr) 532 self.ptr = ptr 533 self._post_init(g.srid) 534 else: 535 raise GEOSException('Transformed WKB was invalid.') 518 536 519 537 #### Topology Routines #### 520 538 def _topology(self, gptr): -
django/contrib/gis/geos/tests/test_geos.py
diff -r 35aeedea954d django/contrib/gis/geos/tests/test_geos.py
a b 852 852 self.assertAlmostEqual(trans.x, p.x, prec) 853 853 self.assertAlmostEqual(trans.y, p.y, prec) 854 854 855 def test23_transform_noop(self): 856 """ Testing `transform` method (SRID match) """ 857 # transform() should no-op if source & dest SRIDs match, 858 # regardless of whether GDAL is available. 859 if gdal.HAS_GDAL: 860 g = GEOSGeometry('POINT (-104.609 38.255)', 4326) 861 gt = g.tuple 862 g.transform(4326) 863 self.assertEqual(g.tuple, gt) 864 self.assertEqual(g.srid, 4326) 865 866 g = GEOSGeometry('POINT (-104.609 38.255)', 4326) 867 g1 = g.transform(4326, clone=True) 868 self.assertEqual(g1.tuple, g.tuple) 869 self.assertEqual(g1.srid, 4326) 870 self.assert_(g1 is not g, "Clone didn't happen") 871 872 old_has_gdal = gdal.HAS_GDAL 873 try: 874 gdal.HAS_GDAL = False 875 876 g = GEOSGeometry('POINT (-104.609 38.255)', 4326) 877 gt = g.tuple 878 g.transform(4326) 879 self.assertEqual(g.tuple, gt) 880 self.assertEqual(g.srid, 4326) 881 882 g = GEOSGeometry('POINT (-104.609 38.255)', 4326) 883 g1 = g.transform(4326, clone=True) 884 self.assertEqual(g1.tuple, g.tuple) 885 self.assertEqual(g1.srid, 4326) 886 self.assert_(g1 is not g, "Clone didn't happen") 887 finally: 888 gdal.HAS_GDAL = old_has_gdal 889 890 def test23_transform_nosrid(self): 891 """ Testing `transform` method (no SRID) """ 892 # raise a warning if SRID <0/None 893 import warnings 894 895 print "\nBEGIN - expecting Warnings; safe to ignore.\n" 896 897 # test for do-nothing behaviour 898 g = GEOSGeometry('POINT (-104.609 38.255)', srid=None) 899 g.transform(2774) 900 self.assertEqual(g.tuple, (-104.609, 38.255)) 901 self.assertEqual(g.srid, None) 902 903 g = GEOSGeometry('POINT (-104.609 38.255)', srid=None) 904 g1 = g.transform(2774, clone=True) 905 self.assert_(g1 is None) 906 907 g = GEOSGeometry('POINT (-104.609 38.255)', srid=-1) 908 g.transform(2774) 909 self.assertEqual(g.tuple, (-104.609, 38.255)) 910 self.assertEqual(g.srid, -1) 911 912 g = GEOSGeometry('POINT (-104.609 38.255)', srid=-1) 913 g1 = g.transform(2774, clone=True) 914 self.assert_(g1 is None) 915 916 # test warning is raised 917 try: 918 warnings.simplefilter('error', FutureWarning) 919 920 g = GEOSGeometry('POINT (-104.609 38.255)', srid=None) 921 self.assertRaises(FutureWarning, g.transform, 2774) 922 923 g = GEOSGeometry('POINT (-104.609 38.255)', srid=None) 924 self.assertRaises(FutureWarning, g.transform, 2774, clone=True) 925 926 g = GEOSGeometry('POINT (-104.609 38.255)', srid=-1) 927 self.assertRaises(FutureWarning, g.transform, 2774) 928 929 g = GEOSGeometry('POINT (-104.609 38.255)', srid=-1) 930 self.assertRaises(FutureWarning, g.transform, 2774, clone=True) 931 finally: 932 warnings.simplefilter('default', category=FutureWarning) 933 934 print "\nEND - expecting Warnings; safe to ignore.\n" 935 936 def test23_transform_nogdal(self): 937 """ Testing `transform` method (GDAL not available) """ 938 old_has_gdal = gdal.HAS_GDAL 939 try: 940 gdal.HAS_GDAL = False 941 942 g = GEOSGeometry('POINT (-104.609 38.255)', 4326) 943 self.assertRaises(GEOSException, g.transform, 2774) 944 945 g = GEOSGeometry('POINT (-104.609 38.255)', 4326) 946 self.assertRaises(GEOSException, g.transform, 2774, clone=True) 947 finally: 948 gdal.HAS_GDAL = old_has_gdal 949 855 950 def test24_extent(self): 856 951 "Testing `extent` method." 857 952 # The xmin, ymin, xmax, ymax of the MultiPoint should be returned. -
docs/internals/deprecation.txt
diff -r 35aeedea954d docs/internals/deprecation.txt
a b 136 136 template variable, not an implied string. The new-style 137 137 behavior is provided in the ``future`` template tag library. 138 138 139 * :meth:`~django.contrib.gis.geos.GEOSGeometry.transform` will raise 140 a :class:`~django.contrib.gis.geos.GEOSException` when called 141 on a geometry with no SRID value. 142 139 143 * 2.0 140 144 * ``django.views.defaults.shortcut()``. This function has been moved 141 145 to ``django.contrib.contenttypes.views.shortcut()`` as part of the -
docs/ref/contrib/gis/geos.txt
diff -r 35aeedea954d docs/ref/contrib/gis/geos.txt
a b 523 523 524 524 Requires GDAL. 525 525 526 .. method:: transform(ct, clone=False) 526 .. method:: GEOSGeometry.transform(ct, clone=False) 527 528 .. versionchanged:: 1.3 527 529 528 530 Transforms the geometry according to the given coordinate transformation paramter 529 531 (``ct``), which may be an integer SRID, spatial reference WKT string, … … 537 539 538 540 Requires GDAL. 539 541 542 .. note:: 543 544 Prior to 1.3, this method would silently no-op if GDAL was not available. 545 Now, a :class:`~django.contrib.gis.geos.GEOSException` is raised as 546 application code relying on this behavior is in error. In addition, 547 use of this method when the SRID is ``None`` or less than 0 now generates 548 a warning because a :class:`~django.contrib.gis.geos.GEOSException` will 549 be raised instead in version 1.5. 550 551 540 552 ``Point`` 541 553 --------- 542 554 -
docs/ref/contrib/gis/install.txt
diff -r 35aeedea954d docs/ref/contrib/gis/install.txt
a b 98 98 .. admonition:: Install GDAL 99 99 100 100 While :ref:`gdalbuild` is technically not required, it is *recommended*. 101 Some features of GeoDjango (including the :ref:`ref-layermapping` and the geographic 102 admin) depend on its functionality. 101 Important features of GeoDjango (including the :ref:`ref-layermapping`, 102 geometry reprojection, and the geographic admin) depend on its 103 functionality. 103 104 104 105 .. note:: 105 106 … … 273 274 274 275 First download the latest GDAL release version and untar the archive:: 275 276 276 $ wget http://download.osgeo.org/gdal/gdal-1.7. 2.tar.gz277 $ tar xzf gdal-1.7. 2.tar.gz278 $ cd gdal-1.7. 2277 $ wget http://download.osgeo.org/gdal/gdal-1.7.3.tar.gz 278 $ tar xzf gdal-1.7.3.tar.gz 279 $ cd gdal-1.7.3 279 280 280 281 Configure, make and install:: 281 282 -
docs/releases/1.3-alpha-2.txt
diff -r 35aeedea954d docs/releases/1.3-alpha-2.txt
a b 95 95 **if the value is not None**, and falls back to the previously used 96 96 :setting:`MEDIA_URL` setting otherwise. 97 97 98 GeoDjango 99 --------- 100 101 * Previously, calling :meth:`~django.contrib.gis.geos.GEOSGeometry.transform` 102 would silently do nothing when GDAL wasn't available. Now, 103 a :class:`~django.contrib.gis.geos.GEOSException` is properly raised 104 to indicate possible faulty application code. A warning is now raised 105 if :meth:`~django.contrib.gis.geos.GEOSGeometry.transform` is called when 106 the SRID of the geometry is less than 0 or ``None``. 107 108 98 109 The Django 1.3 roadmap 99 110 ====================== 100 111