sql-server - 从 Pandas 转换为 SQL Server 地理
问题描述
从 CSV 文件中,我需要将经纬度坐标(浮点数)作为几何图形上传到 SQL Server。如何通过 Pandas 的 to_sql() 方法(通过 sqlalchemy)执行此操作?
解决方案
SQL Server 支持从众所周知的文本 (WKT) 格式的字符串到地理的隐式转换。因此,您应该能够如此简单地在数据框中添加一列,其中包含表单中的数据POINT(LON LAT)
,例如
'POINT(-122.34900 47.65100)'
例如
drop table if exists #foo
go
create table #foo(id int, g geography)
insert into #foo(id, g) values (1,'POINT(-122.34900 47.65100)')
select *, g.STSrid
from #foo
推荐阅读
- node.js - 如何修复 Node 中的“解析错误:意外令牌”?
- angular - 使用值重置的 Angular 6 表单不会更改表单脏状态
- java - 如何在java中取消时间安排的cron作业?
- matlab - 如何在 Matlab 中创建一个矩阵,每个条目都是双变量函数的输出
- firebase - 云函数错误:函数不是有效的特性。必须是数据库、firestore、函数、托管、存储之一
- node.js - 自定义 npm 脚本如何在我的代码中工作?
- python - 这是在读取模式下读取文件的正确方法
- swift - 如何让 NSTextField 包含在可变行高表中
- google-sheets-formula - 如何总结最长的连续正/负值
- python - 如何在两个数字之间进行输入