I have a site that's working on our staging server but after copying it to the live server I am getting the following error when trying to perform a distance() call (code cut down to minimum)
>>> Buddy.objects.all().distance(pnt[0].geom, field_name='postalcode__geom')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/buddyup/sites/buddyup/lib/python2.6/site-packages/django/contrib/gis/db/models/query.py", line 100, in distance
return self._distance_attribute('distance', geom, **kwargs)
File "/home/buddyup/sites/buddyup/lib/python2.6/site-packages/django/contrib/gis/db/models/query.py", line 582, in _distance_attribute
geodetic = geo_field.geodetic(connection)
File "/home/buddyup/sites/buddyup/lib/python2.6/site-packages/django/contrib/gis/db/models/fields.py", line 131, in geodetic
return self.units_name(connection) in self.geodetic_units
File "/home/buddyup/sites/buddyup/lib/python2.6/site-packages/django/contrib/gis/db/models/fields.py", line 122, in units_name
self._get_srid_info(connection)
File "/home/buddyup/sites/buddyup/lib/python2.6/site-packages/django/contrib/gis/db/models/fields.py", line 108, in _get_srid_info
self._units, self._units_name, self._spheroid = get_srid_info(self.srid, connection)
File "/home/buddyup/sites/buddyup/lib/python2.6/site-packages/django/contrib/gis/db/models/fields.py", line 35, in get_srid_info
units, units_name = sr.units
File "/home/buddyup/sites/buddyup/lib/python2.6/site-packages/django/contrib/gis/db/backends/base.py", line 281, in units
return (self.linear_units, self.linear_name)
File "/home/buddyup/sites/buddyup/lib/python2.6/site-packages/django/contrib/gis/db/backends/base.py", line 253, in linear_units
return m.group('unit')
AttributeError: 'NoneType' object has no attribute 'group'
>>> pnt[0].geom
<Point object at 0x1fb0370>
I've been unable to find any information elsewhere this error. Any help as to what might be causing this would be very welcome.
EDIT
Not having a clue what I'm doing, I've come up with possibly the best patch in the world /s
--- /home/buddyup/base.py 2012-01-18 22:17:04.000000000 -0500
+++ /home/buddyup/sites/buddyup/lib/python2.6/site-packages/django/contrib/gis/db/backends/base.py 2012-01-18 22:16:09.000000000 -0500
@@ -239,7 +239,8 @@
return None
else:
m = self.units_regex.match(self.wkt)
- return m.group('unit_name')
+ return 'meter'
+ #return m.group('unit_name')
@property
def linear_units(self):
@@ -250,7 +251,8 @@
return None
else:
m = self.units_regex.match(self.wkt)
- return m.group('unit')
+ return 'm'
+ #return m.group('unit')
@property
def angular_name(self):
I have no idea why it is unable to find the units or the units name, but for now that works for me. I would love to hear what the actual problem could be and find a valid solution.
EDIT 2
yum install gdal
After talking to pizzaparty in the #django IRC channel he pointed out that installed gdal should stop Django trying to get the units from a Point object that doesn't have any. That seems to be a much better solution.
