Esempio n. 1
0
        public BaseFile(Iso8211Reader reader)
        {
            //Current this works because we know the two records are special
            DataSetGeneralInformationRecord = reader.ReadDataRecord();
            var dssi = DataSetGeneralInformationRecord.Fields.GetFieldByTag("DSSI");

            if (dssi != null)
            {
                vectorDataStructure          = (VectorDataStructure)dssi.GetUInt32("DSTR");
                ATTFLexicalLevel             = (LexicalLevel)dssi.GetUInt32("AALL");
                NATFLexicalLevel             = (LexicalLevel)dssi.GetUInt32("NALL");
                numberOfMetaRecords          = dssi.GetUInt32("NOMR");
                numberOfCartographicRecords  = dssi.GetUInt32("NOCR");
                numberOfGeoRecords           = dssi.GetUInt32("NOGR");
                numberOfCollectionRecords    = dssi.GetUInt32("NOLR");
                numberOfIsolatedNodeRecords  = dssi.GetUInt32("NOIN");
                numberOfConnectedNodeRecords = dssi.GetUInt32("NOCN");
                numberOfEdgeRecords          = dssi.GetUInt32("NOED");
                numberOfFaceRecords          = dssi.GetUInt32("NOFA");
            }

            DataSetGeographicReferenceRecord = reader.ReadDataRecord();
            var dspm = DataSetGeographicReferenceRecord.Fields.GetFieldByTag("DSPM");

            if (dspm != null)
            {
                horizontalGeodeticDatum        = dspm.GetUInt32("HDAT");
                verticalDatum                  = dspm.GetUInt32("VDAT");
                soundingDatum                  = dspm.GetUInt32("SDAT");
                compilationScaleOfData         = dspm.GetUInt32("CSCL");
                unitsOfDepthMeasurement        = dspm.GetUInt32("DUNI");
                unitsOfHeightMeasurement       = dspm.GetUInt32("HUNI");
                unitsOfPositionalAccuracy      = dspm.GetUInt32("PUNI");
                coordinateUnits                = (CoordinateUnits)dspm.GetUInt32("COUN");
                coordinateMultiplicationFactor = dspm.GetUInt32("COMF");
                soundingMultiplicationFactor   = dspm.GetUInt32("SOMF");
                // COMT
            }

            // DSPR Dataset projection
            // DSRC Dataset registration control
            // DSHT Dataset history
            // DSAC Dataset accuracy
            // CATD catalogue directory
            // CATX Catalogue cross reference

            List <DataRecord> fr = new List <DataRecord>();
            List <DataRecord> vr = new List <DataRecord>();

            var nextRec = reader.ReadDataRecord();

            while (nextRec != null)
            {
                if (nextRec.Fields.FindFieldByTag("VRID"))
                {
                    vr.Add(nextRec);
                }
                else
                {
                    if (nextRec.Fields.FindFieldByTag("FRID"))
                    {
                        fr.Add(nextRec);
                    }
                }
                nextRec = reader.ReadDataRecord();
            }

            FeatureRecords = fr;
            VectorRecords  = vr;
        }
Esempio n. 2
0
        public static Dictionary <uint, string> GetAttributes(DataField field, BaseFile baseFile)
        {
            int currentIndex = 0;

            if (field.Tag == "ATTF" || field.Tag == "ATTV" || field.Tag == "NATF")
            {
                LexicalLevel lexicalLevel        = field.Tag == "ATTF" || field.Tag == "ATTV" ? baseFile.ATTFLexicalLevel : baseFile.NATFLexicalLevel;
                Dictionary <uint, string> values = new Dictionary <uint, string>();
                uint key = 0;
                while (currentIndex < field.Bytes.Length && field.Bytes[currentIndex] != DataField.FieldTerminator)
                {
                    foreach (SubFieldDefinition subFieldDefinition in field.FieldDescription.SubFieldDefinitions)
                    {
                        if (subFieldDefinition.FormatTypeCode == FormatTypeCode.CharacterData)
                        {
                            var sb = new StringBuilder();
                            if (subFieldDefinition.SubFieldWidth == 0)
                            {
                                if (lexicalLevel == LexicalLevel.ISO10646)
                                {
                                    while (currentIndex < field.Bytes.Length && field.Bytes[currentIndex] != DataField.UnitTerminator)
                                    {
                                        sb.Append(BitConverter.ToChar(field.Bytes, currentIndex));
                                        currentIndex += 2;
                                    }
                                }
                                else if (lexicalLevel == LexicalLevel.ISO8859)
                                {
                                    System.Text.Encoding iso8859 = System.Text.Encoding.GetEncoding("iso-8859-1");
                                    int startIndex = currentIndex;
                                    while (currentIndex < field.Bytes.Length && field.Bytes[currentIndex] != DataField.UnitTerminator)
                                    {
                                        currentIndex++;
                                    }
                                    string val = iso8859.GetString(field.Bytes, startIndex, currentIndex - startIndex);
                                    //string val2 = Encoding.GetEncoding(1252).GetString(field.Bytes, startIndex, currentIndex - startIndex);
                                    sb.Append(val);
                                    currentIndex++;
                                }
                                else
                                {
                                    while (currentIndex < field.Bytes.Length && field.Bytes[currentIndex] != DataField.UnitTerminator)
                                    {
                                        sb.Append((char)field.Bytes[currentIndex]);
                                        currentIndex++;
                                    }
                                    //Consume the Terminator
                                    currentIndex++;
                                }
                            }
                            else
                            {
                                for (int i = 0; i < subFieldDefinition.SubFieldWidth; i++)
                                {
                                    sb.Append((char)field.Bytes[currentIndex]);
                                    currentIndex++;
                                }
                            }
                            var s = sb.ToString();
                            if (!field.SubFields.ContainsKey(subFieldDefinition.Tag))
                            {
                                field.SubFields.Add(subFieldDefinition.Tag, s);
                            }
                            if (!values.ContainsKey(key))
                            {
                                values.Add(key, s);
                            }
                            else
                            {
                                // Attributes Error: declared key is missing
                            }
                        }
                        else if (subFieldDefinition.FormatTypeCode == FormatTypeCode.LsofBinaryForm)
                        {
                            switch (subFieldDefinition.BinaryFormSubType)
                            {
                            case ExtendedBinaryForm.IntegerSigned:
                                if (subFieldDefinition.BinaryFormPrecision != 4)
                                {
                                    throw new NotImplementedException("Only handle Signed Ints of 4 bytes");
                                }
                                int signedValue = 0;
                                for (int i = 0; i < subFieldDefinition.BinaryFormPrecision; i++)
                                {
                                    int tempVal = field.Bytes[currentIndex++];
                                    for (int j = 0; j < i; j++)
                                    {
                                        tempVal = tempVal << 8;
                                    }
                                    signedValue += tempVal;
                                }
                                field.SubFields.Add(subFieldDefinition.Tag, signedValue);
                                break;

                            case ExtendedBinaryForm.IntegerUnsigned:
                                if (subFieldDefinition.BinaryFormPrecision > 4)
                                {
                                    throw new NotImplementedException("Only handle unsigned Ints 4 bytes or less");
                                }

                                UInt32 unsignedValue = 0;
                                for (int i = 0; i < subFieldDefinition.BinaryFormPrecision; i++)
                                {
                                    UInt32 tempVal = field.Bytes[currentIndex++];
                                    for (int j = 0; j < i; j++)
                                    {
                                        tempVal = tempVal << 8;
                                    }
                                    unsignedValue += tempVal;
                                }

                                if (!field.SubFields.ContainsKey(subFieldDefinition.Tag))
                                {
                                    field.SubFields.Add(subFieldDefinition.Tag, unsignedValue);
                                }
                                key = unsignedValue;
                                break;

                            default:
                                throw new NotImplementedException("Unhandled LsofBinaryForm");
                            }
                        }
                        else if (subFieldDefinition.FormatTypeCode == FormatTypeCode.ExplicitPoint)
                        {
                            if (subFieldDefinition.SubFieldWidth == 0)
                            {
                                throw new Exception("Expected a subfield width for Explicit Point Type");
                            }

                            var tempSb = new StringBuilder();

                            for (int i = 0; i < subFieldDefinition.SubFieldWidth; i++)
                            {
                                tempSb.Append((char)field.Bytes[currentIndex]);
                                currentIndex++;
                            }

                            double value = 0;
                            value = Double.Parse(tempSb.ToString(), CultureInfo.InvariantCulture);

                            field.SubFields.Add(subFieldDefinition.Tag, value);
                        }
                        else if (subFieldDefinition.FormatTypeCode == FormatTypeCode.BitStringData)
                        {
                            if (subFieldDefinition.SubFieldWidth == 0)
                            {
                                throw new Exception("Expected a subfield width for Bit String Data");
                            }
                            //divide by 8 and round up
                            int    bytesToRead  = (subFieldDefinition.SubFieldWidth + (8 - 1)) / 8;
                            byte[] newByteArray = new byte[bytesToRead];
                            for (int i = 0; i < bytesToRead; i++)
                            {
                                newByteArray[i] = field.Bytes[currentIndex];
                                currentIndex++;
                            }
                            field.SubFields.Add(subFieldDefinition.Tag, newByteArray);
                        }
                        else
                        {
                            throw new Exception("Unhandled subField type :" + subFieldDefinition.FormatTypeCode);
                        }

                        //if (field.Bytes[field.Bytes.Length - 1] != DataField.FieldTerminator) throw new Exception("Expected Field Terminator");
                    }
                }
                return(values);
            }
            return(null);
        }