bilaldursun1 / nettopologysuite

Automatically exported from code.google.com/p/nettopologysuite
0 stars 0 forks source link

Shapefile write fails without a meaningful exception if the feature data contains attributes with names > 11 characters #146

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

What steps will reproduce the problem?

1. Setup a feature which has one attribute named such as "Simulation name"
2. Write the feature to the shapefile using ShapefileDataWriter.Write
3. You will get an exception with "Attribute Simulation" not exists!".

What is the expected output? What do you see instead?

This is what happens: Dbase have a limit of max 10 characters in the field 
name. The header names gets truncated by Nettopology to be compliant, but when 
looking up the attributes later on - when adding values, it will not truncate 
the field names, hence it will try to find "Simulation name" which does not 
exist in the header. It would be better to detect this up front and toss an 
exception with a meaningful error message, or potentially also to give an 
option to ignore the 10 char limitation.

There is another issue here too:

The DbaseFileheader.AddCoumn seems to incorrectly truncate the names at 11 
characters instead of 10 (which is the dbase limitation, I *believe*).

           string tempFieldName = fieldName;
            if (tempFieldName == null) tempFieldName = "NoName";
            if (tempFieldName.Length > 11)
            {
                tempFieldName = tempFieldName.Substring(0, 11);
                Trace.WriteLine("FieldName " + fieldName + " is longer than 11 characters, truncating to " + tempFieldName);
            }

Original issue reported on code.google.com by tbe...@gmail.com on 19 Apr 2013 at 11:23

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1037.

Original comment by diegogu...@gmail.com on 19 Apr 2013 at 2:38

GoogleCodeExporter commented 9 years ago
fixed with changeset: 1037
to me, looks ok that when you write a shapefile with an invalid attribute name 
(i.e: name length > 11 chars) an exception is thrown.
so now the code is:

   if (tempFieldName.Length > FieldNameMaxLength)
   {
      string s = String.Format("FieldName {0} is longer than {1} characters", fieldName, FieldNameMaxLength);
      throw new ArgumentException(s);
   }

thanks for pointing this.

Original comment by diegogu...@gmail.com on 19 Apr 2013 at 2:40