This project is read-only.

Load shpfile's labelLayer wrong.

May 28, 2012 at 6:43 PM

Hi:

    When shpfile's text field use Chinese words,then labelLayer show's is wrong.

    I find the error in Dotspatial.Data.AttributeTable.cs.

    Error function:private DataRow ReadTableRow(int currentRow, long start, char[] characterContent, DataTable table)

    Because one Chinese words have 2 bytes. Line 663:Array.Copy(characterContent, start, cBuffer, 0, len); <-- wrong here.

    So I modify the codes like this:

 

/// <summary>
        /// Read a single dbase record
        /// </summary>
        /// <returns>Returns an IFeature with information appropriate for the current row in the Table</returns>
        private DataRow ReadTableRow(int currentRow, long start, char[] characterContent, DataTable table)
        {
            DataRow result = table.NewRow();
            for (int col = 0; col < table.Columns.Count; col++)
            {
                // find the length of the field.
                Field currentField = table.Columns[col] as Field;
                if (currentField == null)
                {
                    // somehow the field is not a valid Field
                    return result;
                }

                // read the data.
                char[] cBuffer = new char[currentField.Length];
                long len;
                if (start + currentField.Length > characterContent.Length)
                {
                    len = characterContent.Length - start;
                }
                else
                {
                    len = currentField.Length;
                }
                if (len < 0) return result;
                Array.Copy(characterContent, start, cBuffer, 0, len);

                ////////////////////////////////////modify here///////////////////////////////////////////////////////
                int chineseCount = 0;
                foreach (char c in cBuffer) {
                    if ((int)c > 255)
                        chineseCount++;
                }
                if (chineseCount > 0){
                    for (int i = 0; i < chineseCount; i++)
                        cBuffer[cBuffer.Length - 1 - i] = ' ';
                    start += currentField.Length - chineseCount;
                }
                else {
                    start += currentField.Length;
                }
               

                if (IsNull(cBuffer)) continue;

                result[currentField.ColumnName] = ParseColumn(currentField, currentRow, cBuffer, table);
            }

            return result;
        }

 

May 29, 2012 at 9:17 PM

Thanks for pointing this out. This might be a solution to http://dotspatial.codeplex.com/workitem/22524. Is this the best way to detect Unicode, though?

Jan 5, 2013 at 2:15 AM

It would be better to use System.Text.Encoding and other classes in the System.Text namespace to handle this. Also, DBF doesn't actually support Unicode. It supports older ANSI codepages instead. See the issue mudnug linked to for a more complete discussion.