示例#1
0
        private void ApplyAOI(IRasterDataProvider prd, IMonitoringSubProduct subprd)
        {
            if (!subprd.Definition.IsUseAoiTemplate || prd == null)
            {
                return;
            }
            string aoistring = subprd.Definition.AoiTemplates;

            if (string.IsNullOrEmpty(aoistring))
            {
                return;
            }
            string[]      aoiNames = aoistring.Split(',');
            CoordEnvelope evp      = prd.CoordEnvelope;
            Size          size     = new Size(prd.Width, prd.Height);

            int[] retAOI = null;
            foreach (string aoiName in aoiNames)
            {
                int[] aoi = AOITemplateFactory.MakeAOI(aoiName, evp.MinX, evp.MaxX, evp.MinY, evp.MaxY, size);
                if (retAOI == null)
                {
                    retAOI = aoi;
                }
                else
                {
                    retAOI = AOIHelper.Merge(new int[][] { retAOI, aoi });
                }
            }
            subprd.ArgumentProvider.AOI = retAOI;
        }
示例#2
0
        public void VisitPixelWnd(int[] bandNos, int[] wndBandNos, int minWndSize, int maxWndSize, Func <int, int, T[], T[][], bool> isNeedIncWndSize, Action <int, int, T[], T[][]> extractAction)
        {
            if (extractAction == null || wndBandNos == null || wndBandNos.Length == 0)
            {
                return;
            }
            Rectangle rect = AOIHelper.ComputeAOIRect(_argProvider.AOI, new Size(_argProvider.DataProvider.Width, _argProvider.DataProvider.Height));

            int[] aoi = _argProvider.AOI;
            VisitPixelWnd(rect, aoi, bandNos, wndBandNos, minWndSize, maxWndSize, isNeedIncWndSize, extractAction);
        }
示例#3
0
        public void VisitPixel(int[] bandNos, Action <int, T[]> extractAction)
        {
            if (extractAction == null)
            {
                return;
            }
            if (bandNos == null || bandNos.Length == 0)
            {
                bandNos = GetAllBandNo();
            }
            Rectangle rect = AOIHelper.ComputeAOIRect(_argProvider.AOI, new Size(_argProvider.DataProvider.Width, _argProvider.DataProvider.Height));

            int[] aoi = _argProvider.AOI;
            VisitPixel(rect, aoi, bandNos, extractAction);
        }
示例#4
0
 public int[] GetAOI(Envelope dstEnvelope, Size size)
 {
     ShapePolygon[] geometrys = GetGeometry(null, null);
     if (geometrys == null || geometrys.Length == 0)
     {
         return(null);
     }
     using (IVectorAOIGenerator gen = new VectorAOIGenerator())
     {
         int[] aoi = gen.GetAOI(geometrys, dstEnvelope, size);
         if (_isReverse)
         {
             return(AOIHelper.Reverse(aoi, size));
         }
         return(aoi);
     }
 }
示例#5
0
        private void StatAreaUseAOI(byte[] adminRaster, byte[] landuseRaster, IRasterDataProvider dataProvider, double[,] result, int[] aoi, Func <T, int, int> weight)
        {
            ArgumentProvider arg = new ArgumentProvider(dataProvider, null)
            {
                AOI = aoi
            };

            using (IRasterPixelsVisitor <T> v = new RasterPixelsVisitor <T>(arg))
            {
                Rectangle aoiRect = AOIHelper.ComputeAOIRect(aoi, new Size(dataProvider.Width, dataProvider.Height));
                v.VisitPixel(aoiRect, aoi, new int[] { 1 },
                             (idx, bandValues) =>
                {
                    result[adminRaster[idx], landuseRaster[idx]] += weight(bandValues[0], idx);
                }
                             );
            }
        }
示例#6
0
        public int[] Filter(IRasterDataProvider dataProvider, int[] aoi, Action <string> contextMessage)
        {
            if (_filters == null || _filters.Count == 0)
            {
                return(null);
            }
            Size      size = new Size(dataProvider.Width, dataProvider.Height);
            Rectangle rect = AOIHelper.ComputeAOIRect(aoi, size);

            int[] rolledAOI = aoi;
            foreach (ICandidatePixelFilter filter in _filters)
            {
                if (filter != null && filter.IsEnabled && !filter.IsFiltered)
                {
                    if (contextMessage != null)
                    {
                        contextMessage("正在执行\"" + (filter.Name ?? filter.ToString()) + "\"...");
                    }
                    rolledAOI = filter.Filter(dataProvider, rect, rolledAOI);
                    rect      = AOIHelper.ComputeAOIRect(rolledAOI, size);
                }
            }
            return(rolledAOI);
        }
示例#7
0
        public void VisitPixel(Rectangle aoiRect, int[] aoi, int[] bandNos, Action <int, T[]> extractAction)
        {
            IRasterBand[] bands    = GetRasterBands(bandNos);
            T[][]         buffers  = BuildBuffers(aoiRect, bandNos.Length);
            enumDataType  dataType = _argProvider.DataProvider.DataType;
            int           width    = _argProvider.DataProvider.Width;

            T[] pixelBuffer = new T[bandNos.Length];
            int oIdx = 0, idx = 0;

            GCHandle[] handles = GetHandles(buffers);
            try
            {
                if (aoi == null || aoi.Length == 0)
                {
                    for (int r = aoiRect.Top; r < aoiRect.Bottom; r++, oIdx = r * width, idx = 0)
                    {
                        for (int bIdx = 0; bIdx < bands.Length; bIdx++)
                        {
                            bands[bIdx].Read(aoiRect.Left, r, aoiRect.Width, 1, handles[bIdx].AddrOfPinnedObject(), dataType, aoiRect.Width, 1);
                        }
                        oIdx += aoiRect.Left;
                        for (int c = aoiRect.Left; c < aoiRect.Width; c++, oIdx++, idx++)
                        {
                            for (int bIdx = 0; bIdx < bands.Length; bIdx++)
                            {
                                pixelBuffer[bIdx] = buffers[bIdx][idx];
                            }
                            extractAction(oIdx, pixelBuffer);
                        }
                    }
                }
                else
                {
                    Dictionary <int, AOIHelper.AOIRowRange> aoirows = AOIHelper.ComputeRowIndexRange(aoi, new Size(_argProvider.DataProvider.Width, _argProvider.DataProvider.Height));
                    foreach (int r in aoirows.Keys)
                    {
                        for (int bIdx = 0; bIdx < bands.Length; bIdx++)
                        {
                            bands[bIdx].Read(aoiRect.Left, r, aoiRect.Width, 1, handles[bIdx].AddrOfPinnedObject(), dataType, aoiRect.Width, 1);
                        }
                        idx = 0;
                        AOIHelper.AOIRowRange range = aoirows[r];
                        for (int aoiidx = range.BeginIndex; aoiidx < range.EndIndex; aoiidx++)
                        {
                            oIdx = aoi[aoiidx];
                            int orow = oIdx / width;
                            int ocol = oIdx - orow * width;
                            for (int bIdx = 0; bIdx < bands.Length; bIdx++)
                            {
                                pixelBuffer[bIdx] = buffers[bIdx][ocol - aoiRect.Left];
                            }
                            extractAction(oIdx, pixelBuffer);
                        }
                    }
                }
            }
            finally
            {
                FreeHandles(handles);
            }
        }
示例#8
0
        public void VisitPixelWnd(Rectangle aoiRect, int[] aoi, int[] bandNos, int[] wndBandNos, int minWndSize, int maxWndSize, Func <int, int, T[], T[][], bool> isNeedIncWndSize, Action <int, int, T[], T[][]> extractAction)
        {
            _wndAccessor.Reset(wndBandNos, aoiRect);
            int crtWndSize = minWndSize;

            IRasterBand[] bands    = GetRasterBands(bandNos);
            T[][]         buffers  = BuildBuffers(aoiRect, bandNos.Length);
            enumDataType  dataType = _argProvider.DataProvider.DataType;
            int           width    = _argProvider.DataProvider.Width;

            T[]   pixelBuffer = new T[bandNos.Length];
            T[][] wndBuffers  = new T[wndBandNos.Length][];
            BuildWndBuffers(crtWndSize, wndBuffers);
            int oIdx = 0, idx = 0;

            GCHandle[] handles = GetHandles(buffers);
            try
            {
                if (aoi == null || aoi.Length == 0)
                {
                    for (int r = aoiRect.Top; r < aoiRect.Bottom; r++, oIdx = r * width, idx = 0)
                    {
                        for (int bandIdx = 0; bandIdx < bands.Length; bandIdx++)
                        {
                            bands[bandIdx].Read(aoiRect.Left, r, aoiRect.Width, 1, handles[bandIdx].AddrOfPinnedObject(), dataType, aoiRect.Width, 1);
                        }
                        oIdx += aoiRect.Left;
                        for (int c = aoiRect.Left; c < aoiRect.Width; c++, oIdx++, idx++)
                        {
                            for (int bIdx = 0; bIdx < bands.Length; bIdx++)
                            {
                                pixelBuffer[bIdx] = buffers[bIdx][idx];
                            }
                            //
                            if (!_wndAccessor.ReadWndPixels(oIdx, crtWndSize, wndBuffers))
                            {
                                continue;
                            }
                            while (isNeedIncWndSize(oIdx, crtWndSize, pixelBuffer, wndBuffers) && crtWndSize < maxWndSize)
                            {
                                crtWndSize += 2;//1,3,5,7,9,...
                                BuildWndBuffers(crtWndSize, wndBuffers);
                                //目前这里有个bug,扩大窗口后,没有为wndBuffers赋值,但是直接在这里读取的话,程序速度会很慢。
                            }
                            //by chennan 20121226修改火点判识与一期不一致问题
                            crtWndSize = minWndSize;
                            BuildWndBuffers(crtWndSize, wndBuffers);
                            _wndAccessor.ReadWndPixels(oIdx, crtWndSize, wndBuffers);
                            //
                            extractAction(oIdx, crtWndSize, pixelBuffer, wndBuffers);
                        }
                    }
                }
                else
                {
                    Dictionary <int, AOIHelper.AOIRowRange> aoirows = AOIHelper.ComputeRowIndexRange(aoi, new Size(_argProvider.DataProvider.Width, _argProvider.DataProvider.Height));
                    foreach (int r in aoirows.Keys)
                    {
                        for (int bIdx = 0; bIdx < bands.Length; bIdx++)
                        {
                            bands[bIdx].Read(aoiRect.Left, r, aoiRect.Width, 1, handles[bIdx].AddrOfPinnedObject(), dataType, aoiRect.Width, 1);
                        }
                        idx = 0;
                        AOIHelper.AOIRowRange range = aoirows[r];
                        for (int aoiidx = range.BeginIndex; aoiidx < range.EndIndex; aoiidx++)
                        {
                            oIdx = aoi[aoiidx];
                            int orow = oIdx / width;
                            int ocol = oIdx - orow * width;
                            for (int bIdx = 0; bIdx < bands.Length; bIdx++)
                            {
                                pixelBuffer[bIdx] = buffers[bIdx][ocol - aoiRect.Left];
                            }
                            //
                            if (!_wndAccessor.ReadWndPixels(oIdx, crtWndSize, wndBuffers))
                            {
                                continue;
                            }
                            while (isNeedIncWndSize(oIdx, crtWndSize, pixelBuffer, wndBuffers) && crtWndSize < maxWndSize)
                            {
                                crtWndSize += 2;
                                BuildWndBuffers(crtWndSize, wndBuffers);
                                ////by chennan 高温火点窗口数据读取
                                //_wndAccessor.ReadWndPixels(oIdx, crtWndSize-2, wndBuffers);
                                //目前这里有个bug,扩大窗口后,没有为wndBuffers赋值,但是直接在这里读取的话,程序速度会很慢。
                            }
                            //by chennan 20121226修改火点判识与一期不一致问题
                            crtWndSize = minWndSize;
                            BuildWndBuffers(crtWndSize, wndBuffers);
                            _wndAccessor.ReadWndPixels(oIdx, crtWndSize, wndBuffers);
                            //
                            extractAction(oIdx, crtWndSize, pixelBuffer, wndBuffers);
                        }
                    }
                }
            }
            finally
            {
                FreeHandles(handles);
            }
        }