Example #1
0
        private void CheckArgIsOK(IRasterDataProvider dataProvider, CutArgument args)
        {
            if (dataProvider == null)
            {
                throw new ArgumentNullException("dataProvider");
            }
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            string error = null;

            if (!args.IsOK(out error))
            {
                throw new ArgumentException(error);
            }
            if (args.BandNos == null)
            {
                args.BandNos = new int[dataProvider.BandCount];
                for (int b = 1; b <= dataProvider.BandCount; b++)
                {
                    args.BandNos[b - 1] = b;
                }
            }
            else
            {
                foreach (int bNo in args.BandNos)
                {
                    if (bNo < 1 || bNo > dataProvider.BandCount)
                    {
                        throw new ArgumentOutOfRangeException("BandNos");
                    }
                }
            }
        }
Example #2
0
        private object[] GetOptions(IRasterDataProvider dataProvider, CutArgument args, BlockItem item, out string extName, CoordEnvelope evp)
        {
            extName = null;
            List <object> options = new List <object>();

            if (args.Driver == "LDF")
            {
                extName = ".ldf";
                if (dataProvider.SpatialRef != null)
                {
                    string spRef = "SPATIALREF=" + dataProvider.SpatialRef.ToProj4String();
                    options.Add(spRef);
                }
                string mapInf = evp.ToMapInfoString(new Size(item.Width, item.Height));
                options.Add(mapInf);
            }
            return(options.Count > 0 ? options.ToArray() : null);
        }
Example #3
0
        private void Cut(IRasterDataProvider srcDataProvider, IRasterDataProvider dstDataProvider, CutArgument args, BlockItem item, Action <int, string> progressTracker)
        {
            int rowsOfBlock;

            byte[]   buffer     = TryBuildBlockBuffer(dstDataProvider, out rowsOfBlock);
            int      bRow       = 0;
            int      eRow       = rowsOfBlock;
            int      actualRows = 0;
            GCHandle handle     = GCHandle.Alloc(_buffer, GCHandleType.Pinned);
            int      srcX       = item.Left;
            int      srcY       = item.Top;

            try
            {
                IntPtr ptr = handle.AddrOfPinnedObject();
                do
                {
                    actualRows = eRow - bRow;
                    //
                    foreach (int bNo in args.BandNos)
                    {
                        srcDataProvider.GetRasterBand(bNo).Read(srcX, srcY + bRow, item.Width,
                                                                actualRows, ptr, srcDataProvider.DataType, dstDataProvider.Width, actualRows);
                        dstDataProvider.GetRasterBand(bNo).Write(0, bRow, dstDataProvider.Width, actualRows, ptr, dstDataProvider.DataType, dstDataProvider.Width, actualRows);
                    }
                    //
                    bRow += rowsOfBlock;
                    eRow  = Math.Min(bRow + rowsOfBlock, srcDataProvider.Height);
                }while (eRow < dstDataProvider.Height);
            }
            finally
            {
                handle.Free();
            }
        }