1

I need to import some shapefiles into a database. PostGIS has successfully imported several small files.

enter image description here

But an error occurred with large files. It shows this error: "Unable to convert data value to UTF-8 (iconv reports "Invalid argument"). Current encoding is "UTF-8". Try "LATIN1" (Western European), or one of the values described at http://www.postgresql.org/docs/current/static/multibyte.html."

PostGIS recommended changing the encodings from UTF-8 to latin1. Thus, the import occurred, but Cyrillic names in the database are displayed incorrectly.

enter image description here

How can I fix this?

7
  • 1
    What is the error message? How are you importing, ogr2ogr, shp2pgsql?
    – Bera
    Commented Mar 9, 2023 at 12:46
  • Have the small files also had UTF8 encoding and does it import correctly?
    – til_b
    Commented Mar 9, 2023 at 12:46
  • This is more of a dBase encoding and internationalization issue than a PostGIS one. Details about the shapefile contents and the exact error are necessary.
    – Vince
    Commented Mar 9, 2023 at 12:46
  • 1
    Unable to convert data value to UTF-8 (iconv reports "Invalid argument"). Current encoding is "UTF-8". Try "LATIN1" (Western European), or one of the values described at postgresql.org/docs/current/static/multibyte.html
    – Sergey47
    Commented Mar 9, 2023 at 12:50
  • 1
    Small files are also in UTF-8 and cyrilic names in db are correct
    – Sergey47
    Commented Mar 9, 2023 at 12:51

1 Answer 1

1

You need to find the correct encoding of your original shapefile.

Take a look here: https://gis.stackexchange.com/a/3663/120505

It's supposed to be latin1 but some programs use *.cpg files to store encoding info, so try to look at those files.

You can also open it in ArcGIS or QGIS, check if the encoding is really correct or if this is a problem with your file, and try to resave it.

4
  • UTF 8 is written in cpg files. But dbf has a different encoding and in the case of small files, it converts to UTF 8, if a file with a large number of lines, it gives the error that it described earlier
    – Sergey47
    Commented Mar 9, 2023 at 15:26
  • Have you tried SELECT convert(name, 'LATIN1', 'UTF8') from my_table ? Commented Mar 9, 2023 at 15:43
  • If the codepage file claims UTF-8, but it isn't, the file may not be usable. It's not nice to lie to ETL software.
    – Vince
    Commented Mar 9, 2023 at 16:11
  • Vince, but it works with other files. I have converted these files to QGIS, and they are displayed correctly there
    – Sergey47
    Commented Mar 9, 2023 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.