首页 > 解决方案 > 从 Pandas 转换为 SQL Server 地理

问题描述

从 CSV 文件中,我需要将经纬度坐标(浮点数)作为几何图形上传到 SQL Server。如何通过 Pandas 的 to_sql() 方法(通过 sqlalchemy)执行此操作?

标签: sql-serverpandassqlalchemygeospatial

解决方案


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 

推荐阅读