Loading shapefile to PostGis: ERROR: 22021: invalid byte sequence for encoding "UTF8": 0xf320752e

Topics: General Topics
Sep 27, 2006 at 9:15 AM

I've got the following error when I try to load my hungarian language specific shp file into PostGis:

ERROR: 22021: invalid byte sequence for encoding "UTF8": 0xf320752e

The Shape File contains hungarian letters and I'm sure that this is the source of the problem.

Does anyone have any idea how can i solve this problem?

It's a layer with street names in hungarian language and I need those characters.

I use Morten's tool: Shape2Pgsql to load data into PostGis.

Otherwise everything is OK if the shapefile doesn't contain any hungarian letter...

Thanks if you can help!

Sep 27, 2006 at 3:19 PM

Your problem is the standard encoding of the dbf reader,
which is UTF7.

if you would like to test please hard code the encoding
in "Form1.cs" line 34 with:
shp.Encoding = Encoding.UTF8;

please report your results, if it was successful.

Sep 27, 2006 at 8:55 PM

It's solved the prolem, but when I checked the data in tha table I saw that the hungarian letters are all wrong :(

And I tried the shp2pgsql.exe which is included in Postgresql, and it worked. Unfortunately another problem came up:

This is a text layer, and I tried to show the labels whit the LabelLayer class with SharpMap.

Then I check the table, which is the following:

REATE TABLE utcanevek_text
gid serial NOT NULL,
text_angle float8,
text_size float8,
textstring varchar(254),
blank varchar(1),
the_geom geometry,
CONSTRAINT utcanevektextpkey PRIMARY KEY (gid),
CONSTRAINT enforcedimsthegeom CHECK (ndims(thegeom) = 2),
CONSTRAINT enforcegeotypethegeom CHECK (geometrytype(thegeom) = 'POINT'::text OR the_geom IS NULL),
CONSTRAINT enforcesridthegeom CHECK (srid(thegeom) = -1)
ALTER TABLE utcanevek_text OWNER TO postgres;

As you can see there is a text_size column which defines the size of the text. But there isn't any FontSizeColumn or a kind of property inside the LabelLayer class.

Is it possible to show every text whit its own font size which is in the text_size column?

Thanks for the help!

Oct 13, 2006 at 4:37 AM
Set the input encoding when you import the data using the -W flag of shp2pgsql1. shp2pgsql will automatically convert it to UTF8. You (might) also need to set the encoding2 for the postgresql database to UTF8 in order to get your text stored properly.

Then with all the data in UTF8 (stored by PostGIS) you can retrieve it using the Encoding.UTF8 setting.

1 http://postgis.refractions.net/docs/ch04.html#id2523645
2 http://www.postgresql.org/docs/8.1/static/sql-createdatabase.html