I'm having some trouble when trying to import an shapefile of the Sao Paulo Brazil's state (I downloaded it from the web and I'm using the own PostGis manager to import it).

Here's an image!

enter image description here

The connection is already on.

In the "Options" menu, i had to change from "UTF8" to LATIN1, cause if I didn't, I'd get this error message: "Unable to convert field name to UTF-8 (iconv reports "Illegal byte sequence"). Current encoding is "UTF-8". Try "LATIN1" (Western European), or one of the values described at http://www.gnu.org/software/libiconv/."

I also wanted to now what is SRID and wich value should i put there.

When I changed to LATIN1, I get this other error message: "Failed in pgui_exec(): ERRO: sequência de bytes é inválida para codificação "UTF8": 0xe3 0xa7 0xe3". In english, it says the byte sequence is not valid to UTF8 codification.

I'm a bit desperate cause I've never used GIS before.

  • Is it possible to share the address of the database ?
    – Leasye
    Commented Aug 8, 2014 at 14:41
  • It's mine localhost. But I think everything is ok with the db, I mean, I enabled the geo features when I created it. Also, the encoding in the db is UTF8. If I didn't clarify it I'll share the address. Commented Aug 8, 2014 at 15:12
  • 1
    The problem is LATIN1 probably isn't right for your dataset either. You could try WIN1252. If you could provide the link that would help folks figure out your issue.
    – Regina Obe
    Commented Aug 9, 2014 at 0:55
  • When all else fails..Address fields tend to be the culprits I find....make sure its text...Hyphenated e, etc...
    – user43223
    Commented Dec 21, 2014 at 23:43

5 Answers 5


I was having a similar issue and I used the -W "latin1" option and when using and it took care of my issues:

shp2pgsql  -I -W "latin1" -s 3857 mgau2013v6_0/agebs_urbanos_2013.shp public.mexico_shape_data | psql -d osm

I found that this was a helpful reference for the syntax: http://www.bostongis.com/pgsql2shp_shp2pgsql_quickguide.bqg


For PostGIS, you can try to import with shp2pgsql.

Generic command :

shp2pgsql -s <SRID> -c -D -I <path to shapefile> <schema>.<table> | psql -d <databasename> -h <hostname> -U <username>

For example with Linux :

shp2pgsql -s 4326 -c -D -I /var/www/myshapetoimport.shp nameoftheshape | psql -d databasename -h localhost -U Postgres
  • Already try that. Didn't work either. I get the same first message I mentioned, to try LATIN1. :( Commented Aug 8, 2014 at 21:19

You have to find out the correct encoding of the shapefile. Sometimes metadata aren't helpful at all and the only way is trial and error (try all common encodings for your language in Layer Properties dialog until the attribute data displays correctly in QGIS attribute table). Then, set this encoding while importing and the driver will convert it to UTF on the fly.

  • I tried another shapefile (Entier Brazil's country) and it worked! Now I need create a table with latitude and longitude values. Any ideia on how to do that? Commented Aug 9, 2014 at 19:43
  • Use ST_X and ST_Y functions. If the coordinate system of your data isn't EPSG:4326 geographic, you will have to transform it first. This can be done in one shot: SELECT ST_X(ST_Transform(geom,4326)) AS lon, ST_Y(ST_Transform(geom,4326)) AS lat FROM your_table_name; Commented Aug 11, 2014 at 8:16

Sometimes the error isn't in the attribute value but in the attribute name. Be sure that attribute names don't have spaces or special characters.


I came across the same issue when I imported my shapefile into PostGIS because my column names have Chinese characters. I assume that caused the problem for encoding. After converting all the Chinese characters to English characters for all column names, I imported the data successfully.

  • Using QGIS's DB manager is the best solution I think, it can deal with encoding problems.
    – allenyllee
    Commented Nov 24, 2022 at 5:43

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.