gpt4 book ai didi

python - Django Geo 访问 Polygon 的 LinearRing 不适用于 django shell

转载 作者:行者123 更新时间:2023-12-01 05:14:30 24 4
gpt4 key购买 nike

我想像这样访问多边形的 LinearRing :

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)

为什么结果不一样?

最佳答案

您的settings.py应包含以下字符串:

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

关于python - Django Geo 访问 Polygon 的 LinearRing 不适用于 django shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23489199/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com