2

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.

4
  • Is it possible to share the address of the database ?
    – Leasye
    Aug 8 '14 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. Aug 8 '14 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.
    – LR1234567
    Aug 9 '14 at 0:55
  • When all else fails..Address fields tend to be the culprits I find....make sure its text...Hyphenated e, etc...
    – user43223
    Dec 21 '14 at 23:43
3

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

1

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
1
  • Already try that. Didn't work either. I get the same first message I mentioned, to try LATIN1. :( Aug 8 '14 at 21:19
1

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.

2
  • 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? Aug 9 '14 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; Aug 11 '14 at 8:16
0

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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