我想像这样访问多边形的线性环:
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]
我在仅安装了 Django 1.6 的 virtualenv 中工作(Mac osx mavericks,python 2.7.5)当我在 python 解释器中编写这几行时,没问题:
<LinearRing object at 0x2761d00>
但是当我使用 Django shell 时,我得到了这个错误:
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)
为什么结果不一样?