예제 #1
0
 private void GetSatellite(RasterIdentify rid)
 {
     if (string.IsNullOrEmpty(rid.Satellite) || string.IsNullOrEmpty(Satellite) || rid.Satellite.ToLower() != Satellite.ToLower())
     {
         Satellite = "MULT";
     }
 }
예제 #2
0
        private bool GetFileCollection(string searchStr, string workDir)
        {
            if (fileDic == null)
            {
                fileDic = new Dictionary <DateTime, List <string> >();
            }
            else
            {
                fileDic.Clear();
            }
            string[] files = Directory.GetFiles(workDir, searchStr, SearchOption.AllDirectories);
            if (files == null || files.Length == 0)
            {
                return(false);
            }
            int            length   = files.Length;
            string         filename = string.Empty;
            RasterIdentify ri       = null;

            for (int i = 0; i < length; i++)
            {
                filename = Path.GetFileName(files[i]);
                ri       = new RasterIdentify(files[i]);
                if (!fileDic.ContainsKey(ri.OrbitDateTime))
                {
                    fileDic.Add(ri.OrbitDateTime, new List <string>());
                }
                fileDic[ri.OrbitDateTime].Add(files[i]);
            }
            return(true);
        }
예제 #3
0
 private void GetSensor(RasterIdentify rid)
 {
     if (string.IsNullOrEmpty(rid.Sensor) || string.IsNullOrEmpty(Sensor) || rid.Sensor.ToLower() != Sensor.ToLower())
     {
         Sensor = "MULT";
     }
 }
예제 #4
0
        public Dictionary <DateTime, string> SortByOrbitDate(string[] files)
        {
            if (files == null || files.Length == 0)
            {
                return(null);
            }
            Dictionary <DateTime, string> result = new Dictionary <DateTime, string>();

            if (files.Length == 1)
            {
                CreateRasterIdentify(files[0]);
                result.Add(OrbitDateTime, files[0]);
            }
            else
            {
                RasterIdentify rid = null;
                CreateRasterIdentify(files[0]);
                foreach (string file in files)
                {
                    rid = new RasterIdentify(file);
                    GetOrbitDateTime(rid);
                    result.Add(rid.OrbitDateTime, file);
                }
            }
            return(result.Count == 0 ? null : result.OrderBy(o => o.Key).ToDictionary(o => o.Key, v => v.Value));
        }
예제 #5
0
        /*
         * <Attribute text="产品类别" identify="SubProductIdentify" format="" visible="true"/>
         * <Attribute text="卫星" identify="Satellite" format="" visible="true"/>
         * <Attribute text="传感器" identify="Sensor" format="" visible="true"/>
         * <Attribute text="轨道时间" identify="OrbitDateTime" format="yyyy-MM-dd HH:mm:ss" visible="true"/>
         * <Attribute text="原始文件" identify="SourceFile" format="" visible="true"/>
         * <Attribute text="监测区域" identify="RegionIdentify" format="" visible="true"/>
         * <Attribute text="描述" identify="Description" format="" visible="true"/>
         * <Attribute text="轨道时间分组" identify="OrbitTimeGroup" format="yyyy-MM-dd" visible="true"/>
         * <Attribute text="文件名" identify="FileName" format="" visible="true"/>
         * <Attribute text="路径" identify="FileDir" format="" visible="true"/>
         * <Attribute text="类别中文" identify="CatalogItemCN" format="" visible="false"/>
         * <Attribute text="数据集定义" identify="CatalogDef" format="" visible="false"/>
         * <Attribute text="扩展信息" identify="ExtInfos" format="" visible="false"/>
         * <Attribute text="区域" identify="Region" format="" visible="false"/>
         * <Attribute text="轨道时间段" identify="OrbitTimes" format="yyyy-MM-dd HH:mm:ss ; yyyy-MM-dd HH:mm:ss" visible="false">
         */
        private void TryCreateInfoFromMainFile(string fname, string infoFileName, SubProductCatalogDef catalogDef)
        {
            string fileName = Path.GetFileNameWithoutExtension(fname);

            string[] parts = fileName.Split('_');
            if (parts.Length < 2)
            {
                return;
            }
            RasterIdentify  rst  = new RasterIdentify(fname);
            CatalogItemInfo info = new CatalogItemInfo();

            info.Properties.Add("ProductIdentify", parts[0]);
            info.Properties.Add("SubProductIdentify", parts[1]);
            info.Properties.Add("FileName", Path.GetFileName(fname));
            info.Properties.Add("FileDir", Path.GetDirectoryName(fname));
            info.Properties.Add("CatalogDef", catalogDef == null ? "" : catalogDef.ClassString);
            info.Properties.Add("Satellite", rst.Satellite);
            info.Properties.Add("Sensor", rst.Sensor);
            info.Properties.Add("OrbitDateTime", GetDateFormart(rst.OrbitDateTime, catalogDef, "OrbitDateTime"));
            info.Properties.Add("OrbitTimeGroup", GetDateFormart(rst.OrbitDateTime, catalogDef, "OrbitTimeGroup"));
            info.Properties.Add("CatalogItemCN", GetCatalogCN(info, MifEnvironment.CatalogItemCNDic));
            RasterIdentify ri = new RasterIdentify(fname);

            info.Properties.Add("Region", GetRegionInfo(ri, fname));
            info.Properties.Add("ExtInfos", GetExtInfo(ri, fname));
            info.Properties.Add("CycFlagCN", string.IsNullOrEmpty(ri.CYCFlag) ? "\\" : GetCycFlagCN(info, ri.CYCFlag, MifEnvironment.CatalogItemCNDic));
            info.Properties.Add("OrbitTimes", GetOrbitTimes(ri));
            //.....
            info.SaveTo(infoFileName);
            _info = info;
        }
예제 #6
0
 public IInterestedRaster <T> CycleTimes(string[] fnames, RasterIdentify rasterIdentify, Func <int, T, T, T> iTimesGetter, Action <int, string> progress)
 {
     if (fnames == null || fnames.Length == 0 || iTimesGetter == null)
     {
         return(null);
     }
     if (rasterIdentify == null)
     {
         rasterIdentify = CreateEmptyRasterIdentify();
     }
     IRasterDataProvider[] srcRasters = null;
     try
     {
         srcRasters = new IRasterDataProvider[fnames.Length];
         for (int i = 0; i < srcRasters.Length; i++)
         {
             srcRasters[i] = GeoDataDriver.Open(fnames[i]) as IRasterDataProvider;
         }
         return(CycleTimes(srcRasters, rasterIdentify, iTimesGetter, progress));
     }
     finally
     {
         if (srcRasters != null)
         {
             foreach (IRasterDataProvider prd in srcRasters)
             {
                 prd.Dispose();
             }
         }
         srcRasters = null;
     }
 }
예제 #7
0
        public RasterIdentify(string[] files)
        {
            if (files == null || files.Length == 0)
            {
                return;
            }
            SortedDictionary <DateTime, string> dateFileDic = new SortedDictionary <DateTime, string>();

            if (files.Length == 1)
            {
                CreateRasterIdentify(files[0]);
                dateFileDic.Add(OrbitDateTime, files[0]);
            }
            else
            {
                RasterIdentify rid = null;
                CreateRasterIdentify(files[0]);
                foreach (string file in files)
                {
                    rid = new RasterIdentify(file);
                    GetOrbitDateTime(rid);
                    GetSatellite(rid);
                    GetSensor(rid);
                    TryGetRegionIdentify(rid);
                    if (!dateFileDic.ContainsKey(rid.OrbitDateTime))
                    {
                        dateFileDic.Add(rid.OrbitDateTime, file);
                    }
                }
                GetMinMaxTime();
                //by chennan 修改积雪天数统计图无法生成问题
                //dateFileDic.Clear();
            }
            GetSortFiles(dateFileDic);
        }
예제 #8
0
        public RasterIdentify CreatRasterIndetifyId(string[] files, string productIdentify, string subProductindentify, DataIdentify di, string format, string extinfo)
        {
            RasterIdentify id = new RasterIdentify(files);

            id.ThemeIdentify      = "CMA";
            id.ProductIdentify    = productIdentify;
            id.SubProductIdentify = subProductindentify;
            id.ExtInfos           = extinfo;
            id.Format             = format;
            if (di == null)
            {
                return(id);
            }
            if (string.IsNullOrEmpty(id.Satellite) || id.Satellite == "NUL")
            {
                id.Satellite = di.Satellite;
            }
            if (string.IsNullOrEmpty(id.Sensor) || id.Sensor == "NUL")
            {
                id.Sensor = di.Sensor;
            }
            if (id.OrbitDateTime == DateTime.MinValue)
            {
                id.OrbitDateTime = di.OrbitDateTime;
            }
            return(id);
        }
        public static IStatResult ItemsToResults(StatResultItem[] items, params string[] arguments)
        {
            if (items == null || items.Length == 0)
            {
                return(null);
            }
            List <IStatResult> results = new List <IStatResult>();

            string[] columns = null;
            if (arguments == null)
            {
                columns = arguments;
            }
            else
            {
                columns = new string[] { "矢量分区", "最大覆盖(平方公里)", "最大覆盖(亩)" }
            };
            List <string[]> names = new List <string[]>();
            List <string>   row;

            foreach (StatResultItem item in items)
            {
                row = new List <string>();
                row.Add(item.Name);
                row.Add(item.Value.ToString());
                row.Add((item.Value * 1500).ToString());
                names.Add(row.ToArray());
            }
            string title = "统计日期:" + DateTime.Now.ToShortDateString();

            //
            if (arguments != null && arguments.Length >= 1)
            {
                string orbitTimes = string.Empty;
                foreach (string item in arguments)
                {
                    if (!File.Exists(item))
                    {
                        break;
                    }
                    RasterIdentify rasterId = new RasterIdentify(item);
                    orbitTimes += rasterId.OrbitDateTime.ToShortDateString() + " ";
                }
                title += "\n" + "轨道时间:" + orbitTimes;
            }
            if (names == null || names.Count == 0)
            {
                return(null);
            }
            else
            {
                return(new StatResult(title, columns, names.ToArray()));
            }
        }
    }
예제 #10
0
 public InterestedRaster(RasterIdentify identify, Size size, CoordEnvelope coordEnvelope)
 {
     if (identify == null)
     {
         throw new ArgumentNullException("identify");
     }
     _identify      = identify;
     _size          = size;
     _coordEnvelope = coordEnvelope;
     BuildInternalBuffer();
 }
예제 #11
0
 private void TryGetRegionIdentify(RasterIdentify rid)
 {
     if (string.IsNullOrEmpty(rid.RegionIdentify) && string.IsNullOrEmpty(RegionIdentify))
     {
         _regionIdentify = "";
     }
     else if ((string.IsNullOrEmpty(rid.RegionIdentify) || string.IsNullOrEmpty(RegionIdentify)) || (rid.RegionIdentify.ToUpper() != RegionIdentify.ToUpper()))
     {
         _regionIdentify = "MULT";
     }
 }
예제 #12
0
        public IExtractResult CompareAnalysisByPixel <T1, T>(string productName, string productIdentify, string extInfos, Func <T1, T1, T> function)
        {
            string[] files = GetStringArray("SelectedPrimaryFiles");
            if (files == null || files.Length == 0 || files.Length == 1)
            {
                return(null);
            }
            //文件列表排序
            string[] dstFiles        = SortFileName(files);
            string   outFileIdentify = GetStringArugment("OutFileIdentify");
            object   obj             = _argumentProvider.GetArg("ThemeGraphyGenerator");

            if (obj == null)
            {
                return(null);
            }
            IThemeGraphGenerator tgg = obj as IThemeGraphGenerator;

            if (tgg == null)
            {
                return(null);
            }
            string             templatName    = GetStringArugment("ThemeGraphTemplateName");
            string             colorTabelName = GetColorTableName("colortablename");
            ExtractResultArray results        = new ExtractResultArray(productIdentify + "_COMP");

            for (int i = 0; i < dstFiles.Length - 1; i++)
            {
                //生成专题图
                IPixelFeatureMapper <T> rasterResult = MakeCompareRaster <T1, T>(productIdentify, dstFiles[i], dstFiles[i + 1], function);
                string aoiTemplateName         = string.Empty;
                Dictionary <string, int[]> aoi = null;
                GetAOI(out aoiTemplateName, out aoi);
                if (rasterResult == null)
                {
                    continue;
                }
                RasterIdentify        rid = new RasterIdentify(dstFiles[i]);
                IInterestedRaster <T> iir = new InterestedRaster <T>(rid, rasterResult.Size, rasterResult.CoordEnvelope, rasterResult.SpatialRef);
                iir.Put(rasterResult);
                iir.Dispose();
                string resultFilename = tgg.Generate(iir.FileName, templatName, MasicAOI(aoi, ref extInfos), extInfos, outFileIdentify, colorTabelName);
                if (string.IsNullOrEmpty(resultFilename))
                {
                    return(null);
                }
                FileExtractResult result = new FileExtractResult(outFileIdentify, resultFilename);
                if (result != null)
                {
                    results.Add(result);
                }
            }
            return(results);
        }
예제 #13
0
        private RasterIdentify GetRasterIdentifOfCurrentFile()
        {
            string         rstFileName = _contextEnvironment.GetContextVar(GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE);
            RasterIdentify rstIdentify = null;

            if (rstFileName != null)
            {
                rstIdentify = new RasterIdentify(rstFileName);
            }
            return(rstIdentify);
        }
예제 #14
0
 public InterestedRaster(RasterIdentify identify, Size size, CoordEnvelope coordEnvelope, ISpatialReference spatialRef, int extHeaderSize)
 {
     if (identify == null)
     {
         throw new ArgumentNullException("identify");
     }
     _identify      = identify;
     _size          = size;
     _extHeaderSize = extHeaderSize;
     _coordEnvelope = coordEnvelope;
     _spatialRef    = spatialRef;
     BuildInternalBuffer();
 }
예제 #15
0
        private object GetOrbitTimes(RasterIdentify rid)
        {
            string defFormat = "yyyy-MM-dd HH:mm:ss";

            if (rid.ObritTiems == null || rid.ObritTiems.Length <= 1)
            {
                return("\\");
            }
            else
            {
                string result = rid.ObritTiems[0].ToString(defFormat) + ";" + rid.ObritTiems[1].ToString(defFormat);
                return(result);
            }
        }
예제 #16
0
        private object GetRegionInfo(RasterIdentify ri, string filename)
        {
            string result     = "\\";
            string regionInfo = string.IsNullOrEmpty(ri.RegionIdentify) ? "" : ri.RegionIdentify;

            if (string.IsNullOrEmpty(regionInfo))
            {
                return(result);
            }
            else if (regionInfo.EndsWith("_"))
            {
                regionInfo = regionInfo.Substring(0, regionInfo.Length - 1);
            }
            return(result.Replace("\\", "") + regionInfo);
        }
예제 #17
0
        private object GetExtInfo(RasterIdentify ri, string filename)
        {
            string result  = "\\";
            string extInfo = string.IsNullOrEmpty(ri.ExtInfos) ? "" : ri.ExtInfos;

            if (string.IsNullOrEmpty(extInfo))
            {
                return(result);
            }
            else if (extInfo.EndsWith("_"))
            {
                extInfo = extInfo.Substring(0, extInfo.Length - 1);
            }
            return(result.Replace("\\", "") + extInfo);
        }
예제 #18
0
 private static int SortByOrbitTime(RasterIdentify fstId, RasterIdentify SedId)
 {
     if (fstId.OrbitDateTime.Equals(SedId.OrbitDateTime))
     {
         return(0);
     }
     else if (fstId.OrbitDateTime > SedId.OrbitDateTime)
     {
         return(1);
     }
     else
     {
         return(-1);
     }
 }
예제 #19
0
        public static string GetWorkspaceFileName(RasterIdentify identify)
        {
            string dir = Path.Combine(MifEnvironment.GetWorkspaceDir(), identify.ProductIdentify);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            dir = Path.Combine(dir, DateTime.Now.ToString("yyyy-MM-dd"));
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            return(identify.ToWksFullFileName(".dat"));
        }
예제 #20
0
        private bool GetOrbitDatetime(string currentRasterFile, out DateTime orbitDatetime)
        {
            //无当前文件,无法获取轨道时间,无法查找基于时间的文件
            orbitDatetime = DateTime.Now;
            if (!argDic.ContainsKey("DAYS") && string.IsNullOrEmpty(currentRasterFile))
            {
                return(false);
            }
            RasterIdentify ri = null;

            if (!string.IsNullOrEmpty(currentRasterFile) && File.Exists(currentRasterFile))
            {
                ri            = new RasterIdentify(currentRasterFile);
                orbitDatetime = ri.OrbitDateTime;
            }
            return(true);
        }
예제 #21
0
        private string[] SortFileName(string[] files)
        {
            List <RasterIdentify> idList = new List <RasterIdentify>();

            foreach (string fileName in files)
            {
                RasterIdentify id = new RasterIdentify(fileName);
                idList.Add(id);
            }
            idList.Sort(SortByOrbitTime);
            List <string> fileList = new List <string>();

            foreach (RasterIdentify id in idList)
            {
                fileList.Add(id.OriFileName[0]);
            }
            return(fileList.ToArray());
        }
예제 #22
0
 private void GetOrbitDateTime(RasterIdentify rid)
 {
     if (_obritTimes == null)
     {
         _obritTimes = new List <DateTime>();
     }
     _obritTimes.Add(rid.OrbitDateTime);
     if (rid.OrbitDateTime.ToString("yyyMMdd") == OrbitDateTime.ToString("yyyyMMdd"))
     {
         return;
     }
     else if (rid.OrbitDateTime.ToString("yyyyMM") == OrbitDateTime.ToString("yyyyMM"))
     {
         OrbitDateTime = DateTime.Parse(rid.OrbitDateTime.ToString("yyyy-MM") + "-01");
     }
     else if (rid.OrbitDateTime.ToString("yyyy") == OrbitDateTime.ToString("yyyy"))
     {
         OrbitDateTime = DateTime.Parse(rid.OrbitDateTime.ToString("yyyy") + "-01-01");
     }
 }
예제 #23
0
 public IInterestedRaster <T> Times(string[] fnames, RasterIdentify rasterIdentify, Func <T, T, T> timesAction)
 {
     return(Times(fnames, rasterIdentify, null, timesAction));
 }
예제 #24
0
        private IInterestedRaster <T> CreateDstRaster(IRasterDataProvider baseRaster, CoordEnvelope dstEnvelope, RasterIdentify rasterIdentify, Size dstSize)
        {
            ////修改不同区域生成结果文件大小不足问题 by chennan 20120806
            //IInterestedRaster<T> dst = new InterestedRaster<T>(rasterIdentify, new Size(baseRaster.Width, baseRaster.Height), dstEnvelope, baseRaster.SpatialRef);
            IInterestedRaster <T> dst = new InterestedRaster <T>(rasterIdentify, new Size(dstSize.Width, dstSize.Height), dstEnvelope, baseRaster.SpatialRef);

            return(dst);
        }
예제 #25
0
        public IInterestedRaster <T> CycleTimes(IRasterDataProvider[] srcRasters, RasterIdentify rasterIdentify, Func <int, T, T, T> iTimesGetter, Action <int, string> progress)
        {
            ////修改不同区域生成结果文件大小不足问题 by chennan 20120806
            //CoordEnvelope dstEnvelope = srcRasters[srcRasters.Length - 1].CoordEnvelope;
            CoordEnvelope dstEnvelope    = GetEnvelopeBySize(srcRasters[srcRasters.Length - 1]);
            float         minResolutionX = 0f;
            float         minResolutionY = 0f;
            Size          dstSize        = Size.Empty;;

            for (int i = 0; i < srcRasters.Length - 1; i++)
            {
                if (srcRasters[i].DataType != srcRasters[i + 1].DataType)
                {
                    throw new ArgumentException("数据类型不一致无法进行频次统计!");
                }
                dstEnvelope = dstEnvelope.Union(GetEnvelopeBySize(srcRasters[i]));
                // by chennan 20120806
                minResolutionX = Math.Min(srcRasters[i].ResolutionX, srcRasters[i + 1].ResolutionX);
                minResolutionY = Math.Min(srcRasters[i].ResolutionY, srcRasters[i + 1].ResolutionY);
                dstSize        = new Size((int)Math.Floor(dstEnvelope.Width / minResolutionX), (int)Math.Floor(dstEnvelope.Height / minResolutionY));
            }
            //by chennan 20121025 修改单文件无法进行周期统计
            if (srcRasters.Length == 1)
            {
                minResolutionX = srcRasters[0].ResolutionX;
                minResolutionY = srcRasters[0].ResolutionY;
                dstEnvelope    = srcRasters[0].CoordEnvelope.Clone();
                dstSize        = new Size(srcRasters[0].Width, srcRasters[0].Height);
            }
            IInterestedRaster <T> dstRaster = CreateDstRaster(srcRasters[0], dstEnvelope, rasterIdentify, dstSize);
            IArgumentProvider     argprd = new ArgumentProvider(new AlgorithmDef());
            int offsetX = 0, offsetY = 0;
            int dstIndex = 0;
            int index = 0;

            foreach (IRasterDataProvider rst in srcRasters)
            {
                if (progress != null)
                {
                    progress((int)(index++ *100f / srcRasters.Length), "正在执行周期统计");
                }
                CoordEnvelope inc = rst.CoordEnvelope.Intersect(dstEnvelope);
                if (inc == null || inc.IsEmpty())
                {
                    continue;
                }
                int iCycle = Array.IndexOf <IRasterDataProvider>(srcRasters, rst) + 1;
                offsetX = (int)((rst.CoordEnvelope.MinX - dstEnvelope.MinX) / rst.ResolutionX);
                offsetY = (int)((dstEnvelope.MaxY - rst.CoordEnvelope.MaxY) / rst.ResolutionY);
                //by chennan 20120806
                IRasterDataProvider dstTempPrd = GetSubPrd <T>(dstRaster.HostDataProvider, rst, rasterIdentify, offsetX, offsetY);
                try
                {
                    IVirtualRasterDataProvider virtualDataProvider = new VirtualRasterDataProvider(new IRasterDataProvider[] { dstTempPrd, rst });
                    argprd.DataProvider = virtualDataProvider;
                    using (IRasterPixelsVisitor <T> visitor = new RasterPixelsVisitor <T>(argprd))
                    {
                        visitor.VisitPixel(new int[] { 1, 2 },
                                           (idx, values) =>
                        {
                            dstIndex = (idx / dstTempPrd.Width + offsetY) * dstRaster.HostDataProvider.Width + (idx % dstTempPrd.Width + offsetX);
                            dstRaster.Put(dstIndex, iTimesGetter(iCycle, values[0], values[1]));
                        });
                    }
                }
                finally
                {
                    dstTempPrd.Dispose();
                    if (File.Exists(dstTempPrd.fileName))
                    {
                        File.Delete(dstTempPrd.fileName);
                    }
                }
            }
            for (int i = 0; i < srcRasters.Length; i++)
            {
                srcRasters[i].Dispose();
            }
            return(dstRaster);
        }
예제 #26
0
 public string NewFileName(RasterIdentify rasterIdentify)
 {
     return(rasterIdentify.ToWksFullFileName(rasterIdentify.Format));
 }
예제 #27
0
        /// <summary>
        /// 覆盖面积:指的是覆盖到的面积,
        /// 累计面积:即累计覆盖面积,相同区域不同时次的累计计算
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rasters"></param>
        /// <param name="rasterTemplate"></param>
        /// <param name="func"></param>
        /// <returns></returns>
        private SortedDictionary <string, StatAreaItem> StatTemplate <T>(IRasterDataProvider[] rasters, IRasterDataProvider typeRaster, Func <T, bool> func, bool isCombinSameDay)
        {
            try
            {
                //01、计算所有输入栅格的的范围并集
                CoordEnvelope maxEnv = UnionEnv(rasters);
                //计算待统计栅格与分类栅格的相交区域,以创建相同的虚拟栅格。
                CoordEnvelope       virtureEnv = maxEnv.Intersect(typeRaster.CoordEnvelope);
                VirtualRasterHeader vHeader    = VirtualRasterHeader.Create(virtureEnv, rasters[0].ResolutionX, rasters[0].ResolutionX);

                VirtualRaster typelate = new VirtualRaster(typeRaster, vHeader);
                int[]         tdata    = typelate.ReadData <int>(1, 0, 0, vHeader.Width, vHeader.Height);


                //2、依据逻辑,计算初步统计结果,这一步对于大数据,可考虑分块处理
                int    calcLength  = vHeader.Width * vHeader.Height * rasters.Length;
                int    dataLength  = vHeader.Width * vHeader.Height;
                byte[] valueCalced = new byte[dataLength];

                SortedDictionary <string, StatAreaItem> result = new SortedDictionary <string, StatAreaItem>();
                if (isCombinSameDay)
                {
                    //预处理同天数据
                    Dictionary <DateTime, List <IRasterDataProvider> > dic = new Dictionary <DateTime, List <IRasterDataProvider> >();
                    foreach (IRasterDataProvider raster in rasters)
                    {
                        if (raster.DataIdentify.OrbitDateTime == DateTime.MinValue)
                        {
                            RasterIdentify identify = new RasterIdentify(raster.fileName);
                            raster.DataIdentify.OrbitDateTime = identify.OrbitDateTime;
                        }
                        List <IRasterDataProvider> lst;
                        if (dic.TryGetValue(raster.DataIdentify.OrbitDateTime, out lst))
                        {
                            dic[raster.DataIdentify.OrbitDateTime].Add(raster);
                        }
                        else
                        {
                            lst = new List <IRasterDataProvider>();
                            lst.Add(raster);
                            dic.Add(raster.DataIdentify.OrbitDateTime, lst);
                        }
                    }
                    foreach (DateTime dateKey in dic.Keys)
                    {
                        IRasterDataProvider[] rastersSameDay = dic[dateKey].ToArray();
                        if (rastersSameDay.Length == 1 || dateKey == DateTime.MinValue)
                        {
                            for (int i = 0; i < rastersSameDay.Length; i++)
                            {
                                VirtualRaster vRaster = new VirtualRaster(rastersSameDay[i], vHeader);
                                T[]           datas   = vRaster.ReadData <T>(1, 0, 0, vHeader.Width, vHeader.Height);
                                for (int j = 0; j < dataLength; j++)
                                {
                                    UpdateProgress((int)((j + (i * dataLength)) * 100f / calcLength), "正在计算统计数据");
                                    if (func(datas[j]))
                                    {
                                        string key = tdata[j].ToString();
                                        if (result.ContainsKey(key))//累计计数
                                        {
                                            result[key].GrandTotal += 1;
                                        }
                                        else
                                        {
                                            result.Add(key, new StatAreaItem()
                                            {
                                                GrandTotal = 1
                                            });
                                        }
                                        if (valueCalced[j] == 0)//覆盖计数
                                        {
                                            valueCalced[j]     = 1;
                                            result[key].Cover += 1;
                                        }
                                    }
                                }
                            }
                        }
                        else//同天数据处理,
                        {
                            byte[] sameDayCalced = new byte[vHeader.Width * vHeader.Height];
                            for (int i = 0; i < rasters.Length; i++)
                            {
                                VirtualRaster vRaster = new VirtualRaster(rasters[i], vHeader);
                                T[]           datas   = vRaster.ReadData <T>(1, 0, 0, vHeader.Width, vHeader.Height);
                                for (int j = 0; j < dataLength; j++)
                                {
                                    UpdateProgress((int)((j + (i * dataLength)) * 100f / calcLength), "正在计算统计数据");
                                    if (func(datas[j]))
                                    {
                                        if (sameDayCalced[j] == 0)//
                                        {
                                            sameDayCalced[j] = 1;
                                            string key = tdata[j].ToString();
                                            if (result.ContainsKey(key))//累计计数
                                            {
                                                result[key].GrandTotal += 1;
                                            }
                                            else
                                            {
                                                result.Add(key, new StatAreaItem()
                                                {
                                                    GrandTotal = 1
                                                });
                                            }
                                            if (valueCalced[j] == 0)//覆盖计数
                                            {
                                                valueCalced[j]     = 1;
                                                result[key].Cover += 1;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < rasters.Length; i++)
                    {
                        VirtualRaster vRaster = new VirtualRaster(rasters[i], vHeader);
                        T[]           datas   = vRaster.ReadData <T>(1, 0, 0, vHeader.Width, vHeader.Height);
                        for (int j = 0; j < dataLength; j++)
                        {
                            UpdateProgress((int)((j + (i * dataLength)) * 100f / calcLength), "正在计算统计数据");
                            if (func(datas[j]))
                            {
                                string key = tdata[j].ToString();
                                if (result.ContainsKey(key))//累计计数
                                {
                                    result[key].GrandTotal += 1;
                                }
                                else
                                {
                                    result.Add(key, new StatAreaItem()
                                    {
                                        GrandTotal = 1
                                    });
                                }
                                if (valueCalced[j] == 0)//覆盖计数
                                {
                                    valueCalced[j]     = 1;
                                    result[key].Cover += 1;
                                }
                            }
                        }
                    }
                }

                double perAreas = AreaCountHelper.CalcArea(vHeader.CoordEnvelope.Center.X, vHeader.CoordEnvelope.Center.Y, vHeader.ResolutionX, vHeader.ResolutionY) * Math.Pow(10, -6);
                foreach (string key in result.Keys)
                {
                    result[key].GrandTotal *= perAreas;
                    result[key].Cover      *= perAreas;
                }
                return(result);
            }
            finally
            {
                UpdateProgress(100, "统计数据计算完毕");
            }
        }
예제 #28
0
 public IInterestedRaster <T> Compare(int[] aoi, string raster1, string raster2, Func <T, T, T> comparer, RasterIdentify rasterIdentify)
 {
     throw new NotImplementedException();
 }
예제 #29
0
        public string[] GetNeedFirstSettedArguments(string beginSubProduct)
        {
            List <string> needFirstSettedArgs = new List <string>();
            List <string> initedArgs          = new List <string>();
            SubProductDef firstSubProduct     = _monitoringProduct.Definition.GetSubProductDefByIdentify(beginSubProduct);

            if (firstSubProduct != null && firstSubProduct.IsNeedCurrentRaster)
            {
                needFirstSettedArgs.Add(GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE);
            }
            if (_monitoringProduct.SubProducts != null)
            {
                string         rstFileName = _contextEnvironment.GetContextVar(GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE);
                RasterIdentify rstIdentify = new RasterIdentify();
                if (rstFileName != null)
                {
                    rstIdentify = new RasterIdentify(rstFileName);
                    initedArgs.Add(GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE);
                }
                foreach (IMonitoringSubProduct subprd in _monitoringProduct.SubProducts)
                {
                    AlgorithmDef alg = subprd.Definition.Algorithms[0];
                    if (subprd.Definition.IsNeedCurrentRaster && subprd.Definition.Algorithms.Count() > 0)
                    {
                        ExtractAlgorithmIdentify id = new ExtractAlgorithmIdentify();
                        id.Satellite = rstIdentify.Satellite;
                        id.Sensor    = rstIdentify.Sensor;
                        alg          = subprd.Definition.GetAlgorithmDefByAlgorithmIdentify(id);
                        if (alg == null)
                        {
                            alg = subprd.Definition.Algorithms[0];
                        }
                    }
                    //子产品不存在实例
                    if (subprd.Definition.SubProductInstanceDefs == null)
                    {
                        foreach (ArgumentDef arg in alg.Arguments.Where((a) => { return(a is ArgumentDef); }))
                        {
                            if (arg.IsOptional)
                            {
                                continue;
                            }
                            if (arg.RefType == "file" && arg.FileProvider == null)
                            {
                                if (!needFirstSettedArgs.Contains(arg.Name))
                                {
                                    needFirstSettedArgs.Add(arg.Name);
                                }
                            }
                            else if (arg.RefType == "file")
                            {
                                if (arg.FileProvider.Contains("ContextEnvironment:"))
                                {
                                    string[] parts = arg.FileProvider.Split(':');
                                    if (!initedArgs.Contains(parts[1]) && !needFirstSettedArgs.Contains(parts[1]))
                                    {
                                        needFirstSettedArgs.Add(parts[1]);
                                    }
                                }
                            }
                        }
                    }
                    //子产品有实例
                    else
                    {
                        foreach (SubProductInstanceDef ist in subprd.Definition.SubProductInstanceDefs)
                        {
                            if (ist.FileProvider.Contains("ContextEnvironment:"))
                            {
                                string[] parts = ist.FileProvider.Split(':');
                                if (!initedArgs.Contains(parts[1]) && !needFirstSettedArgs.Contains(parts[1]))
                                {
                                    needFirstSettedArgs.Add(parts[1]);
                                }
                            }
                        }
                    }
                    //
                    initedArgs.Add(subprd.Identify);
                }
            }
            return(needFirstSettedArgs.Count > 0 ? needFirstSettedArgs.ToArray() : null);
        }
예제 #30
0
        private void MakeSubProduct(string preBanks, IMonitoringSubProduct subprd, IContextMessage contextMessage, IArgumentMissProcessor argumentMissProcessor, string executeGroup, Action <int, string> processTracker)
        {
            bool isCreatDataProvider   = false;
            IRasterDataProvider raster = null;

            try
            {
                subprd.ArgumentProvider.Reset();
                subprd.ArgumentProvider.AOI = null;
                AlgorithmDef   alg         = subprd.AlgorithmDefs[0];
                RasterIdentify rstIdentify = null;
                rstIdentify = GetRasterIdentifOfCurrentFile();
                if (subprd.Definition.IsNeedCurrentRaster)
                {
                    string rstFileName = _contextEnvironment.GetContextVar(GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE);
                    raster = GeoDataDriver.Open(rstFileName) as IRasterDataProvider;
                    subprd.ArgumentProvider.DataProvider = raster;
                    isCreatDataProvider = true;
                    //
                    TryApplyAOITemplates(subprd);
                    //
                    if (rstIdentify == null)
                    {
                        if (contextMessage != null)
                        {
                            contextMessage.PrintMessage("参数\"" + GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE + "\"为空!");
                        }
                        if (argumentMissProcessor == null)
                        {
                            return;
                        }
                        string crtFileName = argumentMissProcessor.DoGettingArgument(subprd.Definition, subprd.UseDefaultAlgorithm(subprd.Definition.ProductDef.Identify), GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE);
                        if (crtFileName == null)
                        {
                            return;
                        }
                        rstIdentify = new RasterIdentify(crtFileName);
                        _contextEnvironment.PutContextVar(GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE, crtFileName);
                    }
                    ExtractAlgorithmIdentify id = new ExtractAlgorithmIdentify();
                    id.Satellite = rstIdentify.Satellite;
                    id.Sensor    = rstIdentify.Sensor;
                    alg          = subprd.Definition.GetAlgorithmDefByAlgorithmIdentify(id);
                    if (alg == null)
                    {
                        alg = subprd.Definition.Algorithms[0];
                    }
                }
                subprd.ResetArgumentProvider(alg.Identify);
                subprd.ArgumentProvider.SetArg("AlgorithmName", alg.Identify);
                if (alg.Bands != null && alg.Bands.Length > 0)
                {
                    MonitoringThemeFactory.SetBandArgs(subprd, rstIdentify.Satellite, rstIdentify.Sensor);
                    foreach (BandDef band in alg.Bands)
                    {
                        if (subprd.ArgumentProvider.GetArg(band.Identify).ToString() == "-1")
                        {
                            if (contextMessage != null)
                            {
                                contextMessage.PrintMessage(preBanks + "从波段映射表获取\"" + band.Identify + "\"的波段序号失败,生成过程终止!");
                            }
                            return;
                        }
                    }
                }
                //
                TryHandleCustomArguments(subprd.ArgumentProvider, alg);
                //
                if (subprd.Definition.SubProductInstanceDefs != null)
                {
                    MakeSubProductUseInstances(preBanks + "  ", subprd, alg, contextMessage, argumentMissProcessor, executeGroup, processTracker);
                }
                else
                {
                    DirectMakeSubProduct(preBanks + "  ", subprd, alg, contextMessage, argumentMissProcessor, processTracker);
                }
            }
            finally
            {
                if (raster != null)
                {
                    raster.Dispose();
                    raster = null;
                }
                if (subprd.ArgumentProvider.DataProvider != null && isCreatDataProvider)
                {
                    subprd.ArgumentProvider.DataProvider.Dispose();
                }
            }
        }