Создание LineString из массива Points Shapely - PullRequest
0 голосов
/ 26 июня 2019

У меня есть коллекция точек х и у. Скажите, что они:

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
...