diff options
| author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2017-04-01 00:59:44 +0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-04-07 12:24:38 -0400 |
| commit | e2bd2539b6d30a6f60dacdad9b8e15a2d4085484 (patch) | |
| tree | d04fa4af1de5a6a0537130292983f9a3e0a42dfa | |
| parent | 24ae244a82634254674414bbb99fe10e4c7c08cc (diff) | |
Made get_srid_info() cache use a namedtuple.
| -rw-r--r-- | django/contrib/gis/db/models/fields.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/django/contrib/gis/db/models/fields.py b/django/contrib/gis/db/models/fields.py index 737d757664..e27ff2dcf3 100644 --- a/django/contrib/gis/db/models/fields.py +++ b/django/contrib/gis/db/models/fields.py @@ -1,4 +1,4 @@ -from collections import defaultdict +from collections import defaultdict, namedtuple from django.contrib.gis import forms, gdal 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) +SRIDCacheEntry = namedtuple('SRIDCacheEntry', ['units', 'units_name', 'spheroid']) + + def get_srid_info(srid, connection): """ 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]: srs = get_srs(srid) units, units_name = srs.units - sphere_name = srs['spheroid'] - spheroid = 'SPHEROID["%s",%s,%s]' % (sphere_name, srs.semi_major, srs.inverse_flattening) - _srid_cache[alias][srid] = (units, units_name, spheroid) + _srid_cache[alias][srid] = SRIDCacheEntry( + units=units, + units_name=units_name, + spheroid='SPHEROID["%s",%s,%s]' % (srs['spheroid'], srs.semi_major, srs.inverse_flattening), + ) return _srid_cache[alias][srid] @@ -116,13 +121,13 @@ class BaseSpatialField(Field): return connection.ops.geo_db_type(self) def spheroid(self, connection): - return get_srid_info(self.srid, connection)[2] + return get_srid_info(self.srid, connection).spheroid 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): - return get_srid_info(self.srid, connection)[1] + return get_srid_info(self.srid, connection).units_name def geodetic(self, connection): """ |
