DbaseReader Encoding And Some Question With SharpMap

Topics: Data Access, General Topics, Web Controls
Apr 25, 2007 at 4:35 AM
Edited Apr 25, 2007 at 5:08 PM
Hi.
I'm new in GIS and I start it with SharpMap (ChangeSet 21021).
I have problem with Thai language when read label from shape files
DbaseReader can not detect encoding correctly ;
At DbaseReader.cs function GetDbaseLanguageDriver(byte dbasecode)
dbasecode is always 0 and it return UTF7. Is that correct?;
I not sure with my shape file encoding is, and now I solve ploblem with
import my shape files to PostGIS with UTF8 encoding
and then use pgsql2shp export the shape file to make sure it is UTF8 encoding.

My label have the same problem then I change a line of code in DBaseReader.cs

private void ParseDbfHeader(string filename)
{
if (br.ReadByte() != 0x03)
throw new NotSupportedException("Unsupported DBF Type");
_lastUpdate = new DateTime((int)br.ReadByte() + 1900, (int)br.ReadByte(), (int)br.ReadByte()); //Read the last update date
_NumberOfRecords = br.ReadInt32(); // read number of records.
_HeaderLength = br.ReadInt16(); // read length of header structure.
_RecordLength = br.ReadInt16(); // read length of a record
fs.Seek(29, SeekOrigin.Begin); //Seek to encoding flag
_FileEncoding = System.Text.Encoding.UTF8;//GetDbaseLanguageDriver(br.ReadByte()); //Read and parse Language driver
fs.Seek(32, SeekOrigin.Begin); //Move past the reserved bytes
.
.
.
}
Now I get the correct label.

Can anyone suggest me a little question?
1.Can I change DbaseReader Encoding through LabelLayer? I want to use code like this (For apply to each layer different):
SharpMap.Layers.LabelLayer layKhetLabel = new SharpMap.Layers.LabelLayer("Khet labels");
layKhetLabel.DataSource = layKhet.DataSource;
layKhetLabel.LabelColumn = "NAME";
layKhetLabel.DBaseEncoding = System.Text.Encoding.UTF8;

2.Can I use PostGIS as DataSource? How? What advantage or disadvantage for this?

3.I interest with AJAX Map and I have some problem (With IE, Firefox not found this problem) with sometime map is not moved when I zoom sometime I got over flow error when I zoom more and more. Is this a bug? How to solve this problem?

4.I develop asp.net with SharpMap on Windows but server is Linux (Fedora Core 6). Can I compile SharpMap to run with Mono? How to set environment for test this?

Sorry, I weak in English.
Regard
ThaiGIS
Thailand.
Coordinator
Jun 20, 2007 at 12:40 AM
Edited Jun 20, 2007 at 1:13 AM
Hey ThaiGIS,

1) Unfortunately, we can't make it UTF-8 encoding, without breaking other encodings. DBase III only supports ANSI or vendor-specific encoding, not Unicode, so most readers wouldn't know how to handle a UTF-8 encoding. While it would work in instances of ANSI or when tools expect it, it would break for others.

The right thing to do is to handle the encoding code page. I only have the SharpMap v2.0 code handy, so this might look different, but it would appear similar:

fs.Seek(29, SeekOrigin.Begin); //Seek to encoding flag
_fileEncoding = System.Text.Encoding.GetEncoding(br.ReadByte());
... 
columns[i].ColumnName = _fileEncoding.GetString(reader.ReadBytes(11)).Replace("\0", "").Trim();

The problem, which you might be hitting, is that the LDID field is empty. (Could you confirm this?) We default to ANSI in the v0.9 branch currently. Setting it via a layer property is a compelling suggestion. I'll make a work item and see where it gets. (Here it is: Allow the code page of a provider to be set when it is missing)

Here are answers to your remaining questions:

2) Yes. See Add a PostGIS layer. PostGIS is good, fast and relatively mature. It's a bit of a pain to administer, though. Worse than alternatives? Your call.
3) This is a bug, apparently. I think Overflow exception when zooming covers this.
4) Mono was running at one point (only SharpMap, not SharpMap.UI), but I know nothing of it's current state. Please try it out and report back!
Coordinator
Jun 20, 2007 at 1:07 AM
Oops -

I forgot there was a mapping between code pages in Windows and the ones stored in the dBase file. The DbaseEncodingRegistry in the v2.0 branch deals with this mapping. Both Thai (OEM) and Thai (Windows/MS-DOS) are present in that code, so v2.0 should handle the encoding correctly.

However, it still deals with a missing code page by guessing ASCII. That could be parameterized. On second thought, making it a parameter of the data provider rather than the layer makes more sense.
Jun 20, 2007 at 1:26 PM
Edited Jun 20, 2007 at 1:52 PM
Thanks for your reply. I'll work around the latest version.
SharpMap on mono is work only SharpMap, not SharpMap.UI.
Mono is don't have System.Web.UI.Design.ContainerControlDesigner namespace.
Coordinator
Jun 20, 2007 at 3:00 PM
In v2.0 the rendering and presentation is split out so that it would be a fairly straightforward matter for someone to write a Mono-based renderer and map presenter.
Developer
Dec 7, 2007 at 1:40 PM

codekaizen wrote:
3) This is a bug, apparently. I think Overflow exception when zooming covers this.

I'm playing a little bit with Ajax demo and the problem looks different that the one you talk.
The error is only with IE and the ajax component simply block itself, without any error message.
I'm trying to take a look deeper and see what happens.