8

在我们的组织中,我们处理不同文件格式的 GIS 内容。我需要将这些文件放入 PostGIS 数据库,这是使用 ogr2ogr 完成的。问题是,数据库是 UTF8 编码的,文件可能有不同的编码。

我找到了有关如何通过向 org2ogr 添加选项参数来指定编码的描述,但显然它没有效果。

ogr2ogr -f PostgreSQL PG:"host=localhost user=username dbname=dbname \
password=password options='-c client_encoding=latin1'" sourcefile;

我收到的错误是:

错误 1:更改表“soer_vd”添加列“målsætning”CHAR(10)
错误:编码“UTF8”的字节序列无效:0xe56c73
提示:如果字节序列与
服务器期望的编码,由“client_encoding”控制。

错误 1:ALTER TABLE "soer_vd" 添加列 "påvirkning" CHAR(10)
错误:编码“UTF8”的字节序列无效:0xe57669
提示:如果字节序列与
服务器期望的编码,由“client_encoding”控制。

错误 1:新功能的 INSERT 命令失败。
错误:编码“UTF8”的字节序列无效:0xf8
提示:如果字节序列与
服务器期望的编码,由“client_encoding”控制。

目前,我的源文件是一个 Shape 文件,我很确定它是 Latin1 编码的。

我在这里做错了什么,你能帮帮我吗?

亲切的问候,卡斯帕

4

7 回答 7

12
于 2009-09-08T09:04:25.770 回答
11

听起来确实会将客户端编码设置为 LATIN1。你到底得到了什么错误?

万一 ogr2ogr 没有正确传递它,您也可以尝试将环境变量设置PGCLIENTENCODINGlatin1.

我建议您仔细检查它们实际上是 LATIN1。假设它在文件中实际上是一致的,简单地file在它上面运行会给你一个好主意。您也可以尝试发送它iconv以将其转换为 LATIN1 或 UTF8。

于 2009-09-05T23:17:02.890 回答
8

You need to write your command line like this :

PGCLIENTENCODING=LATIN1 ogr2ogr -f PostgreSQL PG:"dbname=...
于 2012-03-15T10:37:56.617 回答
7

Currently, OGR from GDAL does not perform any recoding of character data during translation between vector formats. The team has prepared RFC 23.1: Unicode support in OGR document which discusses support of recoding for OGR drivers. The RFC 23 was adopted and the core functionality was already released in GDAL 1.6.0. However, most of OGR drivers have not been updated, including Shapefile driver.

For the time being, I would describe OGR as encoding agnostic and ignorant. It means, OGR does take what it gets and sends it out without any processing. OGR uses char type to manipulate textual data. This is fine to handle multi-byte encoded strings (like UTF-8) - it's just a plain stream of bytes stored as array of char elements.

It is advised that developers of OGR drivers should return UTF-8 encoded strings of attribute values, however this rule has not been widely adopted across OGR drivers, thus making this functionality not end-user ready yet.

于 2010-01-22T16:12:45.457 回答
3

On windows a command is

SET PGCLIENTENCODING=LATIN1

On linux

export PGCLIENTENCODING=LATIN1

or

PGCLIENTENCODING=LATIN1

Moreover this discussion help me:

https://gis.stackexchange.com/questions/218443/ogr2ogr-encoding-on-windows-using-os4geo-shell-with-census-data

On windows

SET PGCLIENTENCODING=LATIN1 ogr2ogr...

do not give me any error, but ogr2ogr do not works...I need to change the system variable (e.g. System--> Advanced system settings--> Environment variables -->New system variable) reboot the system and then run

ogr2ogr...

于 2019-01-09T15:43:57.100 回答
1

I solved this problem using this command:

pg_restore --host localhost --port 5432 --username postgres --dbname {DBNAME} --schema public --verbose "{FILE_PATH to import}"

I don't know if this is the right solution, but it worked for me.

于 2012-04-10T07:18:22.987 回答
0

For some reason, I dont know why, I could not import tables with ÅÄÖ in them to the public schema.

When I created a new schema I could import the tables to the new schema.

于 2021-08-10T09:34:34.080 回答