2

我正在使用python读取shapefile,但是遇到了一些问题,这是核心代码:

value="#code"
print 'value:',value
if '#' in value:
    v=value.replace('#','');
    print 'replaced:',v
    fixed_value=str(feature.GetFieldAsString(v))

如果我直接运行脚本,它会按预期工作,但是一旦我在 Web 环境中运行它就会抛出错误,我会得到如下错误:

  File "/home/kk/gis/codes/tilestache/map/__init__.py", line 162, in _get_features
    fixed_value=str(feature.GetFieldAsString(v))
  File "/usr/local/lib/python2.7/dist-packages/GDAL-1.10.1-py2.7-linux-x86_64.egg/osgeo/ogr.py", line 2233, in GetFieldAsString
    return _ogr.Feature_GetFieldAsString(self, *args)
NotImplementedError: Wrong number of arguments for overloaded function 'Feature_GetFieldAsString'.

如果我将行更改为:

fixed_value=str(feature.GetFieldAsString('code'))

有效。

这是怎么回事?

似乎replacepython中的函数让事情变得很奇怪。


更新

似乎我明白了,这是由replacepython中的函数引起的,它返回一个不同的而不是str

value='#code'
type(value) ==> str
v=value.replace('#','')
type(v) ==>unicode

然后我使用:

 fixed_value=str(feature.GetFieldAsString(str(v)))

有效。

但我不确定为什么它在 shell 环境中工作,而不是在 web 环境中工作。我希望有人能解释一下。

4

0 回答 0