Пример #1
0
        internal static void GetBandmapTable(AbstractWarpDataset srcRaster, int[] bandIndexs, out int[] kmBandNoMaps)
        {
            kmBandNoMaps = null;
            PrjBand[] srcBands     = PrjBandTable.GetPrjBands(srcRaster);
            int       kmBandLength = srcBands.Length;

            if (bandIndexs == null || bandIndexs.Length == 0)
            {
                bandIndexs = new int[kmBandLength];
                for (int i = 0; i < bandIndexs.Length; i++)
                {
                    bandIndexs[i] = i + 1;
                }
            }

            List <int> km = new List <int>();

            for (int i = 0; i < bandIndexs.Length; i++)
            {
                if (bandIndexs[i] <= kmBandLength)
                {
                    km.Add(bandIndexs[i]);
                }
            }

            kmBandNoMaps = km.Count == 0 ? null : km.ToArray();
        }
Пример #2
0
 private void InitLutList(AbstractWarpDataset srcRaster)
 {
     PrjBand[] prjBands = PrjBandTable.GetPrjBands(srcRaster);
     for (int i = 0; i < _setting.OutBandNos.Length; i++)
     {
         int     bandNo  = _setting.OutBandNos[i];
         PrjBand b       = prjBands[bandNo - 1];
         string  calName = b.DataSetName.Replace("NOMChannel", "CALChannel");
         Band[]  bands   = srcRaster.GetBands(calName);
         if (bands == null || bands.Length == 0)
         {
             throw new ArgumentNullException(string.Format("FY2X辐射定标,未找到名称为{0}的数据.", calName));
         }
         var     band   = bands[0];
         float[] buffer = new float[band.XSize * band.YSize];
         band.ReadRaster(0, 0, band.XSize, band.YSize, buffer, band.XSize, band.YSize, 0, 0);
         UInt16[] ubuffer = new ushort[band.XSize * band.YSize];
         for (int j = 0; j < buffer.Length; j++)
         {
             if (buffer[j] > 1)
             {
                 ubuffer[j] = (UInt16)(buffer[j] * 10 + 0.5);
             }
             else
             {
                 ubuffer[j] = (UInt16)(buffer[j] * 1000 + 0.5);
             }
         }
         _lutList.Add(ubuffer);
     }
 }
Пример #3
0
        protected Band[] TryCreateRasterDataBands(AbstractWarpDataset srcRaster, FilePrjSettings prjSettings,
                                                  Action <int, string> progressCallback)
        {
            PrjBand[]   bands       = PrjBandTable.GetPrjBands(srcRaster);
            List <Band> rasterBands = new List <Band>();

            for (int i = 0; i < prjSettings.OutBandNos.Length; i++)
            {
                if (progressCallback != null)
                {
                    progressCallback(_readyProgress++, "投影准备");
                }
                int     bandNo = prjSettings.OutBandNos[i];
                PrjBand b      = bands[bandNo - 1];
                Band    band   = srcRaster.GetBands(b.DataSetName)[0];
                rasterBands.Add(band);
            }

            return(rasterBands.ToArray());
        }
Пример #4
0
        private List <float[]> ReadDataSetToSingle(AbstractWarpDataset srcbandpro, int[] bands)
        {
            List <float[]> datas    = new List <float[]>();
            var            prjBands = PrjBandTable.GetPrjBands(srcbandpro);
            H5ID           h5FileId = H5F.open(srcbandpro.fileName, H5F.ACC_RDONLY);

            foreach (int index in bands)
            {
                //Single[] data = new Single[srcSize.Width * srcSize.Height];
                var    bandIndex = prjBands[index - 1].DataSetIndex;
                string dsName    = "CALChannel" + bandIndex.ToString("00");


                H5ID datasetId = H5D.open(h5FileId, dsName);
                if (datasetId <= 0)
                {
                    throw new ArgumentNullException(string.Format("FY4辐射定标,未找到名称为{0}的数据.",
                                                                  "CALChannel" + index.ToString("00")));
                }
                H5ID typeId  = H5D.get_type(datasetId);
                H5ID spaceId = H5D.get_space(datasetId);
                if (H5T.get_class(typeId) == H5T.class_t.FLOAT)
                {
                    int     rank    = H5S.get_simple_extent_ndims(spaceId);
                    ulong[] dims    = new ulong[rank];
                    ulong[] maxDims = new ulong[rank];
                    H5S.get_simple_extent_dims(spaceId, dims, maxDims);

                    float[]  buffer = new float[dims[0]];
                    GCHandle hnd    = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                    H5D.read(datasetId, typeId, H5S.ALL, H5S.ALL, H5P.DEFAULT, hnd.AddrOfPinnedObject());
                    hnd.Free();
                    if (buffer.Any(t => t > Math.Pow(10, 10) || t < -Math.Pow(10, 10)))
                    {
                        for (int i = 0; i < buffer.Length; i++)
                        {
                            var t = BitConverter.GetBytes(buffer[i]);
                            Array.Reverse(t);
                            buffer[i] = BitConverter.ToSingle(t, 0);
                        }
                    }

                    datas.Add(buffer);
                }

                if (spaceId != 0)
                {
                    H5S.close(spaceId);
                }
                if (typeId != 0)
                {
                    H5T.close(typeId);
                }
                if (datasetId != 0)
                {
                    H5D.close(datasetId);
                }
            }

            if (h5FileId != 0)
            {
                H5F.close(h5FileId);
            }

            return(datas);
        }