コード例 #1
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);
        }
コード例 #2
0
        public IInterestedRaster <T> Times(IRasterDataProvider[] srcRasters, RasterIdentify rasterIdentify, Action <int, string> progressTracker, Func <T, T, T> timesAction)
        {
            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]));
                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.Round(dstEnvelope.Width / minResolutionX), (int)Math.Round(dstEnvelope.Height / minResolutionY));
            }
            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;

            if (progressTracker != null)
            {
                progressTracker(0, "开始进行统计...");
            }
            int num = 0;

            foreach (IRasterDataProvider rst in srcRasters)
            {
                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, timesAction(values[0], values[1]));
                        });
                    }
                    num++;
                    int persent = (int)(num * 100f / srcRasters.Length);
                    if (progressTracker != null)
                    {
                        progressTracker(persent, "统计完成" + persent + "%");
                    }
                }
                finally
                {
                    dstTempPrd.Dispose();
                    if (File.Exists(dstTempPrd.fileName))
                    {
                        File.Delete(dstTempPrd.fileName);
                    }
                }
                if (progressTracker != null)
                {
                    progressTracker(100, "统计完成");
                }
            }
            for (int i = 0; i < srcRasters.Length; i++)
            {
                srcRasters[i].Dispose();
            }
            return(dstRaster);
        }