如何将 GeoDataFrame 插入 SQLite
尝试将带有几何变量的 GeoDataFrame 插入到 SQLite 中,出现以下错误:
在enable_spatialite_extension中,从错误spatialite.connection.LoadExtensionError中引发LoadExtensionError(msg):无法加载Spatialite扩展。验证您的 python 模块 sqlite3 是否具有加载扩展支持并检查 libspatialite 是否已安装。尝试过的扩展名称:mod_spatialite、mod_spatialite.so、mod_spatiaite.dylib
我正在 WayScript (IDE) 上运行我的代码,我不知道如何正确安装此模块,甚至也不知道如何在以下文件夹中找到 mod_spatialite.dll 文件在系统路径中。
这是我的代码:
# Create the database connection
connection = sqlite3.connect('database.db')
# Export data to database
data.to_sql('database', con=connection, if_exists='replace', index=False)
# Add a new table column to store the geometry data
cursor = connection.cursor()
cursor.enable_load_extension(True)
cursor.load_extension("mod_spatialite")
cursor.execute("SELECT InitSpatialMetaData(1);")
cursor.execute(
"""
SELECT AddGeometryColumn('database', 'wkb_geometry', 4326, 'POLYGON', 2);
"""
)
Trying to insert a GeoDataFrame with geometry variables to SQLite, I get the following error:
in enable_spatialite_extension raise LoadExtensionError(msg) from error spatialite.connection.LoadExtensionError: Failed to load Spatialite extension. Verify that your python module sqlite3 has load extension support and check that libspatialite is installed. Tried extension names: mod_spatialite, mod_spatialite.so, mod_spatiaite.dylib
I am running my code on WayScript (IDE), and I do not know how to install this module properly, even nor how to locate mod_spatialite.dll file in a folder that is in the system path.
This is my code:
# Create the database connection
connection = sqlite3.connect('database.db')
# Export data to database
data.to_sql('database', con=connection, if_exists='replace', index=False)
# Add a new table column to store the geometry data
cursor = connection.cursor()
cursor.enable_load_extension(True)
cursor.load_extension("mod_spatialite")
cursor.execute("SELECT InitSpatialMetaData(1);")
cursor.execute(
"""
SELECT AddGeometryColumn('database', 'wkb_geometry', 4326, 'POLYGON', 2);
"""
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在 WayScript 终端中
pip install
,然后输入pip freeze >
requirements.txt 进入终端。这是指向 WayScript 文档的链接此事。
You need to
pip install <package>
in the WayScript terminal and then inputpip freeze > requirements.txt
into the terminal.Here is a link to WayScript's docs on the matter.