Question

I want to access to the LinearRing of a Polygon simply like that :

from django.contrib.gis.geos import Polygon
poly = Polygon( ((0.0, 0.0), (0.0, 50.0), (50.0, 50.0), (50.0, 0.0), (0.0, 0.0)) )
poly[0]

I work inside a virtualenv with just Django 1.6 installed (Mac osx mavericks, python 2.7.5) When I write these few line inside the python interpretor, no problem:

<LinearRing object at 0x2761d00>

But when i use the Django shell, i got this error:

python manage.py shell
Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.contrib.gis.geos import Polygon 
>>> poly = Polygon( ((0.0, 0.0), (0.0, 50.0), (50.0, 50.0), (50.0, 0.0), (0.0, 0.0)) )
>>> poly[0]
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/xxx/.virtualenvs/rte-back/lib/python2.7/site-packages/django/contrib/gis/geos/geometry.py", line 141, in __repr__
     return '<%s object at %s>' % (self.geom_type, hex(addressof(self.ptr)))
  File "/Users/xxx/.virtualenvs/rte-back/lib/python2.7/site-packages/django/contrib/gis/geos/geometry.py", line 224, in geom_type
    return capi.geos_type(self.ptr).decode()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 1: ordinal not in range(128)

Why the result is not the same ?

Was it helpful?

Solution

Your settings.py should contain this string:

INSTALLED_APPS = (
    ...
    'django.contrib.gis',
    ...
)

OTHER TIPS

Have you add django geo to your install apps ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top