NetTopologySuite / NetTopologySuite.IO.Esri

BSD 3-Clause "New" or "Revised" License
31 stars 16 forks source link

Import a shape with 0-decimal column, but with decimal anyway #49

Open martin-datalogisk opened 1 week ago

martin-datalogisk commented 1 week ago

Hey Thanks for a greate nuget package I hav a problem importing this file, well ussual when a file can't be read it's a file not following standard 100% There is only 1 colunm in dbf file. A number colunm with 0-decimal, but anyway lots of rows has decimals. So doing the import it crashes at StringToNumber metode in class DbfNumericInt64Field I downloaded the source code and made this small change, that removes "illegal" decimals, this works fine for me. Hopefully this or a likely change can be release soon.

Regards

Martin

    /// <inheritdoc/>
    protected override long StringToNumber(string s)
    {
        int idx = s.IndexOf(".");
        if (idx >= 0)
            s = s.Remove(idx, s.Length - idx);
        return long.Parse(s, CultureInfo.InvariantCulture);
    }

221-1_28.03.202411-16.zip

KubaSzostak commented 1 week ago

Hi @martin-datalogisk. The file you provided has multiple issues. First, it has invalid geometries. It can be fixed by using the GeometryBuilderMode.FixInvalidShapes mode:

var options = new ShapefileReaderOptions
{
    GeometryBuilderMode = GeometryBuilderMode.FixInvalidShapes
};

It has one DOSIS field which is defined as Numeric with Precision=0 and Length=32. In first place Precision=0 indicates that it is an integer field. However, the data stored in the DBF file includes floating-point numbers as well, as shown in the image below.

image

Moreover, the Length=32 setting does not conform to either the dBASE or Esri specifications, which allow a maximum of 20 digits for numeric values.

While the provided file doesn't follow the Shapefile specification, it doesn't prevent our library from reading data from the invalid file. I will make adjustments to ensure it can be processed by the library.

martin-datalogisk commented 1 week ago

Hi @KubaSzostak Yes, it's a very no-standard fileset, I already use the option FixInvalidshapes, but then also this decimal issue ahrr. Thanks for take a look at it :-)

Martin