我有一个95000项的shapefile,我使用read_file
导入带有GeoPandas的文件。该项目是几何结构相当简单的多边形,最大的多边形有316个点。
问题
虽然使用选项options.use_pygeos = True
进行一些速度测试实际上会减慢读取文件的进程。
我使用的是GeoPandas版本0.10.2和pygeos版本0.12.0。我读到有人在从0.8.2版本升级到0.9版本时遇到了同样的问题
实际减速:
time with pygeos 10.6 s
time without pygeos 5.3 s
问题
有人再现这种行为吗?,我们怎样才能避免这种情况?
编辑
这是代码的摘录。我在pyqt5 GUI中使用它。
我最后用了pyogrio和pygeos。这几乎就像一个GeoDataFrame,所以它是非常方便的
数据:https://drive.google.com/file/d/1abzDcvD3cATuKOOUoBA89p5rwvrgpFci/view?usp=sharing
另一个结果
geopandas + pygeos
geopandas: 9.635942159632514
pygeos: geometry to numpy array: 1.8224096298217773
geopandas - pygeos
geopandas: 6.420444488525391
pygeos: geometry to numpy array: 0.251056432723999
pyogrio + pygeos
pyogrio: 1.9999799728393555
pygeos: geometry to numpy array: 0.06801533699035645
代码
import time
import geopandas as gp
gp.options.use_pygeos = True
import pygeos
import pyogrio
shp = r'00_PREDIO_GENERAL.shp'
t0 = time.time()
gdf = gp.read_file(shp)
print('geopandas: ', time.time() - t0)
t0 = time.time()
p_array, idx_coords = pygeos.get_coordinates(pygeos.from_shapely(gdf.geometry), return_index=True)
print('pygeos: geometry to numpy array: ', time.time() - t0)
t0 = time.time()
gdf = pyogrio.read_dataframe(shp)
print('pyogrio: ', time.time() - t0)
t0 = time.time()
gp.options.use_pygeos = False
p_array, idx_coords = pygeos.get_coordinates(gdf.geometry, return_index=True)
print('pygeos: geometry to numpy array: ', time.time() - t0)
你能在读取shapefile之前尝试一下这段代码吗?到目前为止,我也遇到了同样的错误:
import shapely
shapely.speedups.disable()