コード例 #1
0
        private void WritePolarAWX(string hdr, string dat, RasterIdentify id)
        {
            HdrFile hdrObj = HdrFile.LoadFrom(hdr);

            L1Header = new AWXLevel1HeaderImagePolarOrbit();
            L1Header.Write(hdrObj);
            L2Header = new AWXLevel2HeaderImagePolarOrbit();
            if (hdrObj.MapInfo.Name == "Geographic Lat/Lon")
            {
                L2Header.ProjectMode = 4;
            }
            using (IRasterDataProvider dataprd = GeoDataDriver.Open(dat) as IRasterDataProvider)
            {
                if (dataprd != null && dataprd.BandCount != 0)
                {
                    L2Header.GeographicalScopeNorthLatitude = (short)(dataprd.CoordEnvelope.MaxY * 100);
                    L2Header.GeographicalScopeSouthLatitude = (short)(dataprd.CoordEnvelope.MinY * 100);
                    L2Header.GeographicalScopeWestLongitude = (short)(dataprd.CoordEnvelope.MinX * 100);
                    L2Header.GeographicalScopeEastLongitude = (short)(dataprd.CoordEnvelope.MaxX * 100);

                    L2Header.ProjectCenterLatitude       = (short)((L2Header.GeographicalScopeNorthLatitude + L2Header.GeographicalScopeSouthLatitude) / 2);
                    L2Header.ProjectCenterLongitude      = (short)((L2Header.GeographicalScopeEastLongitude + L2Header.GeographicalScopeWestLongitude) / 2);
                    L2Header.ProjectHorizontalResolution = (short)(dataprd.ResolutionX * 100 * 100);
                    L2Header.ProjectVerticalResolution   = (short)(dataprd.ResolutionY * 100 * 100);
                }
            }
            L2Header.Write(hdrObj, id);
            Padding = new byte[L1Header.RecordLength - L1Header.Level1HeaderLength - L1Header.Level2HeaderLength];
            L1Header.WriteFile(hdr);
            L2Header.WriteFile(hdr);
            using (FileStream stream = new FileStream(Path.ChangeExtension(hdr, "AWX"), FileMode.Append))
            {
                using (BinaryWriter bw = new BinaryWriter(stream))
                {
                    bw.Write(Padding);
                }
            }
            using (FileStream stream = new FileStream(dat, FileMode.Open))
            {
                stream.Seek(hdrObj.HeaderOffset, SeekOrigin.Begin);
                using (BinaryReader br = new BinaryReader(stream))
                {
                    byte[] awxProductBytes = br.ReadBytes(Convert.ToInt32(stream.Length - stream.Position));
                    Product = new AWXProduct();
                    Product.Read(new MemoryStream(awxProductBytes));
                }
            }
            using (FileStream stream = new FileStream(Path.ChangeExtension(hdr, "AWX"), FileMode.Append))
            {
                using (BinaryWriter bw = new BinaryWriter(stream))
                {
                    bw.Write(Product.Data);
                }
            }
        }
コード例 #2
0
        private void WriteStationaryAWX(string hdr, string dat, RasterIdentify id)
        {
            HdrFile hdrObj = HdrFile.LoadFrom(hdr);

            L1Header = new AWXLevel1HeaderImageGeostationaryOrbit();
            L1Header.Write(hdrObj);
            L2Header = new AWXLevel2HeaderImageGeostationary();
            if (hdrObj.MapInfo.Name == "Geographic Lat/Lon")
            {
                L2Header.ProjectMode = 4;
            }
            enumDataType datatype = enumDataType.Unknow;

            using (IRasterDataProvider dataprd = GeoDataDriver.Open(dat) as IRasterDataProvider)
            {
                if (dataprd != null && dataprd.BandCount != 0)
                {
                    datatype = dataprd.DataType;
                    L2Header.GeographicalScopeNorthLatitude = (short)(dataprd.CoordEnvelope.MaxY * 100);
                    L2Header.GeographicalScopeSouthLatitude = (short)(dataprd.CoordEnvelope.MinY * 100);
                    L2Header.GeographicalScopeWestLongitude = (short)(dataprd.CoordEnvelope.MinX * 100);
                    L2Header.GeographicalScopeEastLongitude = (short)(dataprd.CoordEnvelope.MaxX * 100);
                    L2Header.ProjectCenterLatitude          = (short)((L2Header.GeographicalScopeNorthLatitude + L2Header.GeographicalScopeSouthLatitude) / 2);
                    L2Header.ProjectCenterLongitude         = (short)((L2Header.GeographicalScopeEastLongitude + L2Header.GeographicalScopeWestLongitude) / 2);
                    L2Header.ProjectHorizontalResolution    = (short)(dataprd.ResolutionX * 100 * 100);
                    L2Header.ProjectVerticalResolution      = (short)(dataprd.ResolutionY * 100 * 100);
                }
            }
            L2Header.Write(hdrObj, id);
            Padding = new byte[L1Header.RecordLength - L1Header.Level1HeaderLength - L1Header.Level2HeaderLength];
            L1Header.WriteFile(hdr);
            L2Header.WriteFile(hdr);
            using (FileStream stream = new FileStream(Path.ChangeExtension(hdr, "AWX"), FileMode.Append))
            {
                using (BinaryWriter bw = new BinaryWriter(stream))
                {
                    bw.Write(Padding);
                }
            }
            using (FileStream stream = new FileStream(dat, FileMode.Open))
            {
                stream.Seek(hdrObj.HeaderOffset, SeekOrigin.Begin);
                using (BinaryReader br = new BinaryReader(stream))
                {
                    byte[] awxProductBytes = new Byte[L2Header.ImageHeight * L2Header.ImageWidth];
                    switch (datatype)
                    {
                    case enumDataType.Byte:
                        awxProductBytes = br.ReadBytes(Convert.ToInt32(stream.Length - stream.Position));
                        break;

                    case enumDataType.Int16:
                        for (int i = 0; i < awxProductBytes.Length; i++)
                        {
                            awxProductBytes[i] = BitConverter.GetBytes(br.ReadInt16())[0];
                        }
                        break;

                    case enumDataType.UInt16:
                        for (int i = 0; i < awxProductBytes.Length; i++)
                        {
                            awxProductBytes[i] = BitConverter.GetBytes(br.ReadUInt16())[0];
                        }
                        break;

                    case enumDataType.Int32:
                        for (int i = 0; i < awxProductBytes.Length; i++)
                        {
                            awxProductBytes[i] = BitConverter.GetBytes(br.ReadInt32())[0];
                        }
                        break;

                    case enumDataType.UInt32:
                        for (int i = 0; i < awxProductBytes.Length; i++)
                        {
                            awxProductBytes[i] = BitConverter.GetBytes(br.ReadUInt32())[0];
                        }
                        break;

                    case enumDataType.Int64:
                        for (int i = 0; i < awxProductBytes.Length; i++)
                        {
                            awxProductBytes[i] = BitConverter.GetBytes(br.ReadInt64())[0];
                        }
                        break;

                    case enumDataType.UInt64:
                        for (int i = 0; i < awxProductBytes.Length; i++)
                        {
                            awxProductBytes[i] = BitConverter.GetBytes(br.ReadUInt64())[0];
                        }
                        break;

                    default:
                        awxProductBytes = br.ReadBytes(Convert.ToInt32(stream.Length - stream.Position));
                        break;
                    }
                    Product = new AWXProduct();
                    Product.Read(new MemoryStream(awxProductBytes));
                }
            }
            using (FileStream stream = new FileStream(Path.ChangeExtension(hdr, "AWX"), FileMode.Append))
            {
                using (BinaryWriter bw = new BinaryWriter(stream))
                {
                    bw.Write(Product.Data);
                }
            }
        }