Пример #1
0
 public void GetArgs(out BlockDefWithAOI envelope, out Size size, out string dir, out string inputFilename)
 {
     envelope      = new BlockDefWithAOI(_blockName, ucGeoRangeControl1.MinX, ucGeoRangeControl1.MinY, ucGeoRangeControl1.MaxX, ucGeoRangeControl1.MaxY);
     size          = new Size((int)txtWidth.Value, (int)txtHeight.Value);
     dir           = txtOutFile.Text;
     inputFilename = txtInputFile.Text;
 }
Пример #2
0
        private void GetArgs(out BlockDefWithAOI envelope, out Size size)//, out string dir, out string inputFilename)
        {
            envelope = new BlockDefWithAOI(_blockName, evp.MinX, evp.MinY, evp.MaxX, evp.MaxY);
            Size aoiSize = new Size((int)GetInteger(((evp.MaxX - evp.MinX) / _resolutionX), _resolutionX),
                                    (int)GetInteger(((evp.MaxY - evp.MinY) / _resolutionY), _resolutionY));

            size = new Size((int)aoiSize.Width, aoiSize.Height);
        }
Пример #3
0
        public void ClipFile(string xmlfile)
        {
            RasterClip             clip      = new RasterClip();
            InputArgs              input     = GetConfigByXml(xmlfile);
            List <BlockDefWithAOI> blocklist = new List <BlockDefWithAOI>();

            for (int i = 0; i < input.ListCoord.Count; i++)
            {
                BlockDefWithAOI blo = new BlockDefWithAOI(input.ListCoord[i].CoordName, input.ListCoord[i].MinX, input.ListCoord[i].MinY, input.ListCoord[i].MaxX, input.ListCoord[i].MaxY);
                blocklist.Add(blo);
            }

            foreach (string itemfile in input.ListInputFiles)
            {
                Console.WriteLine(string.Format("正在裁切:{0}", itemfile));
                clip.RasterClipT(itemfile, blocklist.ToArray(), input.OutDir, null, "Cut");
            }
        }
Пример #4
0
        public override void Execute()
        {
            try
            {
                List <string> _cutfiles = new List <string>();
                base.Execute();
                RasterClip             s = new RasterClip();
                BlockDefWithAOI[]      envelopes;
                string                 inputFilename = TryGetInfoFromActiveView(out envelopes);
                string                 outdir        = Path.GetDirectoryName(inputFilename);
                int[]                  aoiIndex      = null;
                List <BlockDefWithAOI> blockList     = new List <BlockDefWithAOI>();
                frmImageClip           frm           = new frmImageClip(_smartSession);
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    _cutfiles.AddRange(frm.InputFiles);
                    _cutfiles.AddRange(frm.CustomSelectFiles);
                    BlockDefWithAOI outEnvelope;
                    Size            size;
                    frm.GetArgs(out outEnvelope, out size, out outdir, out inputFilename);
                    envelopes = new BlockDefWithAOI[] { outEnvelope };
                    aoiIndex  = frm.GetFeatureAOIIndex();
                    blockList.AddRange(envelopes);
                    if (aoiIndex != null && aoiIndex.Length != 0)
                    {
                        blockList[0].AOIIndexes = aoiIndex;
                    }
                }
                else
                {
                    return;
                }
                if (blockList[0].AOIIndexes == null)
                {
                    blockList[0].AOIIndexes = _smartSession.SmartWindowManager.ActiveCanvasViewer.AOIProvider.GetIndexes();
                }
                string[] put = s.RasterClipT(inputFilename, blockList.ToArray(), outdir, _smartSession.ProgressMonitorManager.DefaultProgressMonitor, "Cut");
                _cutfiles = _cutfiles.Distinct().ToList();
                foreach (string file in _cutfiles)
                {
                    s.RasterClipT(file, blockList.ToArray(), outdir, _smartSession.ProgressMonitorManager.DefaultProgressMonitor, "Cut");
                }
                ISmartViewer         viewer        = _smartSession.SmartWindowManager.ActiveViewer;
                int[]                selectBands   = null;
                List <IRgbProcessor> rgbProcessors = null;
                if (viewer != null)
                {
                    ICanvasViewer canViewer = viewer as ICanvasViewer;
                    if (canViewer == null)
                    {
                        return;
                    }
                    IRasterDrawing rd = canViewer.ActiveObject as IRasterDrawing;
                    if (rd == null || rd.RgbProcessorStack == null)
                    {
                        return;
                    }

                    rgbProcessors = new List <IRgbProcessor>();
                    foreach (IRgbProcessor processor in rd.RgbProcessorStack.Processors)
                    {
                        rgbProcessors.Add(processor);
                    }
                    rgbProcessors.Reverse();
                    selectBands = rd.SelectedBandNos;
                }
                for (int i = 0; i < put.Length; i++)
                {
                    OpenFileToWindows(put[i]);
                    if (selectBands == null)
                    {
                        continue;
                    }
                    IRasterDrawing draw = _smartSession.SmartWindowManager.ActiveViewer.ActiveObject as IRasterDrawing;
                    draw.SelectedBandNos = selectBands;
                    if (rgbProcessors != null && rgbProcessors.Count > 0)
                    {
                        draw.RgbProcessorStack.Clear();
                        foreach (IRgbProcessor processor in rgbProcessors)
                        {
                            draw.RgbProcessorStack.Process(processor);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Пример #5
0
        public IRasterDataProvider Cut(IRasterDataProvider srcRaster, BlockDefWithAOI blockDefsAoi, int samplePercent, string driver, string outdir, Action <int, string> progressCallback, params object[] options)
        {
            IRasterDataProvider tProviders;

            if (progressCallback != null)
            {
                progressCallback(0, "开始数据裁切");
            }
            if (blockDefsAoi == null)
            {
                return(null);
            }
            //位置映射参数
            int           tBeginRow = -1, tEndRow = -1, tBeginCol = -1, tEndCol = -1;
            int           oBeginRow = -1, oEndRow = -1, oBeginCol = -1, oEndCol = -1;
            CoordEnvelope oEnvelope = srcRaster.CoordEnvelope;
            CoordEnvelope tEnvelope = blockDefsAoi.ToEnvelope();
            Size          oSize     = new Size(srcRaster.Width, srcRaster.Height);
            Size          tSize     = ClipCutHelper.GetTargetSize(blockDefsAoi, srcRaster.ResolutionX, srcRaster.ResolutionY);
            //Size tSize = GetTargetSize(blockDefsAoi, srcRaster.ResolutionX, srcRaster.ResolutionY);
            bool   isInternal    = new RasterMoasicClipHelper().ComputeBeginEndRowCol(oEnvelope, oSize, tEnvelope, tSize, ref oBeginRow, ref oBeginCol, ref oEndRow, ref oEndCol, ref tBeginRow, ref tBeginCol, ref tEndRow, ref tEndCol);
            string blockFilename = ClipCutHelper.GetBlockFilename(blockDefsAoi, srcRaster.fileName, outdir, driver);

            tSize = new Size(oEndCol - oBeginCol, oEndRow - oBeginRow);
            IRasterDataDriver rasterDriver = GeoDataDriver.GetDriverByName(driver) as IRasterDataDriver;
            int   oWidth  = 0;
            int   oHeight = 0;
            float tResolutionX;
            float tResolutionY;

            if (samplePercent > 0 && samplePercent < 100)
            {
                oHeight      = (int)(tSize.Width * samplePercent * 1f / 100 + 0.5);
                oWidth       = (int)(tSize.Width * samplePercent * 1f / 100 + 0.5);
                tResolutionX = srcRaster.ResolutionX * samplePercent * 1f / 100;
                tResolutionY = srcRaster.ResolutionY * samplePercent * 1f / 100;
            }
            else
            {
                oHeight      = tSize.Height;
                oWidth       = tSize.Width;
                tResolutionX = srcRaster.ResolutionX;
                tResolutionY = srcRaster.ResolutionY;
            }
            string[] optionString = new string[] {
                "INTERLEAVE=BSQ",
                "VERSION=LDF",
                "WITHHDR=TRUE",
                "SPATIALREF=" + srcRaster.SpatialRef.ToProj4String(),
                "MAPINFO={" + 1 + "," + 1 + "}:{" + tEnvelope.MinX + "," + tEnvelope.MaxY + "}:{" + tResolutionX + "," + tResolutionY + "}"
            };
            tProviders = rasterDriver.Create(blockFilename, oWidth, oHeight, srcRaster.BandCount, srcRaster.DataType, optionString);
            tProviders.GetRasterBand(1).Fill(-999.0f);
            int[] oAoi      = ClipCutHelper.GetOffsetIndex(blockDefsAoi.AOIIndexes, oBeginRow, oBeginCol, srcRaster.Width, oWidth);
            int   rowStep   = ClipCutHelper.ComputeRowStep(srcRaster, oBeginRow, oEndRow);
            int   stepCount = (int)((oEndRow - oBeginRow) / rowStep + 0.5) * srcRaster.BandCount;
            int   step      = 0;
            int   percent   = 0;

            for (int oRow = oBeginRow; oRow < oEndRow; oRow += rowStep)
            {
                if (oRow + rowStep > oEndRow)
                {
                    rowStep = oEndRow - oRow;
                }
                for (int bandIndex = 1; bandIndex <= srcRaster.BandCount; bandIndex++)
                {
                    step++;
                    percent = (int)(step * 1.0f / stepCount * 100);
                    if (progressCallback != null)
                    {
                        progressCallback(percent, "完成数据裁切" + percent + "%");
                    }

                    int    sample     = (oEndCol - oBeginCol);
                    int    typeSize   = ClipCutHelper.GetSize(srcRaster.DataType);
                    int    bufferSize = sample * rowStep * typeSize;
                    byte[] databuffer = new byte[bufferSize];
                    unsafe
                    {
                        fixed(byte *ptr = databuffer)
                        {
                            IntPtr buffer = new IntPtr(ptr);

                            srcRaster.GetRasterBand(bandIndex).Read(oBeginCol, oRow, sample, rowStep, buffer, srcRaster.DataType, sample, rowStep);
                            //byte[] dataNewBf = ClipCutHelper.WriteValueToBuffer(databuffer, oAoi, typeSize);
                            byte[] dataNewBf = WriteValueToBuffer(databuffer, oAoi, typeSize);
                            fixed(byte *p = dataNewBf)
                            {
                                IntPtr newBuffer = new IntPtr(p);

                                if (samplePercent > 0 && samplePercent < 100)
                                {
                                    //tProviders.GetRasterBand(1).Fill(999.0d);
                                    tProviders.GetRasterBand(bandIndex).Write((int)(tBeginCol * samplePercent * 1f / 100 + 0.5), (int)((tBeginRow + (oRow - oBeginRow)) * samplePercent * 1f / 100 + 0.5), (int)(sample * samplePercent * 1f / 100 + 0.5), (int)(rowStep * samplePercent * 1f / 100 + 0.5), newBuffer, srcRaster.DataType, (int)(sample * samplePercent * 1f / 100 + 0.5), (int)(rowStep * samplePercent * 1f / 100 + 0.5));
                                }
                                else
                                {
                                    //tProviders.GetRasterBand(1).Fill(999.0d);
                                    tProviders.GetRasterBand(bandIndex).Write(tBeginCol, tBeginRow + (oRow - oBeginRow), sample, rowStep, newBuffer, srcRaster.DataType, sample, rowStep);
                                }
                            }
                        }
                    }
                }
            }
            if (tProviders != null)
            {
                tProviders.Dispose();
            }
            return(tProviders);
        }