对 python 身材异常感到困惑 ctypes.ArgumentError

Confused about python shapely exception ctypes.ArgumentError

我刚刚安装得很好,基本的东西看起来还不错。我开始按照 this 教程中的示例来感受这个库。

具体来说:

>>> from shapely.wkt import loads
>>> g = loads('POINT (0.0 0.0)')
>>> g.buffer(1.0).area        # 16-gon approx of a unit radius circle
3.1365484905459389
>>> g.buffer(1.0, 128).area   # 128-gon approximation
3.1415138011443009
>>> g.buffer(1.0, 3).area     # triangle approximation
3.0
>>> list(g.buffer(1.0, cap_style='square').exterior.coords)
[(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
>>> g.buffer(1.0, cap_style='square').area
4.0

当我调用 g.buffer(1.0, cap_style='square') 时,出现以下错误:

  buf = list(shp.buffer(1.0, cap_style='square'))
File "/usr/lib64/python2.7/site-packages/shapely/geometry/base.py", line 538, in buffer
mitre_limit))
File "/usr/lib64/python2.7/site-packages/shapely/topology.py", line 78, in __call__
  return self.fn(this._geom, *args)
ctypes.ArgumentError: argument 5: <type 'exceptions.TypeError'>: wrong type

阅读文档here我看到这个例子在shapely/geometry/base.py模块的注释中。但是我注意到 cap_style 参数的默认值是 int (CAP_STYLE.round) 类型而不是字符串。不确定这是否意味着什么。

有谁知道发生了什么事吗?

看来你自己回答了你的问题:) 确实是你说的问题。 cap_style 关键参数必须是整数。而根据shapely documentation,只有以下值可用。

The styles of caps are specified by integer values: 1 (round), 2 (flat), 3 (square). These values are also enumerated by the object shapely.geometry.CAP_STYLE.