postgresql - ogr2ogr 和 Postgis/PostgreSQL 数据库的编码问题

标签 postgresql character-encoding gis postgis gdal

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

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

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

我收到的错误是:

ERROR 1: ALTER TABLE "soer_vd" ADD COLUMN "målsætning" CHAR(10)
ERROR: invalid byte sequence for encoding "UTF8": 0xe56c73
HINT: This error can also happen if the byte sequence does not match the 
encoding expected by the server, which is controlled by "client_encoding".

ERROR 1: ALTER TABLE "soer_vd" ADD COLUMN "påvirkning" CHAR(10)
ERROR: invalid byte sequence for encoding "UTF8": 0xe57669
HINT: This error can also happen if the byte sequence does not match the 
encoding expected by the server, which is controlled by "client_encoding".

ERROR 1: INSERT command for new feature failed.
ERROR: invalid byte sequence for encoding "UTF8": 0xf8
HINT: This error can also happen if the byte sequence does not match the 
encoding expected by the server, which is controlled by "client_encoding".

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

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

亲切的问候,卡斯珀

最佳答案

Magnus 是对的,我将在这里讨论解决方案。

我看过通知PostgreSQL字符编码的选项,options=’-c client_encoding=xxx’,用了很多地方,但好像没什么作用。如果有人知道这部分是如何工作的,请随时详细说明。

Magnus 建议将环境变量 PGCLIENTENCODING 设置为 LATIN1。根据我查询的邮件列表,这可以通过修改对 ogr2ogr 的调用来完成:

ogr2ogr -–config PGCLIENTENCODING LATIN1 –f PostgreSQL 
PG:”host=hostname user=username dbname=databasename password=password” inputfile

这对我没有任何作用。对我有用的是,在调用 ogr2ogr 之前:

SET PGCLIENTENCODING=LATIN1

很高兴听到有经验的用户提供更多详细信息,我希望它可以帮助其他人:)

关于postgresql - ogr2ogr 和 Postgis/PostgreSQL 数据库的编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1377662/

相关文章:

php - £ 符号编码 - 帮助!

发送 http post/put 时的 Android 默认字符集 - 特殊字符问题

gis - 如何使用 UMN map 服务器在图层中获得透明背景?

python - GeoDjango:查找半径内的对象

python - 列出具有几何类型的 map 图层名称

ruby-on-rails - rails 和 postgresql 中的 Date.today 更新问题

database - Apache Spark 的主键

带下划线或句点的 SQL id 列

使用 Heroku dataclips 将 PostgreSQL 数据库导出到 csv 时出现 SQL 语法错误

php - Mysql/Phpmyadmin 中的德语元音变音