我有点x和y的集合。说他们是:
import numpy as np
from shapely.geometry import Point, LineString
from shapely.geometry.polygon import Polygon
from geopandas import GeoSeries
x_data = np.arrange(20)
y_data = np.arrange(20)
现在,我想要一个点数组,然后再从该数组的区域中创建LineString。现在我有:
points = GeoSeries(map(Point, zip(x_data, y_data)))
我的问题是关于LineString的创建。我这样做:
line = LineString([points[initial:last]])
但这给了我错误:
Traceback (most recent call last): File
"shapely\speedups\_speedups.pyx", line 86, in
shapely.speedups._speedups.geos_linestring_from_py File "C:\Program
Files\Python37\lib\site-packages\pandas\core\generic.py", line 5063,
in \__getattr\__
return object.\__getattribute\__(self, name) AttributeError: 'GeoSeries' object has no attribute '\__array_interface\__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File ".\my_progam.py",
line 292, in <module>
line = LineString(points[initial:last]) File "C:\Program Files\Python37\lib\site-packages\shapely\geometry\linestring.py", line
48, in \__init\__
self._set_coords(coordinates) File "C:\Program Files\Python37\lib\site-packages\shapely\geometry\linestring.py", line
97, in _set_coords
ret = geos_linestring_from_py(coordinates) File "shapely\speedups\_speedups.pyx", line 162, in
shapely.speedups._speedups.geos_linestring_from_py File "C:\Program
Files\Python37\lib\site-packages\geopandas\geoseries.py", line 143, in
\__getitem\__
return self._wrapped_pandas_method('\__getitem\__', key) File "C:\Program Files\Python37\lib\site-packages\geopandas\geoseries.py",
line 135, in _wrapped_pandas_method
val = getattr(super(GeoSeries, self), mtd)(*args, **kwargs) File "C:\Program Files\Python37\lib\site-packages\pandas\core\series.py",
line 868, in \__getitem\__
result = self.index.get_value(self, key) File "C:\Program Files\Python37\lib\site-packages\pandas\core\indexes\base.py", line
4374, in get_value
tz=getattr(series.dtype, 'tz', None)) File "pandas\_libs\index.pyx", line 81, in
pandas._libs.index.IndexEngine.get_value File
"pandas\_libs\index.pyx", line 89, in
pandas._libs.index.IndexEngine.get_value File
"pandas\_libs\index.pyx", line 132, in
pandas._libs.index.IndexEngine.get_loc File
"pandas\_libs\hashtable_class_helper.pxi", line 987, in
pandas._libs.hashtable.Int64HashTable.get_item File
"pandas\_libs\hashtable_class_helper.pxi", line 993, in
pandas._libs.hashtable.Int64HashTable.get_item KeyError: 0