Traceback (most recent call last): File "E:\code-study\coda\test.py", line 10, in <module> wgs84_pt = LineString( [ 121.382931917780112, 31.169374032349502 ], [ 121.382929337397997, 31.169373071122799 ], [ 121.382914911938002, 31.169367839196898 ], [ 121.382901579286994, 31.169363145813698 ], [ 121.382889331629997, 31.169358956119698 ], [ 121.382878161152988, 31.169355235261502 ], [ 121.382868060041005, 31.169351948385501 ], [ 121.382858993136992, 31.169349054259101 ], [ 121.382850815900994, 31.169346486133399 ], [ 121.382843356452994, 31.169344170880699 ], [ 121.382836442912009, 31.169342035372896 ], [ 121.382829903393997, 31.169340006482201 ], [ 121.382823544104994, 31.169338011003198 ], [ 121.382817083588009, 31.169335975420999 ], [ 121.382810218472997, 31.169333826143397 ], [ 121.382802645389006, 31.169331489578099 ], [ 121.382794060965992, 31.169328892132697 ], [ 121.382784213861996, 31.169325965687701 ] ) TypeError: __new__() takes from 1 to 2 positional arguments but 19 were given
时间: 2024-01-03 11:02:56 浏览: 79
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
这个错误提示告诉我们,LineString 类的 __new__() 方法接受的位置参数数量是 1 或 2,但是你传入了 19 个位置参数,因此导致了 TypeError。这个错误很可能是因为你传入 LineString 的参数是一组包含多个坐标点的列表,而 LineString 类只接受一个包含所有坐标点的列表。你需要将所有坐标点组成一个列表,然后再传入 LineString 类。可以这样写:
```
coords = [
[ 121.382931917780112, 31.169374032349502 ],
[ 121.382929337397997, 31.169373071122799 ],
[ 121.382914911938002, 31.169367839196898 ],
[ 121.382901579286994, 31.169363145813698 ],
[ 121.382889331629997, 31.169358956119698 ],
[ 121.382878161152988, 31.169355235261502 ],
[ 121.382868060041005, 31.169351948385501 ],
[ 121.382858993136992, 31.169349054259101 ],
[ 121.382850815900994, 31.169346486133399 ],
[ 121.382843356452994, 31.169344170880699 ],
[ 121.382836442912009, 31.169342035372896 ],
[ 121.382829903393997, 31.169340006482201 ],
[ 121.382823544104994, 31.169338011003198 ],
[ 121.382817083588009, 31.169335975420999 ],
[ 121.382810218472997, 31.169333826143397 ],
[ 121.382802645389006, 31.169331489578099 ],
[ 121.382794060965992, 31.169328892132697 ],
[ 121.382784213861996, 31.169325965687701 ]
]
wgs84_pt = LineString(coords)
```
这样应该就能正确创建 LineString 对象了。
阅读全文