Exemple #1
0
        public void Read(string filename)
        {
            using (FileStream stream = new FileStream(filename, FileMode.Open))
            {
                using (BinaryReader br = new BinaryReader(stream))
                {
                    byte[] awxLevel1HeaderBytes = br.ReadBytes(40);
                    L1Header = new AWXLevel1Header();
                    L1Header.Read(new MemoryStream(awxLevel1HeaderBytes));
                    switch (L1Header.ProductType)
                    {
                    case 1:
                        L2Header = new AWXLevel2HeaderImageGeostationary();
                        break;

                    case 2:
                        L2Header = new AWXLevel2HeaderImagePolarOrbit();
                        break;

                    default:
                        L2Header = new AWXLevel2HeaderImagePolarOrbit();
                        break;
                    }
                    byte[] awxLevel2HeaderBytes = br.ReadBytes(L1Header.Level2HeaderLength);
                    L2Header.Read(new MemoryStream(awxLevel2HeaderBytes));
                    switch (L1Header.ProductType)
                    {
                    case 1:
                        AWXLevel2HeaderImage L2HeaderImageGeostationary = L2Header as AWXLevel2HeaderImage;
                        if (L2HeaderImageGeostationary.ToningTableDataBlockLength
                            + L2HeaderImageGeostationary.CalibrationDataBlockLength
                            + L2HeaderImageGeostationary.LocationDataBlockLength > 0)
                        {
                            L2HeaderEx = new AWXLevel2HeaderExImage(
                                L2HeaderImageGeostationary.ToningTableDataBlockLength,
                                L2HeaderImageGeostationary.CalibrationDataBlockLength,
                                L2HeaderImageGeostationary.LocationDataBlockLength,
                                new CalibrationDataBlockGeostationary());
                            L2HeaderEx.Read(stream);
                        }
                        break;

                    case 2:
                        AWXLevel2HeaderImage L2HeaderImagePolarOrbit = L2Header as AWXLevel2HeaderImage;
                        if (L2HeaderImagePolarOrbit.ToningTableDataBlockLength
                            + L2HeaderImagePolarOrbit.CalibrationDataBlockLength
                            + L2HeaderImagePolarOrbit.LocationDataBlockLength > 0)
                        {
                            L2HeaderEx = new AWXLevel2HeaderExImage(
                                L2HeaderImagePolarOrbit.ToningTableDataBlockLength,
                                L2HeaderImagePolarOrbit.CalibrationDataBlockLength,
                                L2HeaderImagePolarOrbit.LocationDataBlockLength,
                                new CalibrationDataBlockGeostationary());
                            L2HeaderEx.Read(stream);
                        }
                        break;
                    }
                }
            }
        }
Exemple #2
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);
                }
            }
        }
Exemple #3
0
        protected override void CallGDALBefore()
        {
            base.CallGDALBefore();
            AWXFile awxFile = new AWXFile();

            awxFile.Read(fileName);
            if (awxFile.L1Header.ProductType == 1 || awxFile.L1Header.ProductType == 2)
            {
                AWXLevel2HeaderImage l2HI = awxFile.L2Header as AWXLevel2HeaderImage;
                HdrFile hdr = new HdrFile();
                hdr.DataType = 0;
                if (l2HI.Reserve != 0)
                {
                    hdr.DataType = l2HI.Reserve;
                }
                if (awxFile.L1Header.ProductType == 2)
                {
                    AWXLevel2HeaderImagePolarOrbit l2HIP = awxFile.L2Header as AWXLevel2HeaderImagePolarOrbit;
                    if (hdr.DataType == 0)
                    {
                        if (l2HIP.BytesPerPixel == 2)
                        {
                            hdr.DataType = 2;
                        }
                        else
                        {
                            hdr.DataType = 1;
                        }
                    }
                }
                else
                {
                    l2HI = awxFile.L2Header as AWXLevel2HeaderImageGeostationary;
                    //if(hdr.DataType==0)
                    hdr.DataType = 1;
                }
                hdr.Lines = l2HI.ImageHeight;
                string[] bandNames;
                hdr.Bands        = CheckBands(awxFile.L1Header, l2HI, out bandNames);//需根据静止或极轨数据进行区分;
                hdr.BandNames    = bandNames;
                hdr.Samples      = l2HI.ImageWidth;
                hdr.HeaderOffset = awxFile.L1Header.RecordLength;
                hdr.Intertleave  = enumInterleave.BSQ;
                hdr.ByteOrder    = (awxFile.L1Header.Endian == 0) ? enumHdrByteOder.Host_intel : enumHdrByteOder.Network_IEEE;
                //TryCreateSpatialRefByHeader(l2HI);
                //hdr.HdrProjectionInfo = GetHdrProjectionInfo();
                hdr.MapInfo = GetHdrMapInfo(l2HI);
                //hdr.GeoPoints = GetHdrGeoPoints(l2HI);
                hdr.SaveTo(Path.ChangeExtension(fileName, "hdr"));
            }
        }
Exemple #4
0
        private int CheckBands(AWXLevel1Header l1Hdr, AWXLevel2HeaderImage l2HeaderImage, out string [] bandNames)
        {
            int bandNO = 1;

            bandNames = null;
            int ChN = l2HeaderImage.ChannelNumber;

            if (l1Hdr.ProductType == 1)
            {
                bandNO    = 1;
                bandNames = new string[1];
                switch (ChN)
                {
                case 1:
                    bandNames[0] = "红外通道(10.3-11.3)";
                    break;

                case 2:
                    bandNames[0] = "水汽通道 (6.3-7.6)";
                    break;

                case 3:
                    bandNames[0] = "红外分裂窗通道 (11.5-12.5)";
                    break;

                case 4:
                    bandNames[0] = "可见光通道 (0.5-0.9)";
                    break;

                case 5:
                    bandNames[0] = "中红外通道(3.5-4.0)";
                    break;

                default:
                    bandNames[0] = "备用";
                    break;
                }
            }
            else if (l1Hdr.ProductType == 2)
            {
                if (ChN == 0)
                {
                    AWXLevel2HeaderImagePolarOrbit l2HIP = l2HeaderImage as AWXLevel2HeaderImagePolarOrbit;
                    bandNO    = 3;
                    bandNames = new string[3] {
                        "band" + l2HIP.RChannelNumber, "band" + l2HIP.GChannelNumber, "band" + l2HIP.BChannelNumber
                    };
                }
                else
                {
                    bandNames = new string[1];
                    if (ChN > 0 && ChN <= 5)
                    {
                        bandNO       = 1;
                        bandNames[0] = string.Format("band {0}", ChN);
                    }
                    else if (ChN >= 101 && ChN <= 119)
                    {
                        bandNO       = 1;
                        bandNames[0] = "TOVS HIRS通道";
                    }
                    else if (ChN >= 201 && ChN <= 204)
                    {
                        bandNO       = 1;
                        bandNames[0] = "TOVS MSU通道";
                    }
                    else
                    {
                        bandNO       = 1;
                        bandNames[0] = "备用";
                    }
                }
            }
            return(bandNO);
        }