单行指向线串

我有一个 Pandas 数据框,其中包含一系列形状匀称的 Point 对象形式的起点和终点。我想将其转换为线串的地理数据库。


ID    orig_coord                                      dest_coord

0     POINT (-116.2847753565571 43.61722615312507)  POINT (-116.3042144501943 43.60844476082184)

1     POINT (-116.2847753565571 43.61722615312507)  POINT (-116.3042144501943 43.60844476082184)

2     POINT (-116.2847753565571 43.61722615312507)  POINT (-116.3042144501943 43.60844476082184)

我试过了df['line']=df.apply(lambda x: LineString()),但没有任何反应。我试过了df['line']=LineString([df['orig_coord'],df['dest_coord']]),但这给了我


---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

c:\users\...\py3\lib\site-packages\shapely\speedups\_speedups.pyx in shapely.speedups._speedups.geos_linestring_from_py()


AttributeError: 'list' object has no attribute '__array_interface__'


During handling of the above exception, another exception occurred:


AssertionError                            Traceback (most recent call last)

<ipython-input-31-fe64089b1dcf> in <module>

----> 1 df['line']=LineString([df['orig_coord'],df['dest_coord']])


c:\users\...\py3\lib\site-packages\shapely\geometry\linestring.py in __init__(self, coordinates)

     46         BaseGeometry.__init__(self)

     47         if coordinates is not None:

---> 48             self._set_coords(coordinates)

     49 

     50     @property


c:\users\...\py3\lib\site-packages\shapely\geometry\linestring.py in _set_coords(self, coordinates)

     95     def _set_coords(self, coordinates):

     96         self.empty()

---> 97         ret = geos_linestring_from_py(coordinates)

     98         if ret is not None:

     99             self._geom, self._ndim = ret


c:\users\...\py3\lib\site-packages\shapely\speedups\_speedups.pyx in shapely.speedups._speedups.geos_linestring_from_py()


AssertionError: 


鸿蒙传说
浏览 173回答 2
2回答

慕码人2483693

这里有一个解决方案:from shapely.geometry import Point, LineStringo = [Point (-116.2847753565571, 43.61722615312507),&nbsp; &nbsp; &nbsp;Point(-116.2847753565571, 43.61722615312507),&nbsp; &nbsp; &nbsp;Point (-116.2847753565571,43.61722615312507)]d = [Point (-116.3042144501943, 43.60844476082184),&nbsp; &nbsp; &nbsp;Point(-116.3042144501943,43.60844476082184),&nbsp; &nbsp; &nbsp;Point(-116.3042144501943,43.60844476082184)]df = pd.DataFrame({'orig_coord' : o, 'dest_coord': d})df['line']=df.apply(lambda x: LineString([x['orig_coord'], x['dest_coord']]),axis=1)print(df['line'])

aluckdog

我已经用它来获取 Point 对象,但我没有想到要重复这个过程:df['line']=[LineString(xy) for xy in zip(df.orig_coord,df.dest_coord)]
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python