Made get_srid_info() cache use a namedtuple.
This commit is contained in:
parent
24ae244a82
commit
e2bd2539b6
|
@ -1,4 +1,4 @@
|
||||||
from collections import defaultdict
|
from collections import defaultdict, namedtuple
|
||||||
|
|
||||||
from django.contrib.gis import forms, gdal
|
from django.contrib.gis import forms, gdal
|
||||||
from django.contrib.gis.db.models.proxy import SpatialProxy
|
from django.contrib.gis.db.models.proxy import SpatialProxy
|
||||||
|
@ -15,6 +15,9 @@ from django.utils.translation import gettext_lazy as _
|
||||||
_srid_cache = defaultdict(dict)
|
_srid_cache = defaultdict(dict)
|
||||||
|
|
||||||
|
|
||||||
|
SRIDCacheEntry = namedtuple('SRIDCacheEntry', ['units', 'units_name', 'spheroid'])
|
||||||
|
|
||||||
|
|
||||||
def get_srid_info(srid, connection):
|
def get_srid_info(srid, connection):
|
||||||
"""
|
"""
|
||||||
Return the units, unit name, and spheroid WKT associated with the
|
Return the units, unit name, and spheroid WKT associated with the
|
||||||
|
@ -38,9 +41,11 @@ def get_srid_info(srid, connection):
|
||||||
if srid not in _srid_cache[alias]:
|
if srid not in _srid_cache[alias]:
|
||||||
srs = get_srs(srid)
|
srs = get_srs(srid)
|
||||||
units, units_name = srs.units
|
units, units_name = srs.units
|
||||||
sphere_name = srs['spheroid']
|
_srid_cache[alias][srid] = SRIDCacheEntry(
|
||||||
spheroid = 'SPHEROID["%s",%s,%s]' % (sphere_name, srs.semi_major, srs.inverse_flattening)
|
units=units,
|
||||||
_srid_cache[alias][srid] = (units, units_name, spheroid)
|
units_name=units_name,
|
||||||
|
spheroid='SPHEROID["%s",%s,%s]' % (srs['spheroid'], srs.semi_major, srs.inverse_flattening),
|
||||||
|
)
|
||||||
|
|
||||||
return _srid_cache[alias][srid]
|
return _srid_cache[alias][srid]
|
||||||
|
|
||||||
|
@ -116,13 +121,13 @@ class BaseSpatialField(Field):
|
||||||
return connection.ops.geo_db_type(self)
|
return connection.ops.geo_db_type(self)
|
||||||
|
|
||||||
def spheroid(self, connection):
|
def spheroid(self, connection):
|
||||||
return get_srid_info(self.srid, connection)[2]
|
return get_srid_info(self.srid, connection).spheroid
|
||||||
|
|
||||||
def units(self, connection):
|
def units(self, connection):
|
||||||
return get_srid_info(self.srid, connection)[0]
|
return get_srid_info(self.srid, connection).units
|
||||||
|
|
||||||
def units_name(self, connection):
|
def units_name(self, connection):
|
||||||
return get_srid_info(self.srid, connection)[1]
|
return get_srid_info(self.srid, connection).units_name
|
||||||
|
|
||||||
def geodetic(self, connection):
|
def geodetic(self, connection):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue