我尝试按照本指南使用 ogr2ogr 命令将一些形状导入 SQL https://alastaira.wordpress.com/ogr2ogr-patterns-for-sql-server/
我使用这个命令:
ogr2ogr -overwrite -f MSSQLSpatial [connection string] [shapefile] -nln "shape3" -nlt GEOMETRY
并收到此错误:
ERROR 1: INSERT command for new feature failed. [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'dbo.shape3'. ERROR 1: Unable to write feature 0 from layer tl_2010_06_zcta510. ERROR 1: Terminating translation prematurely after failed translation of layer tl_2010_06_zcta510 (use -skipfailures to skip errors)
该命令不会创建表并且插入失败。
我尝试先创建表并使用命令在其上插入:
ogr2ogr -f "MSSQLSpatial" [connection string] [shapefile] -a_srs "ESPG:4269" -lco "GEOM_TYPE=geography" -lco "GEOM_NAME=area" -nln "shapes3"
它工作正常,除非它不加载 GEOGRAPHY 列(区域),它仍然为 NULL。
我使用指南中提供的文件,连接字符串中的用户是管理员,所以这不是权限问题。
谢谢大家。
最佳答案
解决了在命令中添加 -lco UPLOAD_GEOM_FORMAT=wkt 的问题,它与一些几何格式有关。
UPLOAD_GEOM_FORMAT: (From GDAL 2.0.0) Specify the geometry format (wkb or wkt) when creating or modifying features. The default is wkb. https://www.gdal.org/drv_mssqlspatial.html
关于sql-server - ogr2ogr 不创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52259696/