Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
1  
Post the EDIT 2 as an answer instead of as part of the question :) –  Francisco Puga Jan 19 '12 at 9:57
    
@FranciscoPuga done. Is there any advantage to adding it as an answer instead of an edit? –  EspadaV8 Jan 23 '12 at 1:21
    
It's just a good practice. The questions will appear as solved if you search for it, others users can vote your answer, ... And it's easy to read –  Francisco Puga Jan 23 '12 at 11:10
add comment

1 Answer

up vote 1 down vote accepted
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.

http://code.djangoproject.com/svn/django/tags/releases/1.3.1/django/contrib/gis/db/backends/base.py

You can read the TODO there about how GDAL is highly recommended for distance queries.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.