Ejemplo n.º 1
0
 private Band[] GetDstRasterBand(AbstractWarpDataset dstRaster, FilePrjSettings prjSettings, int beginBandIndex)
 {
     Band[] bands   = new Band[prjSettings.OutBandNos.Length];
     int[]  bandNos = prjSettings.OutBandNos;
     for (int i = beginBandIndex; i < bandNos.Length + beginBandIndex; i++)
     {
         if (dstRaster.isMultiDs)
         {
             int newBand = -1;
             if (dstRaster.TryGetBandNoFromBandName(bandNos[i], out newBand))
             {
                 bands[i] = dstRaster.GetRasterBand(newBand);
             }
             else
             {
                 bands[i] = dstRaster.GetRasterBand(bandNos[i]);
             }
         }
         else
         {
             bands[i] = dstRaster.GetRasterBand(bandNos[i]);
         }
     }
     return(bands);
 }
Ejemplo n.º 2
0
        private Band[] TryCreateRasterDataBands(AbstractWarpDataset srcRaster, FY3L2L3FilePrjSettings prjSettings, Action <int, string> progressCallback)
        {
            List <Band> rasterBands = new List <Band>();

            if (prjSettings.OutBandNos == null)
            {
                int count = srcRaster.BandCount;

                for (int i = 0; i < count; i++)
                {
                    if (progressCallback != null)
                    {
                        progressCallback(_readyProgress++, "准备第" + i + "个输入数据通道");
                    }
                    Band band = srcRaster.GetRasterBand(i);
                    rasterBands.Add(band);
                }
            }
            else
            {
                foreach (var i in prjSettings.OutBandNos)
                {
                    Band band = srcRaster.GetRasterBand(i);
                    rasterBands.Add(band);
                }
            }

            return(rasterBands.ToArray());
        }
Ejemplo n.º 3
0
        private void WriteDataToLDF <T>(AbstractWarpDataset prdWriter, DataType dataType, int outWidth, int rowStep, int oRow, T[] dstBandData, int b, double dataweight, float zoom)
        {
            Band band = null;

            for (int i = 0; i < dstBandData.Length; i++)
            {
                dstBandData[i] = (T)Convert.ChangeType(Convert.ToDouble(dstBandData[i]) * dataweight * zoom, typeof(T));
            }
            try
            {
                band = prdWriter.GetRasterBand(b + 1);
                GCHandle h = GCHandle.Alloc(dstBandData, GCHandleType.Pinned);
                try
                {
                    IntPtr bufferPtr = h.AddrOfPinnedObject();
                    band.WriteRaster(0, oRow, outWidth, rowStep, bufferPtr, outWidth, rowStep, dataType, 0, 0);
                }
                finally
                {
                    h.Free();
                }
            }
            finally
            {
                //这里不能释放,由于大部分band是记录在RasterDataProvider中的数组中的,如果释放后,下次取就会出错
                //if (band!=null&&band is IGDALRasterBand)
                //{
                //    band.Dispose();
                //}
            }
        }
Ejemplo n.º 4
0
        private void WriteDataToLDF <T>(AbstractWarpDataset prdWriter, DataType dataType, int outWidth, int rowStep, int oRow, T[] dstBandData, int b)
        {
            Band band = null;

            try
            {
                band = prdWriter.GetRasterBand(b);
                GCHandle h = GCHandle.Alloc(dstBandData, GCHandleType.Pinned);
                try
                {
                    IntPtr bufferPtr = h.AddrOfPinnedObject();
                    band.WriteRaster(0, oRow, outWidth, rowStep, bufferPtr, outWidth, rowStep, dataType, 0, 0);
                }
                finally
                {
                    h.Free();
                }
            }
            finally
            {
                //这里不能释放,由于大部分band是记录在RasterDataProvider中的数组中的,如果释放后,下次取就会出错
                //if (band!=null&&band is IGDALRasterBand)
                //{
                //    band.Dispose();
                //}
            }
        }
Ejemplo n.º 5
0
        private Band[] TryCreateRasterDataBands(AbstractWarpDataset srcRaster, FilePrjSettings prjSettings, Action <int, string> progressCallback)
        {
            List <Band> rasterBands = new List <Band>();

            for (int i = 0; i < prjSettings.OutBandNos.Length; i++)
            {
                if (progressCallback != null)
                {
                    progressCallback(_readyProgress++, "投影准备");
                }
                int  bandNo = prjSettings.OutBandNos[i];
                Band band   = srcRaster.GetRasterBand(bandNo - 1);
                rasterBands.Add(band);
            }
            return(rasterBands.ToArray());
        }
Ejemplo n.º 6
0
 ///针对FY2E,投影波段,设置为1,2,3,4,5[NOMChannelVIS],6[NOMCloudClassification]
 private Band[] GetSrcRasterBand(AbstractWarpDataset srcRaster, FilePrjSettings prjSettings)
 {
     Band[] bands   = new Band[prjSettings.OutBandNos.Length];
     int[]  bandNos = prjSettings.OutBandNos;
     if (bandNos.Length == 1 && bandNos[0] == 5)
     {
         Band[] bs = srcRaster.GetBands("NOMChannelVIS1KM");
         if (bs != null)
         {
             bands[0] = bs[0];
             //bands[0].GetBandID() = 5;
             _srcImgResolution = 0.01f;
         }
     }
     else
     {
         for (int i = 0; i < bandNos.Length; i++)
         {
             if (bandNos[i] <= 4)
             {
                 bands[i] = srcRaster.GetRasterBand(bandNos[i]);
             }
             else if (bandNos[i] == 5)
             {
                 Band[] bs = srcRaster.GetBands("NOMChannelVIS1KM");
                 if (bs != null)
                 {
                     bands[i] = bs[0];
                     //bands[i].BandNo = 5;
                 }
             }
             else if (bandNos[i] == 6)
             {
                 Band[] bs = srcRaster.GetBands("NOMCloudClassification");
                 if (bs != null)
                 {
                     bands[i] = bs[0];
                     //bands[i].BandNo = 6;
                 }
             }
         }
     }
     return(bands);
 }
Ejemplo n.º 7
0
        /* public static string OverView(AbstractWarpDataset outfileRaster, int _prjPngSize)
         * {
         *   //int height = _prjPngSize;
         *   int maxWidth = _prjPngSize;
         *   int matchHeight = Convert.ToInt32(outfileRaster.Height * 1.0* _prjPngSize / outfileRaster.Width );
         *   //int width = Convert.ToInt32(outfileRaster.Width * 1.0 / outfileRaster.Height * _prjPngSize);
         *   var rLayer = LayerFactory.CreateDefaultRasterLayer(outfileRaster.ds as IRasterDataset);
         *   ILayer layer = rLayer as ILayer;
         *   mRasterRenderTool.Instance.RenderSingleRasterSource(layer, outfileRaster.fileName);
         *
         *   IDisplayTransformation disTrans = new DisplayTransformation();
         *   disTrans.Bounds = layer.Extent;
         *   disTrans.DeviceFrame = new System.Drawing.RectangleF(0, 0, maxWidth, matchHeight);
         *   disTrans.VisibleBounds = layer.Extent;
         *   disTrans.SpatialReference = outfileRaster.SpatialRef;
         *
         *   Bitmap bit = new Bitmap(maxWidth, matchHeight);
         *   Graphics graphic = Graphics.FromImage(bit);
         *   layer.Draw(graphic, disTrans, SystemUI.LayerDrawPhaseType.DPGeography, null);
         *   //bit.MakeTransparent(Color.Black);
         *   string outOverviewFile = Path.Combine(Path.GetDirectoryName(outfileRaster.fileName), Path.GetFileNameWithoutExtension(outfileRaster.fileName) + ".OverView.png");
         *   bit.Save(outOverviewFile);
         *   //根据输入影像 生成指定尺寸的png
         *   return outOverviewFile;
         * }*/

        public static string OverView(AbstractWarpDataset outfileRaster, int _prjPngSize)
        {
            int    maxWidth        = _prjPngSize;
            int    matchHeight     = Convert.ToInt32(outfileRaster.Height * 1.0 * _prjPngSize / outfileRaster.Width);
            string outOverviewFile = Path.Combine(Path.GetDirectoryName(outfileRaster.fileName),
                                                  Path.GetFileNameWithoutExtension(outfileRaster.fileName) + ".overview.png");

            RasterSourceTypeSingleInfo single =
                mRasterSourceManager.GetInstance().GetInputfileRasterSourceInfo(outfileRaster.fileName);

            int[] bandNos = new int[] { 3, 2, 1 };
            if (single != null)
            {
                var bands = single.RenderCol.Defaultband.Split(',');
                if (bands.Length == 1)
                {
                    bandNos[0] = Convert.ToInt32(bands[0]);
                    bandNos[1] = Convert.ToInt32(bands[0]);
                    bandNos[2] = Convert.ToInt32(bands[0]);
                }
                else if (bands.Length == 3)
                {
                    bandNos[0] = Convert.ToInt32(bands[0]);
                    bandNos[1] = Convert.ToInt32(bands[1]);
                    bandNos[2] = Convert.ToInt32(bands[2]);
                }
            }

            Console.WriteLine("Bands :{0} {1} {2}", bandNos[0], bandNos[1], bandNos[2]);
            var outDs = Gdal.GetDriverByName("MEM").Create("", maxWidth, matchHeight, 4, DataType.GDT_Byte, null);

            UInt16[][] buffer = new UInt16[4][];
            for (int i = 0; i < 4; i++)
            {
                buffer[i] = new UInt16[maxWidth * matchHeight];
            }


            outfileRaster.GetRasterBand(bandNos[0] - 1)
            .ReadRaster(0, 0, outfileRaster.Width, outfileRaster.Height, buffer[0], maxWidth, matchHeight, 0, 0);
            outfileRaster.GetRasterBand(bandNos[1] - 1)
            .ReadRaster(0, 0, outfileRaster.Width, outfileRaster.Height, buffer[1], maxWidth, matchHeight, 0, 0);
            outfileRaster.GetRasterBand(bandNos[2] - 1)
            .ReadRaster(0, 0, outfileRaster.Width, outfileRaster.Height, buffer[2], maxWidth, matchHeight, 0, 0);


            double offsetR = 0, offsetG = 0, offsetB = 0;
            double scaleR = 0.25, scaleG = 0.25, scaleB = 0.25;

            if (single != null)
            {
                var renderR =
                    single.RenderCol.BandRenderCol.FirstOrDefault(t => t.BandID.Contains(bandNos[0].ToString()));
                var renderG =
                    single.RenderCol.BandRenderCol.FirstOrDefault(t => t.BandID.Contains(bandNos[1].ToString()));
                var renderB =
                    single.RenderCol.BandRenderCol.FirstOrDefault(t => t.BandID.Contains(bandNos[2].ToString()));
                if (renderR != null && renderG != null && renderB != null)
                {
                    offsetR = Convert.ToDouble(renderR.RenderMin);
                    offsetG = Convert.ToDouble(renderG.RenderMin);
                    offsetB = Convert.ToDouble(renderB.RenderMin);
                    scaleR  = 250 / (Convert.ToDouble(renderR.RenderMax) - Convert.ToDouble(renderR.RenderMin));
                    scaleG  = 250 / (Convert.ToDouble(renderG.RenderMax) - Convert.ToDouble(renderG.RenderMin));
                    scaleB  = 250 / (Convert.ToDouble(renderB.RenderMax) - Convert.ToDouble(renderB.RenderMin));
                }
            }

            for (int i = 0; i < maxWidth * matchHeight; i++)
            {
                buffer[0][i] = buffer[0][i] > offsetR
                    ? Convert.ToUInt16((buffer[0][i] - offsetR) *scaleR)
                    : (ushort)0;

                buffer[1][i] = buffer[1][i] > offsetG
                    ? Convert.ToUInt16((buffer[1][i] - offsetG) *scaleG)
                    : (ushort)0;

                buffer[2][i] = buffer[2][i] > offsetB
                    ? Convert.ToUInt16((buffer[2][i] - offsetB) *scaleB)
                    : (ushort)0;

                var t = buffer[0][i] + buffer[1][i] + buffer[2][i];
                if (t <= 0 || t >= 255 * 3)
                {
                    buffer[3][i] = 0;
                }
                else
                {
                    buffer[3][i] = 255;
                }
            }

            outDs.GetRasterBand(1).WriteRaster(0, 0, maxWidth, matchHeight, buffer[0], maxWidth, matchHeight, 0, 0);
            outDs.GetRasterBand(2).WriteRaster(0, 0, maxWidth, matchHeight, buffer[1], maxWidth, matchHeight, 0, 0);
            outDs.GetRasterBand(3).WriteRaster(0, 0, maxWidth, matchHeight, buffer[2], maxWidth, matchHeight, 0, 0);
            outDs.GetRasterBand(4).WriteRaster(0, 0, maxWidth, matchHeight, buffer[3], maxWidth, matchHeight, 0, 0);


            Dataset pngDs = Gdal.GetDriverByName("PNG").CreateCopy(outOverviewFile, outDs, 0, null, null, null);

            pngDs.Dispose();

            outDs.Dispose();
            return(outOverviewFile);
        }
Ejemplo n.º 8
0
 protected void SetPrdwritterNodata(AbstractWarpDataset dstRaster, double nodatavalue)
 {
     Enumerable.Range(0, dstRaster.BandCount).ToList()
     .ForEach(t => dstRaster.GetRasterBand(t).SetNoDataValue(nodatavalue));
 }