Beispiel #1
0
        public ProductInfo(Iso8211Reader reader)
        {
            DataSetGeneralInformationRecord = reader.ReadDataRecord();
            var dsid = DataSetGeneralInformationRecord.Fields.GetFieldByTag("DSID");

            if (dsid != null)
            {
                IntendedUsage = dsid.subFields.GetUInt32(0, "INTU");
            }
            DataSetGeographicReferenceRecord = reader.ReadDataRecord();
            var dspm = DataSetGeographicReferenceRecord.Fields.GetFieldByTag("DSPM");

            if (dspm != null)
            {
                subFieldRow                    = dspm.subFields.Values[0];
                tagLookup                      = dspm.subFields.TagIndex;
                horizontalGeodeticDatum        = subFieldRow.GetUInt32(tagLookup["HDAT"]);
                verticalDatum                  = subFieldRow.GetUInt32(tagLookup["VDAT"]);
                soundingDatum                  = subFieldRow.GetUInt32(tagLookup["SDAT"]);
                compilationScaleOfData         = subFieldRow.GetUInt32(tagLookup["CSCL"]);
                unitsOfDepthMeasurement        = subFieldRow.GetUInt32(tagLookup["DUNI"]);
                unitsOfHeightMeasurement       = subFieldRow.GetUInt32(tagLookup["HUNI"]);
                unitsOfPositionalAccuracy      = subFieldRow.GetUInt32(tagLookup["PUNI"]);
                coordinateUnits                = (CoordinateUnits)subFieldRow.GetUInt32(tagLookup["COUN"]);
                coordinateMultiplicationFactor = subFieldRow.GetUInt32(tagLookup["COMF"]);
                soundingMultiplicationFactor   = subFieldRow.GetUInt32(tagLookup["SOMF"]);
                // COMT
            }
        }
Beispiel #2
0
        //public void ReadCatalogue(System.IO.Stream stream)
        //{
        //    using (var reader = new Iso8211Reader(stream))
        //    {
        //        catalogueFile = new CatalogueFile(reader);
        //        BuildCatalogue();
        //    }
        //}

        public void ReadCatalogue(ZipArchive archive)
        {
            Stream          S57map         = null;
            ZipArchiveEntry catalogueentry = null;

            foreach (ZipArchiveEntry entry in archive.Entries)
            {
                if (entry.Name.Equals("CATALOG.031"))
                {
                    catalogueentry = entry;
                }
            }
            S57map = catalogueentry.Open();
            var count = catalogueentry.Length;

            byte[]       fileByteArray = new byte[count]; //consider re-using same byte array for next file to minimize new allocations
            MemoryStream memoryStream  = new MemoryStream(fileByteArray);

            S57map.CopyTo(memoryStream);
            memoryStream.Dispose();
            using (var reader = new Iso8211Reader(fileByteArray))
            {
                catalogueFile = new CatalogueFile(reader);
                BuildCatalogue();
                foreach (var bla in reader.tagcollector)
                {
                    Console.WriteLine(bla);
                }
            }
            S57map.Dispose();
        }
Beispiel #3
0
        public UpdateFile(Iso8211Reader reader)
        {
            //throw new NotImplementedException("UpdateFile not implemented");
            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();
            }

            UpdateFeatureRecords = fr;
            UpdateVectorRecords  = vr;
        }
Beispiel #4
0
        //public void ReadCatalogue(string RootDirectory)
        //{
        //    if (!RootDirectory.EndsWith("ENC_ROOT"))
        //    {
        //        //Console.WriteLine("Selected folder is not ENC_ROOT folder of a Volume");
        //        return;
        //    }
        //    Stream S57map = null;
        //    string[] filePaths = Directory.GetFiles(@RootDirectory, "CATALOG.031", SearchOption.AllDirectories);
        //    string catalogueentry = null;
        //    if (filePaths.Length > 1)
        //    {
        //        //Console.WriteLine("More than one Catalogue file found. Please selected MapSet root folder");
        //        return;
        //    }
        //    catalogueentry = filePaths[0];
        //    S57map = new FileStream(@catalogueentry, FileMode.Open, FileAccess.Read, FileShare.Read, 65536);
        //    using (var reader = new Iso8211Reader(S57map))
        //    {
        //        catalogueFile = new CatalogueFile(reader);
        //        BuildCatalogue();
        //    }
        //    S57map.Dispose();
        //}

        //public void ReadProductInfo(System.IO.Stream stream)
        //{
        //    using (var reader = new Iso8211Reader(stream))
        //    {
        //        productInfo = new ProductInfo(reader);
        //    }
        //}

        public void ReadProductInfo(ZipArchive archive, string MapName)
        {
            Stream S57map = null;

            foreach (ZipArchiveEntry entry in archive.Entries)
            {
                if (entry.Name.Equals(MapName))
                {
                    S57map = entry.Open();
                    int count = (int)entry.Length;
                    if (fileByteArray == null)
                    {
                        fileByteArray = new byte[count];
                    }
                    else
                    {
                        Array.Clear(fileByteArray, 0, fileByteArray.Length);
                        Array.Resize(ref fileByteArray, count);
                    }
                    MemoryStream memoryStream = new MemoryStream(fileByteArray);
                    S57map.CopyTo(memoryStream);
                    memoryStream.Dispose();

                    using (var reader = new Iso8211Reader(fileByteArray))
                    {
                        productInfo = new ProductInfo(reader);
                    }
                }
            }
        }
Beispiel #5
0
        public ProductInfo(Iso8211Reader reader)
        {
            DataSetGeneralInformationRecord = reader.ReadDataRecord();
            var dsid = DataSetGeneralInformationRecord.Fields.GetFieldByTag("DSID");

            if (dsid != null)
            {
                IntendedUsage = dsid.GetUInt32("INTU");
            }
            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
            }
        }
Beispiel #6
0
 public void ReadProductInfo(System.IO.Stream stream)
 {
     using (var reader = new Iso8211Reader(stream))
     {
         productInfo = new ProductInfo(reader);
     }
 }
Beispiel #7
0
 public void ReadCatalogue(System.IO.Stream stream)
 {
     using (var reader = new Iso8211Reader(stream))
     {
         catalogueFile = new CatalogueFile(reader);
         BuildCatalogue();
     }
 }
Beispiel #8
0
 public void Read(System.IO.Stream stream)
 {
     newFeatures.Clear();
     using (var reader = new Iso8211Reader(stream))
     {
         baseFile = new BaseFile(reader);
         cell     = new Cell(baseFile);
         BuildVectors();
         BuildFeatures();
     }
 }
Beispiel #9
0
        public CatalogueFile(Iso8211Reader reader)
        {
            var nextRec = reader.ReadDataRecord();

            while (nextRec != null)
            {
                DataField field = nextRec.Fields.GetFieldByTag("CATD");
                if (field != null)
                {
                    CatalogueRecords.Add(nextRec);
                }
                nextRec = reader.ReadDataRecord();
            }
        }
Beispiel #10
0
 public void Read(System.IO.Stream stream)
 {
     //Stopwatch timer = new Stopwatch();
     //timer.Start();
     using (var reader = new Iso8211Reader(stream))
     {
         baseFile = new BaseFile(reader);
     }
     //timer.Stop();
     //Console.WriteLine(((double)(timer.Elapsed.TotalMilliseconds)).ToString("0.00 ms"));
     cell = new Cell(baseFile);
     //timer.Start();
     baseFile.BindVectorPointersOfVectors();
     baseFile.BindVectorPointersOfFeatures();
     baseFile.BuildVectorGeometry();
     baseFile.BindFeatureObjectPointers();
     //timer.Stop();
     //Console.WriteLine(((double)(timer.Elapsed.TotalMilliseconds)).ToString("0.00 ms"));
 }
Beispiel #11
0
        public void ShouldOpenTheCatalog031File()
        {
            using (var reader = new Iso8211Reader(@".\CATALOG.031"))
            {
                reader.Open();

                int       i = 0;
                DdfRecord record;
                while ((record = reader.Read()) != null)
                {
                    i++;
                    foreach (var field in record.Fields)
                    {
                        Debug.WriteLine(field.FieldDefinition.FieldName);
                        var data = field.GetRecord();
                        foreach (var key in data.Keys)
                        {
                            Debug.WriteLine("{0}:{1}", key, data[key].Value);
                        }
                    }
                }
                Debug.WriteLine(i);
            }
        }
Beispiel #12
0
        public void ReadArchiveCatalogue(ZipArchive archive, string MapName)
        {
            string          basename       = MapName.Remove(MapName.Length - 4);
            Stream          S57map         = null;
            ZipArchiveEntry catalogueentry = null;

            foreach (ZipArchiveEntry entry in archive.Entries)
            {
                if (entry.Name.Contains(basename))
                {
                    if (entry.Name.Equals(MapName))
                    {
                        catalogueentry = entry;
                    }
                }
            }
            S57map = catalogueentry.Open();
            using (var reader = new Iso8211Reader(S57map))
            {
                catalogueFile = new CatalogueFile(reader);
                BuildCatalogue();
            }
            S57map.Dispose();
        }
Beispiel #13
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;
        }
Beispiel #14
0
        public void ReadFromArchive(ZipArchive archive, string MapName, bool ApplyUpdates)
        {
            //Stopwatch timer = new Stopwatch();
            //timer.Start();
            string          basename  = MapName.Remove(MapName.Length - 4);
            Stream          S57map    = null;
            ZipArchiveEntry baseentry = null;
            SortedList <uint, ZipArchiveEntry> updatefiles = new SortedList <uint, ZipArchiveEntry>();
            Stream S57update;

            foreach (ZipArchiveEntry entry in archive.Entries)
            {
                if (entry.Name.Contains(basename))
                {
                    if (entry.Name.Equals(MapName))
                    {
                        baseentry = entry;
                    }
                    else
                    {
                        int    val;
                        string end = entry.Name.Substring(entry.Name.Length - 3);
                        if (char.IsDigit(end[0]) && char.IsDigit(end[1]) && char.IsDigit(end[2]))
                        {
                            int.TryParse(end, out val);
                            updatefiles.Add(Convert.ToUInt32(end.ToString()), entry);
                        }
                    }
                }
            }
            S57map = baseentry.Open();
            using (var reader = new Iso8211Reader(S57map))
            {
                baseFile = new BaseFile(reader);
            }
            S57map.Dispose();
            //timer.Stop();
            //Console.WriteLine(((double)(timer.Elapsed.TotalMilliseconds)).ToString("0.00 ms"));
            //timer.Start();
            if (ApplyUpdates)
            {
                foreach (var entry in updatefiles)
                {
                    S57update = entry.Value.Open();
                    using (var updatereader = new Iso8211Reader(S57update))
                    {
                        UpdateFile updateFile = new UpdateFile(updatereader);
                        baseFile.ApplyUpdateFile(updateFile);
                    }
                    S57update.Dispose();
                }
            }
            //timer.Stop();
            //Console.WriteLine(((double)(timer.Elapsed.TotalMilliseconds)).ToString("0.00 ms"));

            //cell = new Cell(baseFile);
            //timer.Start();
            baseFile.BindVectorPointersOfVectors();
            baseFile.BindVectorPointersOfFeatures();
            baseFile.BuildVectorGeometry();
            baseFile.BindFeatureObjectPointers();
        }
Beispiel #15
0
        public void Read(ZipArchive archive, string MapName, bool ApplyUpdates)
        {
            string          basename  = MapName.Remove(MapName.Length - 4);
            Stream          S57map    = null;
            ZipArchiveEntry baseentry = null;
            SortedList <uint, ZipArchiveEntry> updatefiles = new SortedList <uint, ZipArchiveEntry>();
            Stream S57update;

            foreach (ZipArchiveEntry entry in archive.Entries)
            {
                if (entry.Name.Contains(basename))
                {
                    if (entry.Name.Equals(MapName))
                    {
                        baseentry = entry;
                    }
                    else
                    {
                        int    val;
                        string end = entry.Name.Substring(entry.Name.Length - 3);
                        if (char.IsDigit(end[0]) && char.IsDigit(end[1]) && char.IsDigit(end[2]))
                        {
                            int.TryParse(end, out val);
                            updatefiles.Add(Convert.ToUInt32(end.ToString()), entry);
                        }
                    }
                }
            }
            S57map = baseentry.Open();
            int count = (int)baseentry.Length;

            if (fileByteArray == null)
            {
                fileByteArray = new byte[count];
            }
            else
            {
                Array.Clear(fileByteArray, 0, fileByteArray.Length);
                Array.Resize(ref fileByteArray, count);
            }
            MemoryStream memoryStream = new MemoryStream(fileByteArray);

            S57map.CopyTo(memoryStream);
            memoryStream.Dispose();

            using (var reader = new Iso8211Reader(fileByteArray))
            {
                baseFile = new BaseFile(reader);
                foreach (var bla in reader.tagcollector)
                {
                    Console.WriteLine(bla);
                }
            }
            S57map.Dispose();

            if (ApplyUpdates)
            {
                foreach (var entry in updatefiles)
                {
                    S57update = entry.Value.Open();
                    count     = (int)entry.Value.Length;
                    Array.Clear(fileByteArray, 0, fileByteArray.Length);
                    Array.Resize(ref fileByteArray, count);
                    memoryStream = new MemoryStream(fileByteArray);
                    S57update.CopyTo(memoryStream);
                    memoryStream.Dispose();
                    using (var updatereader = new Iso8211Reader(fileByteArray))
                    {
                        UpdateFile updateFile = new UpdateFile(updatereader);
                        baseFile.ApplyUpdateFile(updateFile);
                    }
                    S57update.Dispose();
                }
            }
            cellInfo = new Cell(baseFile);
            baseFile.BindVectorPointersOfVectors();
            baseFile.BindVectorPointersOfFeatures();
            baseFile.BuildVectorGeometry();
            baseFile.BindFeatureObjectPointers();
        }
Beispiel #16
0
 public UpdateFile(Iso8211Reader reader)
 {
     throw new NotImplementedException("UpdateFile not implemented");
 }
Beispiel #17
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)
            {
                subFieldRow                  = dssi.subFields.Values[0];
                tagLookup                    = dssi.subFields.TagIndex;
                vectorDataStructure          = (VectorDataStructure)subFieldRow.GetUInt32(tagLookup.IndexOf("DSTR"));
                ATTFLexicalLevel             = (S57LexicalLevel)subFieldRow.GetUInt32(tagLookup.IndexOf("AALL"));
                NATFLexicalLevel             = (S57LexicalLevel)subFieldRow.GetUInt32(tagLookup.IndexOf("NALL"));
                numberOfMetaRecords          = subFieldRow.GetUInt32(tagLookup.IndexOf("NOMR"));
                numberOfCartographicRecords  = subFieldRow.GetUInt32(tagLookup.IndexOf("NOCR"));
                numberOfGeoRecords           = subFieldRow.GetUInt32(tagLookup.IndexOf("NOGR"));
                numberOfCollectionRecords    = subFieldRow.GetUInt32(tagLookup.IndexOf("NOLR"));
                numberOfIsolatedNodeRecords  = subFieldRow.GetUInt32(tagLookup.IndexOf("NOIN"));
                numberOfConnectedNodeRecords = subFieldRow.GetUInt32(tagLookup.IndexOf("NOCN"));
                numberOfEdgeRecords          = subFieldRow.GetUInt32(tagLookup.IndexOf("NOED"));
                numberOfFaceRecords          = subFieldRow.GetUInt32(tagLookup.IndexOf("NOFA"));
            }

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

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

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

            eFeatureRecords = new Dictionary <NAMEkey, Feature>();
            eFeatureObjects = new Dictionary <LongName, Feature>();
            eVectorRecords  = new Dictionary <NAMEkey, Vector>();

            var nextRec = reader.ReadDataRecord();

            while (nextRec != null)
            {
                if (nextRec.Fields.FindFieldByTag("VRID"))
                {
                    vrid = nextRec.Fields.GetFieldByTag("VRID");
                    rcnm = vrid.subFields.GetUInt32(0, "RCNM");
                    rcid = vrid.subFields.GetUInt32(0, "RCID");
                    var    key    = new NAMEkey(rcnm, rcid);
                    Vector newVec = new Vector(key, nextRec);
                    eVectorRecords.Add(key, newVec);
                }
                else
                {
                    if (nextRec.Fields.FindFieldByTag("FRID"))
                    {
                        frid = nextRec.Fields.GetFieldByTag("FRID");
                        rcnm = frid.subFields.GetUInt32(0, "RCNM");
                        rcid = frid.subFields.GetUInt32(0, "RCID");
                        //consider using lnam as key (from FOID field), challenge: update files deleting a feature record do not encode lnam of that feature record
                        var     key     = new NAMEkey(rcnm, rcid);
                        Feature newFeat = new Feature(key, nextRec);
                        eFeatureRecords.Add(key, newFeat);
                    }
                }
                nextRec = reader.ReadDataRecord();
            }
        }