从GDAL导入带有ogr2ogr的形状文件时,是否可以设置search_path?

时间:2016-07-22 21:43:23

标签: postgresql postgis gdal

我通过以下命令将形状文件导入Postgresql:

ogr2ogr PG:host=localhost dbname=someDbName user=someUserName password=somePassword shapeFile.shp -nln alternateLayerName -nlt someValidGeometry

这很有效,但在Postgresql中进入public模式。我想选择不同的架构。有没有办法单独使用ogr2ogr来实现这一目标?

man ogr2ogr架构中没有引用。我的网络搜索也没有成效。

我知道我可以做ALTER TABLE some_table set schema a_different_schema,但这意味着要为流程添加另一个步骤。

$ ogr2ogr --version GDAL 2.1.0, released 2016/04/25

2 个答案:

答案 0 :(得分:1)

我在GDAL pg driver documentation上找到一个更好的网络搜索后,可以使用ACTIVE_SCHEMA=string: Active schema.来设置创建表格的架构。

我试过这样:

ogr2ogr -f "PostgreSQL" PG:"dbname=mydb active_schema=layers" country.shp -nln test_table -nlt MULTILINESTRING

它抱怨道:

ERROR 1: PQconnectdb failed: invalid connection option "active_schema"

但是表格会被正确创建和填充。所以我猜它没关系。

答案 1 :(得分:0)

我使用lco选项找到了更好的解决方案:

ogr2ogr -f PostgreSQL "PG:host=localhost port=5432 dbname=some_db
user=postgres password=" someShapeFile.shp -nln desiredTableName
-nlt someValidGeometry -lco SCHEMA=desiredPostgresqlSchema