LayerMapping no longer available?

587 views
Skip to first unread message

Flavio Coelho

unread,
Apr 4, 2009, 4:30:20 AM4/4/09
to geodjango
Hi I have used the layermapping method described in the wiki to import
shapefiles into the database, now it is giving an error:

In [1]: from django.contrib.gis.utils import LayerMapping
---------------------------------------------------------------------------
ImportError Traceback (most recent call
last)

/home/fccoelho/<ipython console> in <module>()

ImportError: cannot import name LayerMapping


what's the current way to import LayerMapping?

thanks in advance,

Flávio

Ariel Mauricio Nunez Gomez

unread,
Apr 4, 2009, 9:20:01 AM4/4/09
to geod...@googlegroups.com
Flavio,

Can you try the following and let us know what's the output:

>>>from django.contrib.gis.gdal import HAS_GDAL
>>>print HAS_GDAL

Flávio Codeço Coelho

unread,
Apr 6, 2009, 5:52:14 AM4/6/09
to geod...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

the output is "True"

Ariel Mauricio Nunez Gomez wrote:
> Flavio,
>
> Can you try the following and let us know what's the output:
>
>>>>from django.contrib.gis.gdal import /HAS_GDAL/
>>>>print HAS_GDAL
>
> >
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknZ0MQACgkQC7yysgGhWotVSQCgokmHn5gU1XujkhsWtrn5YSV7
sDsAoJGvW7VmHLOYbwJ4k868AFgPQ1mZ
=YOEb
-----END PGP SIGNATURE-----

Ariel Mauricio Nunez Gomez

unread,
Apr 6, 2009, 8:24:58 AM4/6/09
to geod...@googlegroups.com
Ok, the way you are using to import LayerMapping should work, but the problem is that the import there masks any other errors that may appear:

http://code.djangoproject.com/browser/django/trunk/django/contrib/gis/utils/__init__.py

10     try:
11         # LayerMapping requires DJANGO_SETTINGS_MODULE to be set,
12         # so this needs to be in try/except.
13         from django.contrib.gis.utils.layermapping import LayerMapping
14     except:
15         pass


Please, try ti import it directly and see what happens:

from django.contrib.gis.utils.layermapping import LayerMapping

Regards,
Ariel

patrick91

unread,
May 10, 2009, 2:20:32 AM5/10/09
to geodjango
I've the same problem, first I tried this code:
>>>from django.contrib.gis.gdal import HAS_GDAL
>>>print HAS_GDAL
and the result was:
True

Also I tried this code:
>>> from django.contrib.gis.utils.layermapping import LayerMapping

and the result was:

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/
django/contrib/gis/utils/layermapping.py", line 119, in <module>
from django.contrib.gis.models import GeometryColumns,
SpatialRefSys
ImportError: cannot import name GeometryColumns

thanks for any help :)

Ariel Nunez

unread,
May 10, 2009, 9:19:33 AM5/10/09
to geod...@googlegroups.com

Traceback (most recent call last):
 File "<console>", line 1, in <module>
 File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/
django/contrib/gis/utils/layermapping.py", line 119, in <module>
   from django.contrib.gis.models import GeometryColumns,
SpatialRefSys
ImportError: cannot import name GeometryColumns


Have you verified your db has a spatial_ref_sys and a geometry_columns table?

Sourabh

unread,
Sep 15, 2013, 2:02:44 PM9/15/13
to geod...@googlegroups.com
I've the same problem, first I tried this code:
>>>from django.contrib.gis.gdal import HAS_GDAL
>>>print HAS_GDAL
and the result was:
FALSE

Let me know what should i do in this case

I also tried to use try except but was getting below error-

django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANG
O_SETTINGS_MODULE or call settings.configure() before accessing settings.

i have properly set DJANGO_SETTINGS_MODULE value but still getting above error.

Can you please help.

Regards,
Sourabh

Claude Paroz

unread,
Sep 16, 2013, 3:48:38 PM9/16/13
to geod...@googlegroups.com
Le dimanche 15 septembre 2013 à 11:02 -0700, Sourabh a écrit :
> I've the same problem, first I tried this code:
> >>>from django.contrib.gis.gdal import HAS_GDAL
> >>>print HAS_GDAL
>
> and the result was:
> FALSE
>
> Let me know what should i do in this case

https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/geolibs/#can-t-find-gdal-library

> I also tried to use try except but was getting below error-
>
> django.core.exceptions.ImproperlyConfigured: Requested setting
> DATABASES, but settings are not configured. You must either define the
> environment variable DJANG
> O_SETTINGS_MODULE or call settings.configure() before accessing
> settings.
>
> i have properly set DJANGO_SETTINGS_MODULE value but still getting
> above error.

This is more django-users territory, not GIS specific. You might get
more support by asking on IRC channels (#django for example).

Good luck!

Claude
--
www.2xlibre.net

Reply all
Reply to author
Forward
0 new messages