2016-10-11 79 views
0

我剛剛安裝好身材,基本的東西看起來很好。我開始在this教程中使用一個示例來感受一下圖書館。關於蟒蛇形狀異常的困惑ctypes.ArgumentError

具體做法是:

>>> 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我看到,這個例子是在勻稱的評論/geometry/base.py模塊。但是我注意到,cap_style參數的默認值是int類型(CAP_STYLE.round),而不是字符串。不知道這是否意味着什麼。

有沒有人有任何想法是怎麼回事?

回答

0

看來你自己回答了你的問題:) 這確實是你提到的問題。 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.