Hello,
I am new in the GeoTools user group. I try to read my shapefile using
GeoTools, but the returned Chinese characters from attribute have encoding
problem: all the attribute strings are encoded into ISO-8859-1 not the right
local encoding. I tracked into the source codes, and found that the encoding
is set to "ISO-8859-1" in DbaseFileReader.java:
205 charBuffer = CharBuffer.*allocate*(header.getRecordLength() - 1);
206 Charset chars = Charset.*forName*("ISO-8859-1");
207 decoder = chars.newDecoder();
However, the default encoding can not be changed, because it may lead to
wrong record length (each Chinese character occupy two bytes). Finally, I
added some codes to decode the string type attribute from ISO-8859-1 to
local encoding, and it works.
443 // set up the new indexes for start and end
444 charBuffer.position(start).limit(end + 1);
445 String s = charBuffer.toString();
446
448 // decode string from ISO-8859-1 to default encoding
449 s = *new* String(s.getBytes("ISO-8859-1"));
450
451 // this resets the limit...
452 charBuffer.clear();
453 object = s;
454 *break*;
Does anyone else have better way to solve the encoding problem of shapefile?
I have no idea about how to commit the change to code repository, and
any suggestion
will be appreciated?
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel