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