Enabling OpenStreetMap in Django admin - error: "ImportError: cannot import name SpatialRefSys"

520 views
Skip to first unread message

gw

unread,
Aug 31, 2009, 6:23:26 AM8/31/09
to geodjango
Hi there,
I've just installed GeoDjango and am successfully using it in some of
my models. Great work on the framework - it's fantastic, particularly
the query API.

My issue: I'd like to be able to use the OpenStreetMaps map layer in
the admin interface, however I can't seem to add the required Mercator
projection detailed here:

http://geodjango.org/docs/install.html#addgoogleprojection

I get the following import error:

$ python manage.py shell
Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.contrib.gis.utils import add_postgis_srs
>>> add_postgis_srs(900913)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/django/contrib/gis/utils/
srs.py", line 15, in add_postgis_srs
from django.contrib.gis.models import SpatialRefSys
ImportError: cannot import name SpatialRefSys


I found this prior query on the same issue:
http://groups.google.com/group/geodjango/browse_thread/thread/dc56474989fae43d
so installed the GRASS framework and its python bindings using the
packages found in Debian Lenny's repositories. This did not help.

If I use the admin.OSMGeoAdmin admin widget in my models, I get a map
interface but with no contents.

I'm running Django 1.0.2 on Debian Lenny, with MySQL 5. I have
installed the PROJ.4 datum shifting files.

Any help would be appreciated.

Regards,

Graeme West

Adon Metcalfe

unread,
Aug 31, 2009, 3:22:56 PM8/31/09
to geod...@googlegroups.com
I found olwidget to be a much more easily extensible dropin for admin models & standalone pages :)


That has all the OSM layers presetup using yourcelf's very nice javascript wrapper for OpenLayers
--
Adon Metcalfe
mobile: 0429 080 931

Adon Metcalfe

unread,
Aug 31, 2009, 3:25:20 PM8/31/09
to geod...@googlegroups.com
PS I also found django 1.1 on postgis to work a bit better, though don't know if your stuck with mysql (postgres for me worked flawlessly out of the box, currently reprojecting views of about 100/200'000 tracking records from gda94 into spherical mercator only takes a couple of seconds)
Sent from West Leederville, Western Australia, Australia

gw

unread,
Sep 1, 2009, 6:56:11 AM9/1/09
to geodjango
Thanks Adon, that's really helpful. I've now enabled OSM in my views.

Unfortunately I am limited to using a MySQL database for now. On that
subject, could I ask whether there's any way to make a distance query
between two points in standard units (km, mile, meter, whatever) using
MySQL as a backend? I tried to do it, and got a 'join error'.

>>> GeoPoint.objects.filter(point__distance_lte=(barr.point, Distance(km=20)))
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/django/db/models/manager.py",
line 102, in filter
return self.get_query_set().filter(*args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/db/models/query.py",
line 489, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/db/models/query.py",
line 507, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/usr/lib/python2.5/site-packages/django/db/models/sql/
query.py", line 1258, in add_q
can_reuse=used_aliases)
File "/usr/lib/python2.5/site-packages/django/db/models/sql/
query.py", line 1133, in add_filter
negate=negate, process_extras=process_extras)
File "/usr/lib/python2.5/site-packages/django/db/models/sql/
query.py", line 1461, in setup_joins
raise FieldError("Join on field %r not permitted." % name)
FieldError: Join on field 'point' not permitted.

I can get the distance between polygons in degrees using GEOM, like
so:

>>> GeoPoly.objects.all()[2].poly.distance(GeoPoly.objects.all()[0].poly)
0.58908982480729088

but it doesn't seem like this can be quantified. Is there any way to
solve this issue using MySQL?

My model for points is as follows:

class GeoPoint(models.Model):
name = models.CharField(max_length=120, help_text="A reference name
for this geographical point")
point = models.PointField()
objects = models.GeoManager()

Thanks in advance for any ideas.

Regards,

Graeme






On Aug 31, 8:25 pm, Adon Metcalfe <adon.metca...@gmail.com> wrote:
> PS I also found django 1.1 on postgis to work a bit better, though don't
> know if your stuck with mysql (postgres for me worked flawlessly out of the
> box, currently reprojecting views of about 100/200'000 tracking records from
> gda94 into spherical mercator only takes a couple of seconds)
>
> >>http://groups.google.com/group/geodjango/browse_thread/thread/dc56474...
Reply all
Reply to author
Forward
0 new messages