Opened 9 years ago

Closed 9 years ago

#25797 closed Bug (fixed)

error when using GeoManager.distance on fields with SRID 32140 with no GDAL

Reported by: Sergey Fedoseev Owned by: Sergey Fedoseev
Component: GIS Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

models.py

class Test(models.Model):
    point = models.PointField(srid=32140)

    objects = models.GeoManager()
In [2]: Test.objects.distance(Point(0, 1, srid=4326))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-13b46a88fb50> in <module>()
----> 1 Test.objects.distance(Point(0, 1, srid=4326))


/home/sergey/dev/django/django/db/models/manager.pyc in manager_method(self, *args, **kwargs)
    120         def create_method(name, method):
    121             def manager_method(self, *args, **kwargs):
--> 122                 return getattr(self.get_queryset(), name)(*args, **kwargs)
    123             manager_method.__name__ = method.__name__
    124             manager_method.__doc__ = method.__doc__

/home/sergey/dev/django/django/contrib/gis/db/models/query.pyc in distance(self, geom, **kwargs)
     84                         is used.
     85         """
---> 86         return self._distance_attribute('distance', geom, **kwargs)
     87 
     88     def envelope(self, **kwargs):

/home/sergey/dev/django/django/contrib/gis/db/models/query.pyc in _distance_attribute(self, func, geom, tolerance, spheroid, **kwargs)
    494         # units of the geometry field.
    495         connection = connections[self.db]
--> 496         geodetic = geo_field.geodetic(connection)
    497         geography = geo_field.geography
    498 

/home/sergey/dev/django/django/contrib/gis/db/models/fields.pyc in geodetic(self, connection)
    146         system that uses non-projected units (e.g., latitude/longitude).
    147         """
--> 148         units_name = self.units_name(connection)
    149         # Some backends like MySQL cannot determine units name. In that case,
    150         # test if srid is 4326 (WGS84), even if this is over-simplification.

/home/sergey/dev/django/django/contrib/gis/db/models/fields.pyc in units_name(self, connection)
    138     def units_name(self, connection):
    139         if not hasattr(self, '_units_name'):
--> 140             self._get_srid_info(connection)
    141         return self._units_name
    142 

/home/sergey/dev/django/django/contrib/gis/db/models/fields.pyc in _get_srid_info(self, connection)
    124     def _get_srid_info(self, connection):
    125         # Get attributes from `get_srid_info`.
--> 126         self._units, self._units_name, self._spheroid = get_srid_info(self.srid, connection)
    127 
    128     def spheroid(self, connection):

/home/sergey/dev/django/django/contrib/gis/db/models/fields.pyc in get_srid_info(srid, connection)
     38         # Use `SpatialRefSys` model to query for spatial reference info.
     39         sr = SpatialRefSys.objects.using(connection.alias).get(srid=srid)
---> 40         units, units_name = sr.units
     41         spheroid = SpatialRefSys.get_spheroid(sr.wkt)
     42         _srid_cache[connection.alias][srid] = (units, units_name, spheroid)

/home/sergey/dev/django/django/contrib/gis/db/backends/base/models.pyc in units(self)
    161         "Returns a tuple of the units and the name."
    162         if self.projected or self.local:
--> 163             return (self.linear_units, self.linear_name)
    164         elif self.geographic:
    165             return (self.angular_units, self.angular_name)

/home/sergey/dev/django/django/contrib/gis/db/backends/base/models.pyc in linear_units(self)
    133         else:
    134             m = self.units_regex.match(self.wkt)
--> 135             return m.group('unit')
    136 
    137     @property

AttributeError: 'NoneType' object has no attribute 'group'

Change History (5)

comment:1 by Sergey Fedoseev, 9 years ago

Owner: changed from nobody to Sergey Fedoseev
Status: newassigned

comment:2 by Sergey Fedoseev, 9 years ago

Has patch: set

comment:3 by Tim Graham, 9 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 717a54c8:

Fixed #25797 -- Fixed regex for getting units from SRS WKT.

Note: See TracTickets for help on using tickets.
Back to Top