[GIS] ogr2ogr: encoding issues when importing from Oracle Spatial to PostGIS

encodingogr2ogroracle-spatialpostgispostgresql

I'm trying to import some spatial tables from Oracle Spatial to PostGIS using ogr2ogr, but I can't figure out why the special characters on the attribute tables get messed up while I'm doing it.

My environment is:

  • Oracle Database 10g / Oracle Spatial 10.2.0.4 NLS_CHARACTERSET WE8ISO8859P1, NLS_LANGUAGE AMERICAN
  • PostgreSQL 9.5 / PostGIS 2.2 installed on Windows 8.1 Pro PT-BR. Database encoding is UTF8, character type IS Portuguese_Brazil.1252

My ogr2ogr command is:

ogr2ogr -progress -f "PostgreSQL" -nln schema.table -skipfailures -overwrite -lco FID=ID_COLUMN -lco GEOMETRY_NAME=geom PG:"host=localhost user=postgres password=yadayada dbname=database" OCI:username/password@server:port/database:schema.table

The table is imported perfectly, except for the special characters like "~". All the "ã" are replaced by "?", for example. I've already tried to use SET PGCLIENT ENCODING=LATIN 1 and SET PGCLIENTENCODING=WIN1252 without success.

I don't know if it helps, but if I try to open the tables directly from Oracle into QGIS the characters are displayed properly.

Best Answer

Try this Oracle environment variable:

NLS_LANG=AMERICAN_AMERICA.UTF8