Exemplo n.º 1
0
        protected override void ReadLocations(AbstractWarpDataset srcRaster, out double[] longitudes,
                                              out double[] latitudes, out Size locationSize)
        {
            try
            {
                Console.WriteLine($"{srcRaster.Width} {srcRaster.Height}");
                locationSize = new Size(srcRaster.Width, srcRaster.Height);
                longitudes   = new Double[srcRaster.Width * srcRaster.Height];
                latitudes    = new Double[srcRaster.Width * srcRaster.Height];
                CPLErr err = CPLErr.CE_None;

                Band latBand = srcRaster.GetBands(Latitude)[0];
                Console.WriteLine($"LatBand {latBand.XSize} {latBand.YSize}");
                err = latBand.ReadRaster(0, 0, latBand.XSize, latBand.YSize, latitudes,
                                         locationSize.Width, locationSize.Height, 0, 0);
                Console.WriteLine("latBand.ReadRaster" + err);

                Band lonBand = srcRaster.GetBands(Longitude)[0];
                Console.WriteLine($"LonBand {lonBand.XSize} {lonBand.YSize}");

                err = lonBand.ReadRaster(0, 0, lonBand.XSize, lonBand.XSize, longitudes,
                                         locationSize.Width, locationSize.Height, 0, 0);
                Console.WriteLine("lonBand.ReadRaster" + err);
            }
            catch (Exception ex)
            {
                throw new Exception("读取经纬度数据集失败:" + ex.Message, ex);
            }
        }
Exemplo n.º 2
0
        public override void ComputeDstEnvelope(AbstractWarpDataset srcRaster, SpatialReference dstSpatialRef,
                                                out PrjEnvelope maxPrjEnvelope, Action <int, string> progressCallback)
        {
            InitLocationArgs(srcRaster);
            var projTrans = ProjectionTransformFactory.GetProjectionTransform(_srcSpatialRef, dstSpatialRef);

            float srcResolutionX = Convert.ToSingle(_srcGeoTrans[1]);
            float srcResolutionY = Math.Abs(Convert.ToSingle(_srcGeoTrans[5]));

            double srcLeftTopX = _srcGeoTrans[0];
            double srcLeftTopY = _srcGeoTrans[3];
            int    srcWidth    = srcRaster.Width;
            int    srcHeight   = srcRaster.Height;
            Size   srcSize     = new Size(srcWidth, srcHeight);

            int wSample = 1;
            int hSample = 1;

            if (srcWidth > 1000)
            {
                wSample = srcWidth / 1000;
            }

            if (srcHeight > 1000)
            {
                hSample = srcHeight / 1000;
            }

            double[] xs    = new double[(srcWidth / wSample) * (srcHeight / hSample)];
            double[] ys    = new double[(srcWidth / wSample) * (srcHeight / hSample)];
            int      index = 0; //非真实的索引号,采样后的

            for (int rowInx = 0; rowInx <= (srcHeight - hSample); rowInx += hSample)
            {
                for (int colInx = 0; colInx <= (srcWidth - wSample); colInx += wSample)
                {
                    xs[index] = srcLeftTopX + colInx * srcResolutionX;
                    ys[index] = srcLeftTopY - rowInx * srcResolutionY;
                    index++;
                }
            }

            if (dstSpatialRef.IsSame(SpatialReferenceFactory.CreateSpatialReference(4326)) == 1)
            {
                projTrans.Transform(xs, ys);
                GeosCorrection(dstSpatialRef, xs, ys);
                maxPrjEnvelope = PrjEnvelope.GetEnvelope(xs, ys, null);
            }
            else
            {
                _rasterProjector.ComputeDstEnvelope(_srcSpatialRef, xs, ys, srcSize, dstSpatialRef, out maxPrjEnvelope,
                                                    null);
            }

            if (_setting != null && _setting.OutEnvelope != null)
            {
                //求交
                maxPrjEnvelope.Intersect(_setting.OutEnvelope);
            }
        }
Exemplo n.º 3
0
        public override void Project(AbstractWarpDataset srcRaster, FilePrjSettings prjSettings,
                                     SpatialReference dstSpatialRef, Action <int, string> progressCallback)
        {
            _setting = prjSettings as FY4A_AGRIPrjSetting;
            progressCallback?.Invoke(0, "读取位置参数");
            InitLocationArgs(srcRaster);
            CreateDstRaster(srcRaster, prjSettings, dstSpatialRef, progressCallback);
            WriteMetaData(srcRaster, _prdWriter, prjSettings);
            ReadySession(srcRaster, prjSettings, dstSpatialRef, progressCallback);
            var calChannel = ReadDataSetToSingle(srcRaster, _setting.OutBandNos);

            for (int i = 0; i < calChannel.Count; i++)
            {
                ushort[] buffer = new ushort[calChannel[i].Length];
                for (int j = 0; j < calChannel[i].Length; j++)
                {
                    if (calChannel[i][j] > 2)
                    {
                        buffer[j] = Convert.ToUInt16(calChannel[i][j] * 10);
                    }
                    else
                    {
                        buffer[j] = Convert.ToUInt16(calChannel[i][j] * 1000);
                    }
                }

                _calChannel.Add(buffer);
            }

            base.Project(srcRaster, prjSettings, dstSpatialRef, progressCallback);
        }
Exemplo n.º 4
0
        private Band[] TryCreateRasterDataBands(AbstractWarpDataset srcRaster, FY3L2L3FilePrjSettings prjSettings, Action <int, string> progressCallback)
        {
            List <Band> rasterBands = new List <Band>();

            if (prjSettings.OutBandNos == null)
            {
                int count = srcRaster.BandCount;

                for (int i = 0; i < count; i++)
                {
                    if (progressCallback != null)
                    {
                        progressCallback(_readyProgress++, "准备第" + i + "个输入数据通道");
                    }
                    Band band = srcRaster.GetRasterBand(i);
                    rasterBands.Add(band);
                }
            }
            else
            {
                foreach (var i in prjSettings.OutBandNos)
                {
                    Band band = srcRaster.GetRasterBand(i);
                    rasterBands.Add(band);
                }
            }

            return(rasterBands.ToArray());
        }
Exemplo n.º 5
0
        protected override void ReadLocations(AbstractWarpDataset locationRaster, out double[] xs, out double[] ys, out System.Drawing.Size locationSize)
        {
            //IBandProvider srcbandpro = locationRaster.BandProvider as IBandProvider;
            {
                Band[] lonsBands = locationRaster.GetBands("Longitude");
                Band   lonsBand  = lonsBands[0];
                {
                    locationSize = new Size(lonsBand.XSize, lonsBand.YSize);
                    xs           = new Double[lonsBand.XSize * lonsBand.YSize];
                    unsafe
                    {
                        fixed(Double *ptrLong = xs)
                        {
                            IntPtr bufferPtrLong = new IntPtr(ptrLong);

                            lonsBand.ReadRaster(0, 0, lonsBand.XSize, lonsBand.YSize, bufferPtrLong, lonsBand.XSize, lonsBand.YSize, DataType.GDT_Float64, 0, 0);
                        }
                    }
                }
                Band[] latBands = locationRaster.GetBands("Latitude");
                Band   latBand  = latBands[0];
                {
                    ys = new Double[locationSize.Width * locationSize.Height];
                    unsafe
                    {
                        fixed(Double *ptrLat = ys)
                        {
                            {
                                IntPtr bufferPtrLat = new IntPtr(ptrLat);
                                latBand.ReadRaster(0, 0, latBand.XSize, latBand.YSize, bufferPtrLat, latBand.XSize, latBand.YSize, DataType.GDT_Float64, 0, 0);
                            }
                        }
                    }
                }
            }
            if (_xzoom != 1d)
            {
                for (int i = 0; i < xs.Length; i++)
                {
                    xs[i] = xs[i] * _xzoom;
                }
            }
            if (_xzoom != 1d)
            {
                for (int i = 0; i < ys.Length; i++)
                {
                    ys[i] = ys[i] * _yzoom;
                }
            }
            if (_prjSettings != null && _prjSettings.ExtArgs != null && _prjSettings.ExtArgs.Contains("360"))
            {
                for (int i = 0; i < xs.Length; i++)
                {
                    if (xs[i] > 180)
                    {
                        xs[i] = xs[i] - 360d;
                    }
                }
            }
        }
Exemplo n.º 6
0
 private void TryCreateDefaultArg(AbstractWarpDataset srcRaster, FY3L2L3FilePrjSettings prjSettings, ref SpatialReference dstSpatialRef)
 {
     if (dstSpatialRef == null)
     {
         dstSpatialRef = _srcSpatialRef;
     }
     if (string.IsNullOrWhiteSpace(prjSettings.OutFormat))
     {
         prjSettings.OutFormat = "LDF";
     }
     if (dstSpatialRef.IsGeographic() == 1)
     {
         _srcImgResolution = 0.01f;
     }
     else
     {
         _srcImgResolution = 0.01f;
     }
     if (prjSettings.OutResolutionX == 0 || prjSettings.OutResolutionY == 0)
     {
         if (dstSpatialRef.IsGeographic() == 1)
         {
             prjSettings.OutResolutionX = 0.01f;
             prjSettings.OutResolutionY = 0.01f;
         }
         else
         {
             prjSettings.OutResolutionX = 1000f;
             prjSettings.OutResolutionY = 1000f;
         }
     }
 }
Exemplo n.º 7
0
 private void DoSession(AbstractWarpDataset srcRaster, SpatialReference dstSpatialRef, FY3L2L3FilePrjSettings prjSettings, Action <int, string> progressCallback)
 {
     if (_curSession == null || _curSession != srcRaster || _isBeginSession)
     {
         AbstractWarpDataset locationRester = prjSettings.LocationFile;
         ReadyLocations(locationRester, dstSpatialRef, out _xs, out _ys, out _maxPrjEnvelope, out _srcLocationSize, progressCallback);
         if (_srcLocationSize.Width != srcRaster.Width || _srcLocationSize.Height != srcRaster.Height)
         {
             throw new ArgumentException("输入经纬度查找表长宽参数异常");
         }
         if (progressCallback != null)
         {
             progressCallback(_readyProgress++, "准备其他参数");
         }
         //if (prjSettings.IsSolarZenith && prjSettings.IsRadiation)
         //{
         //    _szDataFilename = GetSolarZenithCacheFilename(locationRester.fileName);
         //    if (!File.Exists(_szDataFilename))
         //        ReadySolarZenithArgsToFile(locationRester);
         //    else
         //        _solarZenithCacheRaster = GeoDataDriver.Open(_szDataFilename) as AbstractWarpDataset;
         //    if (prjSettings.IsSensorZenith)
         //    {
         //        ReadySensorZenith(locationRester);
         //    }
         //}
         _rasterDataBands = TryCreateRasterDataBands(srcRaster, prjSettings, progressCallback);
         _isBeginSession  = false;
     }
 }
Exemplo n.º 8
0
        private void WriteDataToLDF <T>(AbstractWarpDataset prdWriter, DataType dataType, int outWidth, int rowStep, int oRow, T[] dstBandData, int b)
        {
            Band band = null;

            try
            {
                band = prdWriter.GetRasterBand(b);
                GCHandle h = GCHandle.Alloc(dstBandData, GCHandleType.Pinned);
                try
                {
                    IntPtr bufferPtr = h.AddrOfPinnedObject();
                    band.WriteRaster(0, oRow, outWidth, rowStep, bufferPtr, outWidth, rowStep, dataType, 0, 0);
                }
                finally
                {
                    h.Free();
                }
            }
            finally
            {
                //这里不能释放,由于大部分band是记录在RasterDataProvider中的数组中的,如果释放后,下次取就会出错
                //if (band!=null&&band is IGDALRasterBand)
                //{
                //    band.Dispose();
                //}
            }
        }
Exemplo n.º 9
0
        private void WriteDataToLDF <T>(AbstractWarpDataset prdWriter, DataType dataType, int outWidth, int rowStep, int oRow, T[] dstBandData, int b, double dataweight, float zoom)
        {
            Band band = null;

            for (int i = 0; i < dstBandData.Length; i++)
            {
                dstBandData[i] = (T)Convert.ChangeType(Convert.ToDouble(dstBandData[i]) * dataweight * zoom, typeof(T));
            }
            try
            {
                band = prdWriter.GetRasterBand(b + 1);
                GCHandle h = GCHandle.Alloc(dstBandData, GCHandleType.Pinned);
                try
                {
                    IntPtr bufferPtr = h.AddrOfPinnedObject();
                    band.WriteRaster(0, oRow, outWidth, rowStep, bufferPtr, outWidth, rowStep, dataType, 0, 0);
                }
                finally
                {
                    h.Free();
                }
            }
            finally
            {
                //这里不能释放,由于大部分band是记录在RasterDataProvider中的数组中的,如果释放后,下次取就会出错
                //if (band!=null&&band is IGDALRasterBand)
                //{
                //    band.Dispose();
                //}
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 初始化输入数据集
        /// </summary>
        /// <param name="srcRaster"></param>
        /// <param name="prjSettings"></param>
        private void InitInputDataset(AbstractWarpDataset srcRaster, FilePrjSettings prjSettings)
        {
            if (iBandGeoDataset == null)
            {
                if ((new int[] { 1, 2, 3, 4, 5 }).Any(t => prjSettings.OutBandNos.Contains(t)))
                {
                    iBandGeoDataset = WarpDataset.Open(FileFinder.TryFindNppIbandGeoFile(srcRaster));
                }
            }

            if (mBandGeoDataset == null)
            {
                mBandGeoDataset = WarpDataset.Open(FileFinder.TryFindNppMbandGeoFile(srcRaster));
            }

            foreach (var item in prjSettings.OutBandNos)
            {
                if (!bandDatasetList.ContainsKey(item))
                {
                    if (item <= 5)
                    {
                        bandDatasetList.Add(item, WarpDataset.Open(FileFinder.TryFindNppIbandFile(srcRaster, item)));
                    }
                    else
                    {
                        bandDatasetList.Add(item,
                                            WarpDataset.Open(FileFinder.TryFindNppMbandFile(srcRaster, item - 5)));
                    }
                }
            }
        }
Exemplo n.º 11
0
        private void InitLocationArgs(AbstractWarpDataset srcRaster)
        {
            double nReslution = 5000;
            var    infoDic    = srcRaster.TryReadDataTable(fileInfo);
            string proj       = "+proj=geos +no_defs +a=6378137.0 +b=6356752.3 +h=35785863";// +h=35785863 +a=6378137.0 +b=6356752.3 +lon_0={0} ";

            if (infoDic.ContainsKey("NOMCenterLon"))
            {
                proj += string.Format(" +lon_0={0}", infoDic["NOMCenterLon"]);
            }
            else
            {
                proj += string.Format(" +lon_0={0}", infoDic["104.5"]);
            }

            double[] geoTransform = new double[6];
            geoTransform[0] = -5720000;
            geoTransform[1] = nReslution;
            geoTransform[2] = 0;
            geoTransform[3] = 5720000 - 0 * nReslution;
            geoTransform[4] = 0;
            geoTransform[5] = -nReslution;
            _srcSpatialRef  = new SpatialReference("");
            _srcSpatialRef.ImportFromProj4(proj);
            _srcGeoTrans = geoTransform;
        }
Exemplo n.º 12
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);
     }
 }
Exemplo n.º 13
0
        protected override void DoRadiation(AbstractWarpDataset srcImgRaster, int i, ushort[] srcBandData, float[] solarZenithData, Size srcBlockImgSize, Size angleSize)
        {
            if (_isRadRef)
            {
                string ds      = _prjBands[i].DataSetName;
                int    dsIndex = _prjBands[i].DataSetIndex;
                DoRadiation(srcImgRaster, srcBandData, srcBlockImgSize, ds, dsIndex, solarZenithData, angleSize);
            }
            if (_isRad)
            {
                string dsName  = _prjBands[i].DataSetName;
                int    dsIndex = _prjBands[i].DataSetIndex;
                ReadDnIS(srcImgRaster, dsName);
                float intercept = _dsIntercept[dsIndex];
                float slope     = _dsSlope[dsIndex];

                Parallel.For(0, srcBandData.Length, (index) =>
                {
                    ushort rad16 = 0;
                    double rad   = slope * (srcBandData[index] - intercept);
                    if (rad < ushort.MaxValue)
                    {
                        rad16 = Convert.ToUInt16(rad);
                    }
                    srcBandData[index] = rad16;
                });
            }
        }
Exemplo n.º 14
0
 private void CheckIs0250(AbstractWarpDataset srcRaster)
 {
     try
     {
         Dictionary <string, string> filaAttrs = srcRaster.GetAttributes();
         if (filaAttrs == null || !filaAttrs.ContainsKey("File Alias Name"))
         {
             throw new Exception("不能确认为合法的MERSI轨道数据,尝试获取文件属性File Alias Name的值为空");
         }
         string fileAliasName = filaAttrs["File Alias Name"];
         if (string.IsNullOrWhiteSpace(fileAliasName))
         {
             throw new Exception("不能确认为合法的MERSI轨道数据,尝试获取文件属性File Alias Name的值为空");
         }
         else if (fileAliasName == "MERSI_1KM_L1")
         {
             _dataType = "1KM";
         }
         else if (fileAliasName == "MERSI_QKM_L1" || fileAliasName == "MERSI_250M_L1")
         {
             _dataType = "QKM";
         }
         else
         {
             throw new Exception("不能确认为合法的MERSI轨道数据,文件属性File Alias Name的值为[" + fileAliasName + "]支持的是MERSI_1KM_L1或者MERSI_QKM_L1");
         }
     }
     catch (Exception ex)
     {
         throw new Exception("不能确认为合法的MERSI轨道数据" + ex.Message, ex.InnerException);
     }
 }
Exemplo n.º 15
0
 private Band[] GetDstRasterBand(AbstractWarpDataset dstRaster, FilePrjSettings prjSettings, int beginBandIndex)
 {
     Band[] bands   = new Band[prjSettings.OutBandNos.Length];
     int[]  bandNos = prjSettings.OutBandNos;
     for (int i = beginBandIndex; i < bandNos.Length + beginBandIndex; i++)
     {
         if (dstRaster.isMultiDs)
         {
             int newBand = -1;
             if (dstRaster.TryGetBandNoFromBandName(bandNos[i], out newBand))
             {
                 bands[i] = dstRaster.GetRasterBand(newBand);
             }
             else
             {
                 bands[i] = dstRaster.GetRasterBand(bandNos[i]);
             }
         }
         else
         {
             bands[i] = dstRaster.GetRasterBand(bandNos[i]);
         }
     }
     return(bands);
 }
Exemplo n.º 16
0
        public static List <string> TryFindHSDGroupt(AbstractWarpDataset fileRaster)
        {
            Console.WriteLine
                ($"开始搜索与文件:{Environment.NewLine}          {fileRaster.fileName}{Environment.NewLine}相同时次的HSD数据");
            FileInfo h8FileInfo = new FileInfo(fileRaster.fileName);

            string[] part = Path.GetFileNameWithoutExtension(fileRaster.fileName).Split('_');
            DateTime time = DateTime.ParseExact(part[2] + part[3], "yyyyMMddHHmm",
                                                System.Globalization.CultureInfo.CurrentCulture);
            var files = h8FileInfo.Directory.GetFiles("*.bz2");

            List <string> groupBz2Files = new List <string>();

            foreach (var bzFile in files)
            {
                string[] parts   = Path.GetFileNameWithoutExtension(bzFile.FullName).Split('_');
                DateTime curTime = DateTime.ParseExact(parts[2] + parts[3], "yyyyMMddHHmm",
                                                       System.Globalization.CultureInfo.CurrentCulture);
                if (curTime == time)
                {
                    groupBz2Files.Add(bzFile.FullName);
                }
            }

            Console.WriteLine
                ($"搜索到匹配时次数据{groupBz2Files.Count}个");
            return(groupBz2Files);
        }
Exemplo n.º 17
0
 private void DoSession(AbstractWarpDataset srcRaster, SpatialReference dstSpatialRef, Fy2_NOM_PrjSettings prjSettings, Action <int, string> progressCallback)
 {
     if (_curSession == null || _curSession != srcRaster || _isBeginSession)
     {
         Size geoSize = new Size(srcRaster.Width, srcRaster.Height);
         ReadyLocations(srcRaster, dstSpatialRef, geoSize, out _xs, out _ys, out _maxPrjEnvelope, progressCallback);
         if (prjSettings.OutEnvelope == null)
         {
             prjSettings.OutEnvelope = _maxPrjEnvelope;
         }
         if (progressCallback != null)
         {
             progressCallback(4, "准备亮温计算参数");
         }
         if (progressCallback != null)
         {
             progressCallback(5, "准备亮温计算参数");
         }
         if (prjSettings.IsSensorZenith)//执行临边变暗订正
         {
             ReadySensorZenith(srcRaster);
         }
         //亮温值映射表
         ReadBandNoValueMap(srcRaster);
         _isBeginSession = false;
     }
 }
Exemplo n.º 18
0
        public static AbstractWarpDataset TryFindFY3C_MERSI_1KM_L1FromQKM(AbstractWarpDataset fileRaster)
        {
            try
            {
                string dir      = Path.GetDirectoryName(fileRaster.fileName);
                string fileName = Path.GetFileName(fileRaster.fileName);
                string retFile  = fileName.Replace("_GEOQK_", "_1000M_");
                string fullpath = Path.Combine(dir, retFile);
                if (retFile == fileName)
                {
                    return(null);
                }
                if (retFile == fileName || !File.Exists(fullpath))
                {
                    //如果文件夹内部不存在再匹配上面两层文件夹是否包含该文件
                    retFile = Path.Combine(dir.Replace("GEOQK", "1000M"), retFile);
                    if (!File.Exists(retFile))
                    {
                        return(null);
                    }
                }

                return(Open(retFile));
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 19
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();
        }
Exemplo n.º 20
0
        public static AbstractWarpDataset TryFindGeoFileFromFY3C_VIRR(AbstractWarpDataset fileRaster)
        {
            string dir      = Path.GetDirectoryName(fileRaster.fileName);
            string fileName = Path.GetFileName(fileRaster.fileName);
            string retFile;

            if (fileName.Contains("_1000M_"))
            {
                retFile = fileName.Replace("_1000M_", "_GEOXX_");
            }
            else if (fileName.Contains("L1B"))
            {
                retFile = fileName.Replace("L1B", "GEOXX");
            }
            else
            {
                throw new Exception("无法找到角度数据(如经纬度等)文件[._GEOXX_...HDF]");
            }
            retFile = Path.Combine(dir.Replace("1000M", "GEO"), retFile);
            if (retFile == fileName || !File.Exists(retFile))
            {
                throw new Exception("无法找到角度数据(如经纬度等)文件[._GEOXX_...HDF]");
            }
            try
            {
                return(Open(retFile));
            }
            catch (Exception ex)
            {
                throw new Exception("获取经纬度文件失败" + ex.Message, ex);
            }
        }
Exemplo n.º 21
0
        public static AbstractWarpDataset TryFindQkmGeoFileFromFY3C_MERSI(AbstractWarpDataset fileRaster)
        {
            string fileName = fileRaster.fileName;
            string dir      = Path.GetDirectoryName(fileName);

            fileName = Path.GetFileName(fileName);
            string retFile      = fileName.Replace("_1000M_", "_GEOQK_").Replace("_0250M_", "_GEOQK_");
            string fileFullPath = Path.Combine(dir, retFile);

            if (retFile == fileName || !File.Exists(fileFullPath))
            {
                //如果文件夹内部不存在再匹配上面两层文件夹是否包含该文件
                fileFullPath = Path.Combine(dir.Replace("1000M", "GEOQK").Replace("250M", "GEOQK"), retFile);
                if (!File.Exists(fileFullPath))
                {
                    return(null);
                }
            }

            try
            {
                return(Open(fileFullPath));
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// 20130418添加了对以下类型文件名的支持。(尚未完成)
 /// Z_SATE_C_BAWX_20130321034403_P_FY3B_MERSI_GBAL_L1_20110220_0510_0250M_MS.HDF
 /// Z_SATE_C_BAWX_20130321034729_P_FY3B_MERSI_GBAL_L1_20110220_0510_1000M_MS.HDF
 /// </summary>
 /// <param name="fileName"></param>
 /// <returns></returns>
 public static AbstractWarpDataset TryFindMERSI_1KM_L1FromQKM(AbstractWarpDataset fileRaster)
 {
     try
     {
         string dir           = Path.GetDirectoryName(fileRaster.fileName);
         string fileName      = Path.GetFileName(fileRaster.fileName);
         string retFile       = fileName.Replace("_0250M_", "_1000M_");
         string resultretFile = Path.Combine(dir, retFile);
         if (retFile == fileName || !File.Exists(resultretFile))
         {
             //这里再进一步扫描目录下的文件,用正则匹配,如果能找到,同样适用。
             if (File.Exists(resultretFile.Replace("250M", "1000M")))
             {
                 return(Open(resultretFile.Replace("250M", "1000M")));
             }
             else
             {
                 throw new Exception("无法找到对应1KM文件(获取太阳天顶角等角度数据使用)");
             }
         }
         else
         {
             return(Open(resultretFile));
         }
     }
     catch (Exception ex)
     {
         throw new Exception("无法找到对应1KM文件(获取太阳天顶角等角度数据使用)", ex);
     }
 }
Exemplo n.º 23
0
        public static AbstractWarpDataset TryFindMERSI_QKM_L1FromKM(AbstractWarpDataset fileRaster)
        {
            try
            {
                string dir      = Path.GetDirectoryName(fileRaster.fileName);
                string fileName = Path.GetFileName(fileRaster.fileName);
                string retFile  = fileName.Replace("_1000M", "_0250M");
                if (retFile == fileName) //文件名中不包含_1000M_
                {
                    return(null);
                }
                string resultretFile = Path.Combine(dir, retFile);
                if (File.Exists(resultretFile))
                {
                    return(Open(resultretFile));
                }
                //增加文件夹匹配原则搜索文件
                else if (File.Exists(Path.Combine(dir.Replace("1000M", "250M"), retFile)))
                {
                    return(Open(Path.Combine(dir.Replace("1000M", "250M"), retFile)));
                }

                //if (kmFileName.Contains("Z_SATE_C_BAWX_"))
                //{
                //}
                return(null);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 24
0
 private void ReadySolarZenithArgsToFile(AbstractWarpDataset srcRaster)
 {
     if (srcRaster == null)
     {
         throw new ArgumentNullException("srcRaster", "获取太阳天顶角数据失败");
     }
     try
     {
         Size    srcSize             = new System.Drawing.Size(srcRaster.Width, srcRaster.Height);
         short[] readSolarZenithData = ReadDataSetToInt16(srcRaster, srcSize, SolarZenith, 0);
         int     length = srcRaster.Width * srcRaster.Height;
         float[] saveSolarZenithData = new float[length];
         Parallel.For(0, length, index =>
         {
             if (readSolarZenithData[index] > 0 && readSolarZenithData[index] < 18000)
             {
                 saveSolarZenithData[index] = (float)(10.0f / Math.Cos(readSolarZenithData[index] * DEG_TO_RAD_P100));
             }
             else
             {
                 saveSolarZenithData[index] = 0;
             }
         });
         _solarZenithCacheRaster = WriteData(saveSolarZenithData, _szDataFilename, srcSize.Width, srcSize.Height);
         saveSolarZenithData     = null;
         readSolarZenithData     = null;
     }
     catch (Exception ex)
     {
         throw new Exception("获取太阳天顶角数据失败", ex.InnerException);
     }
 }
Exemplo n.º 25
0
        private void ReadyLocations(AbstractWarpDataset srcRaster, SpatialReference dstSpatialRef, FY3_MERSI_PrjSettings fy3prjSettings,
                                    out Size locationSize, out PrjEnvelope maxPrjEnvelope, Action <int, string> progressCallback)
        {
            if (progressCallback != null)
            {
                progressCallback(_readyProgress++, "读取经纬度数据集");
            }
            Stopwatch sw = new Stopwatch();

            sw.Start();
            double[] xs = null;
            double[] ys = null;
            //Size locationSize;
            ReadLocations(srcRaster, out xs, out ys, out locationSize);
            TryResetLonlatForLeftRightInvalid(xs, ys, locationSize);
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds + "ms....1");
            if (progressCallback != null)
            {
                progressCallback(_readyProgress++, "预处理经纬度数据集");
            }
            sw.Restart();
            _rasterProjector.ComputeDstEnvelope(_srcSpatialRef, xs, ys, locationSize, dstSpatialRef, out maxPrjEnvelope, progressCallback);
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds + "ms....2");
            _xs = xs;
            _ys = ys;
        }
Exemplo n.º 26
0
 public override void EndSession()
 {
     base.EndSession();
     _xs            = null;
     _ys            = null;
     _vir_Cal_Coeff = null;
     if (_solarZenithCacheRaster != null)
     {
         _solarZenithCacheRaster.Dispose();
         _solarZenithCacheRaster = null;
     }
     if (_longitudeBand != null)
     {
         (_longitudeBand as IDisposable).Dispose();
         _longitudeBand = null;
     }
     if (_latitudeBand != null)
     {
         (_latitudeBand as IDisposable).Dispose();
         _latitudeBand = null;
     }
     if (_latitudeRaster != null)
     {
         _latitudeRaster.Dispose();
         _latitudeRaster = null;
     }
     if (_longitudeRaster != null)
     {
         _longitudeRaster.Dispose();
         _longitudeRaster = null;
     }
 }
Exemplo n.º 27
0
 private void DoSession(AbstractWarpDataset srcRaster, AbstractWarpDataset locationRaster, SpatialReference dstSpatialRef, FY3_MERSI_PrjSettings prjSettings, Action <int, string> progressCallback)
 {
     if (_curSession == null || _curSession != srcRaster || _isBeginSession)
     {
         Size srcImgSize = new Size(srcRaster.Width, srcRaster.Height);
         ReadyLocations(srcRaster, dstSpatialRef, prjSettings, out _srcLocationSize, out _maxPrjEnvelope, progressCallback);
         if (progressCallback != null)
         {
             progressCallback(4, "准备其他参数");
         }
         if (prjSettings.IsRadRef || prjSettings.IsRad)
         {
             ReadyRadiationArgs(srcRaster);
         }
         if (prjSettings.IsSolarZenith) //&& prjSettings.IsRadiation
         {
             _szDataFilename = GetSolarZenithCacheFilename(locationRaster.fileName);
             if (!File.Exists(_szDataFilename))
             {
                 ReadySolarZenithArgsToFile(locationRaster);
             }
             else
             {
                 _solarZenithCacheRaster = WarpDataset.Open(_szDataFilename);
             }
             if (prjSettings.IsSensorZenith)
             {
                 ReadySensorZenith(locationRaster);
             }
         }
         _rasterDataBands = TryCreateRasterDataBands(srcRaster, prjSettings, progressCallback);//待投影的波段
         _isBeginSession  = false;
     }
 }
Exemplo n.º 28
0
 public override void EndSession()
 {
     if (_prdWriter != null)
     {
         _prdWriter.Dispose();
         _prdWriter = null;
     }
 }
Exemplo n.º 29
0
 // 1
 public override void Project(AbstractWarpDataset srcRaster, FilePrjSettings prjSettings,
                              SpatialReference dstSpatialRef, Action <int, string> progressCallback)
 {
     _dstSpatialRef       = dstSpatialRef;
     _projectionTransform = ProjectionTransformFactory.GetProjectionTransform(_srcSpatialRef, dstSpatialRef);
     ProjectRaster(srcRaster, prjSettings, _prdWriter, progressCallback, NODATA_VALUE, 0, 1, 1);
     GC.Collect();
 }
Exemplo n.º 30
0
 private void ReadySensorZenith(AbstractWarpDataset srcRaster)
 {
     _sensorSenithRaster = srcRaster;
     Band[] bands = srcRaster.GetBands("NOMSatelliteZenith");//卫星天顶角
     if (bands != null || bands.Length != 1)
     {
         _sensorSenithBand = bands[0];
     }
 }