我尝试在QGIS中创建一个多边形shapefile,并用python逐个读取它。示例代码如下所示:
import fiona
from shapely.geometry import shape
multipolys = fiona.open(somepath)
multi = multipolys[0]
coord = shape(multi['geometry'])
EOSGeom_createLinearRing_r返回一个空指针,检查多边形在QGIS中是否有效,并且没有报告错误。实际上,它甚至不适用于在QGIS中生成的一个简单的三角形。有人知道怎么解决这个问题吗?
谢谢
发布于 2020-09-02 00:35:28
和J. P.一样,我在创建LineStrings时也遇到了这个问题。在Shapely github存储库中有an old issue (2016),这似乎是相关的。更改导入的顺序为我解决了问题:
from shapely.geometry import LineString
import fiona
LineString([[0, 0], [1, 1]]).to_wkt()
# 'LINESTRING (0.0000000000000000 0.0000000000000000, 1.0000000000000000 1.0000000000000000)'
鉴于
import fiona
from shapely.geometry import LineString
LineString([[0, 0], [1, 1]]).to_wkt()
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# File "C:\Users\xxxxxxx\AppData\Roaming\Python\Python37\site-packages\shapely\geometry\linestring.py", line 48, in __init__
# self._set_coords(coordinates)
# File "C:\Users\xxxxxxx\AppData\Roaming\Python\Python37\site-packages\shapely\geometry\linestring.py", line 97, in _set_coords
# ret = geos_linestring_from_py(coordinates)
# File "shapely\speedups\_speedups.pyx", line 208, in shapely.speedups._speedups.geos_linestring_from_py
# ValueError: GEOSGeom_createLineString_r returned a NULL pointer
Shapely存储库中需要查看的其他一些问题
针对Mac
和osgeo
的反向导入顺序技巧相同
https://stackoverflow.com/questions/62075847
复制相似问题