about import shape file

Topics: Developer Forum
May 5, 2009 at 8:00 AM
hi,i deploy database without any problems,but when i use msscmd.exe to import, i meet a mistake :(.
so i trace the exception and found it came from the nettopologysuite.the definite class is GisSharpBlog.NetTopologySuite.IO.ShapefileDataReader.
when the fields of .dbf file are all english, it works fine,but error occurs when the field  is  chinese.
from the link you can get my  test .shp file.
thanks a lot for any help! :)

May 5, 2009 at 9:15 AM
Hi zabcd117, Not sure but you may be able to solve it by using a modified version of NetTopologySuite. You will need to pull the source, modify, build and then reference in the MsSqlSpatial project. (You may need to get an old version of the NTS source though).  
At a guess you need to change the file DbaseFileReader.cs line 35 (currently - it may be different in the older source) 
_dbfStream = new BinaryReader(stream, Encoding.Default);
change to:
 _dbfStream = new BinaryReader(stream, Encoding.Unicode);

this is not ideal as it will then break non unicode shapefiles but it may help you over a bump.. jd
May 14, 2009 at 3:04 AM

hi, johndiss.thanks for your quick reply.i follow your suggestion,but error still occurs. then i compare the source code of  SharpMap and NetTopologySuite,  until i got the problem. in the nested class DbaseFileEnumerator in DbaseFileReader.cs, the Read() method cause that problem. when the tempFieldType variable is 'C',  it readChars from binayreader and transfer it  into  a string without change encoding, i change from original code to:

case 'C':   // character record.
         tempObject = Encoding.Default.GetString(_dbfStream.ReadBytes(tempFieldLength)).Replace("\0", "").Trim(); //default encoding is "gb2312"

then it works. but as you said, non "gb2312" encoding .dbf file will be stuned.maybe  i should add some control of the encoding in the class latter.

last, thanks again :)