NetTopologySuite / NetTopologySuite.IO.ShapeFile

The ShapeFile IO module for NTS.
35 stars 25 forks source link

DbaseFileHeader.DetectEncoding method should be modified #73

Closed rgbcmy closed 3 years ago

rgbcmy commented 3 years ago

this method reference http://downloads.esri.com/support/documentation/pad_/ArcPad_RefGuide_1105.pdf;

image The pdf first is Check for DBF LDID,but the method first is Check for CPG ;and the method ShapefileDataReader(string filename, GeometryFactory geometryFactory, Encoding encoding) if the parameter encoding is null and .CPG file not exist, ShapefileStreamProviderRegistry.DataEncodingStream also have default,so LDID Not available at all。I think it should be modified to

private static Encoding DetectEncoding(byte ldid, IStreamProvider cpgFile)
        {

            if (DbaseEncodingUtility.LdidToEncoding.TryGetValue(ldid, out Encoding value))
            {
                return value;
            }
           if (cpgFile != null)
            {
                return GetEncoding(cpgFile);
            }
            return DefaultEncoding;
        }
DGuidi commented 3 years ago

Actually, I have mixed feelings about taking ArcPad specifications as a general reference: do you know any info about other software that handles cpg in the same way? In any case, my two cents: cpg is an optional file, so info in cpg should override the "default" info in header; so, to me the current code it's ok. 5gc412

rgbcmy commented 3 years ago

I mean if cpg file not exist ShapefileStreamProviderRegistry.DataEncodingStream has a default so it never to read dbf Ldid

DGuidi commented 3 years ago

ShapefileStreamProviderRegistry.DataEncodingStream has a default so it never to read dbf Ldid

This comment does not make sense to me, sorry. Anyway, you can see the actual code here and it follows the ArcPad specifications, so forgot my "mixed feelings"... I will close this issue, if you think the problem still persist feel free to re-open the issue, but please be specific about the problem, the expected behavior and possibly add some code and data that reproduces the problem.