Loading django/contrib/gis/tests/test_spatialrefsys.py +30 −17 Original line number Diff line number Diff line Loading @@ -3,6 +3,8 @@ import unittest from django.contrib.gis.gdal import HAS_GDAL from django.contrib.gis.tests.utils import (no_mysql, oracle, postgis, spatialite, HAS_SPATIALREFSYS, SpatialRefSys) from django.contrib.gis.utils import add_srs_entry from django.db import connection from django.utils import six Loading Loading @@ -38,8 +40,10 @@ test_srs = ({'srid': 4326, class SpatialRefSysTest(unittest.TestCase): @no_mysql def test01_retrieve(self): "Testing retrieval of SpatialRefSys model objects." def test_retrieve(self): """ Test retrieval of SpatialRefSys model objects. """ for sd in test_srs: srs = SpatialRefSys.objects.get(srid=sd['srid']) self.assertEqual(sd['srid'], srs.srid) Loading @@ -59,8 +63,10 @@ class SpatialRefSysTest(unittest.TestCase): six.assertRegex(self, srs.proj4text, sd['proj4_re']) @no_mysql def test02_osr(self): "Testing getting OSR objects from SpatialRefSys model objects." def test_osr(self): """ Test getting OSR objects from SpatialRefSys model objects. """ for sd in test_srs: sr = SpatialRefSys.objects.get(srid=sd['srid']) self.assertEqual(True, sr.spheroid.startswith(sd['spheroid'])) Loading @@ -76,13 +82,15 @@ class SpatialRefSysTest(unittest.TestCase): if postgis or spatialite: srs = sr.srs six.assertRegex(self, srs.proj4, sd['proj4_re']) # No `srtext` field in the `spatial_ref_sys` table in SpatiaLite if not spatialite: # No `srtext` field in the `spatial_ref_sys` table in SpatiaLite < 4 if not spatialite or connection.ops.spatial_version[0] >= 4: self.assertTrue(srs.wkt.startswith(sd['srtext'])) @no_mysql def test03_ellipsoid(self): "Testing the ellipsoid property." def test_ellipsoid(self): """ Test the ellipsoid property. """ for sd in test_srs: # Getting the ellipsoid and precision parameters. ellps1 = sd['ellipsoid'] Loading @@ -95,12 +103,17 @@ class SpatialRefSysTest(unittest.TestCase): for i in range(3): self.assertAlmostEqual(ellps1[i], ellps2[i], prec[i]) def suite(): s = unittest.TestSuite() s.addTest(unittest.makeSuite(SpatialRefSysTest)) return s def run(verbosity=2): unittest.TextTestRunner(verbosity=verbosity).run(suite()) @no_mysql def test_add_entry(self): """ Test adding a new entry in the SpatialRefSys model using the add_srs_entry utility. """ add_srs_entry(900913) self.assertTrue( SpatialRefSys.objects.filter(srid=900913).exists() ) srs = SpatialRefSys.objects.get(srid=900913) self.assertTrue( SpatialRefSys.get_spheroid(srs.wkt).startswith('SPHEROID[') ) django/contrib/gis/utils/srs.py +2 −2 Original line number Diff line number Diff line from django.contrib.gis.gdal import SpatialReference from django.db import connections, DEFAULT_DB_ALIAS def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None, Loading Loading @@ -30,10 +31,9 @@ def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None, database: The name of the database connection to use; the default is the value of `django.db.DEFAULT_DB_ALIAS` (at the time of this writing, it's value of `django.db.DEFAULT_DB_ALIAS` (at the time of this writing, its value is 'default'). """ from django.db import connections, DEFAULT_DB_ALIAS if not database: database = DEFAULT_DB_ALIAS connection = connections[database] Loading Loading
django/contrib/gis/tests/test_spatialrefsys.py +30 −17 Original line number Diff line number Diff line Loading @@ -3,6 +3,8 @@ import unittest from django.contrib.gis.gdal import HAS_GDAL from django.contrib.gis.tests.utils import (no_mysql, oracle, postgis, spatialite, HAS_SPATIALREFSYS, SpatialRefSys) from django.contrib.gis.utils import add_srs_entry from django.db import connection from django.utils import six Loading Loading @@ -38,8 +40,10 @@ test_srs = ({'srid': 4326, class SpatialRefSysTest(unittest.TestCase): @no_mysql def test01_retrieve(self): "Testing retrieval of SpatialRefSys model objects." def test_retrieve(self): """ Test retrieval of SpatialRefSys model objects. """ for sd in test_srs: srs = SpatialRefSys.objects.get(srid=sd['srid']) self.assertEqual(sd['srid'], srs.srid) Loading @@ -59,8 +63,10 @@ class SpatialRefSysTest(unittest.TestCase): six.assertRegex(self, srs.proj4text, sd['proj4_re']) @no_mysql def test02_osr(self): "Testing getting OSR objects from SpatialRefSys model objects." def test_osr(self): """ Test getting OSR objects from SpatialRefSys model objects. """ for sd in test_srs: sr = SpatialRefSys.objects.get(srid=sd['srid']) self.assertEqual(True, sr.spheroid.startswith(sd['spheroid'])) Loading @@ -76,13 +82,15 @@ class SpatialRefSysTest(unittest.TestCase): if postgis or spatialite: srs = sr.srs six.assertRegex(self, srs.proj4, sd['proj4_re']) # No `srtext` field in the `spatial_ref_sys` table in SpatiaLite if not spatialite: # No `srtext` field in the `spatial_ref_sys` table in SpatiaLite < 4 if not spatialite or connection.ops.spatial_version[0] >= 4: self.assertTrue(srs.wkt.startswith(sd['srtext'])) @no_mysql def test03_ellipsoid(self): "Testing the ellipsoid property." def test_ellipsoid(self): """ Test the ellipsoid property. """ for sd in test_srs: # Getting the ellipsoid and precision parameters. ellps1 = sd['ellipsoid'] Loading @@ -95,12 +103,17 @@ class SpatialRefSysTest(unittest.TestCase): for i in range(3): self.assertAlmostEqual(ellps1[i], ellps2[i], prec[i]) def suite(): s = unittest.TestSuite() s.addTest(unittest.makeSuite(SpatialRefSysTest)) return s def run(verbosity=2): unittest.TextTestRunner(verbosity=verbosity).run(suite()) @no_mysql def test_add_entry(self): """ Test adding a new entry in the SpatialRefSys model using the add_srs_entry utility. """ add_srs_entry(900913) self.assertTrue( SpatialRefSys.objects.filter(srid=900913).exists() ) srs = SpatialRefSys.objects.get(srid=900913) self.assertTrue( SpatialRefSys.get_spheroid(srs.wkt).startswith('SPHEROID[') )
django/contrib/gis/utils/srs.py +2 −2 Original line number Diff line number Diff line from django.contrib.gis.gdal import SpatialReference from django.db import connections, DEFAULT_DB_ALIAS def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None, Loading Loading @@ -30,10 +31,9 @@ def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None, database: The name of the database connection to use; the default is the value of `django.db.DEFAULT_DB_ALIAS` (at the time of this writing, it's value of `django.db.DEFAULT_DB_ALIAS` (at the time of this writing, its value is 'default'). """ from django.db import connections, DEFAULT_DB_ALIAS if not database: database = DEFAULT_DB_ALIAS connection = connections[database] Loading