如何将 GeoDataFrame 插入 SQLite

发布于 2025-01-15 03:13:29 字数 953 浏览 1 评论 0原文

尝试将带有几何变量的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好久不见√ 2025-01-22 03:13:29

您需要在 WayScript 终端中 pip install ,然后输入 pip freeze > requirements.txt 进入终端。

这是指向 WayScript 文档的链接此事

You need to pip install <package> in the WayScript terminal and then input pip freeze > requirements.txt into the terminal.

Here is a link to WayScript's docs on the matter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文