示例#1
0
        private int[] GetDefaultBands(IRasterDrawing drawing)
        {
            IRasterDataProvider prd = drawing.DataProvider;

            if (prd == null)
            {
                return(null);
            }
            return(prd.GetDefaultBands() == null ? new int[] { 1, 2, 3 } : prd.GetDefaultBands());
        }
示例#2
0
 public static string OverView(IRasterDataProvider prd, int maxSize)
 {
     try
     {
         int[] bands = prd.GetDefaultBands();
         if (bands == null || bands.Length == 0)
         {
             bands = new int[] { 1, 1, 1 }
         }
         ;
         for (int i = 0; i < 3; i++)
         {
             if (bands[i] > prd.BandCount)
             {
                 bands[i] = 1;
             }
         }
         //int[] newBandMaps;
         //PrjBand[] prjBands = BandNoToBand(bands, out newBandMaps);
         //bands = bands.Reverse().ToArray();
         string overViewFilename = OverFileName(prd.fileName);
         using (Bitmap bmp = GenerateOverview(prd, bands, maxSize))
         {
             bmp.MakeTransparent(Color.Black);
             bmp.Save(overViewFilename, ImageFormat.Png);
             bmp.Dispose();
         }
         return(overViewFilename);
     }
     catch (Exception ex)
     {
         Console.WriteLine("生成缩略图失败" + ex.Message);
         return(null);
     }
 }
示例#3
0
 private int[] GetDefaultBands(IRasterDataProvider dataProvider)
 {
     int[] defaultBands = dataProvider.GetDefaultBands();
     if (dataProvider.BandCount > 0)
     {
         if (defaultBands == null)
         {
             if (dataProvider.BandCount < 3)
             {
                 defaultBands = new int[] { 1 }
             }
             ;
             else
             {
                 defaultBands = new int[] { 1, 2, 3 }
             };
         }
         else
         {
             for (int i = 0; i < defaultBands.Length; i++)
             {
                 if (defaultBands[i] < 1 || defaultBands[i] > dataProvider.BandCount)
                 {
                     defaultBands[i] = 1;
                 }
             }
         }
     }
     if (defaultBands != null)
     {
         Array.Reverse(defaultBands);
     }
     return(defaultBands);
 }
示例#4
0
        private void GetBandNos(out int[] defaultBandNos, out int[] otherBandNos)
        {
            defaultBandNos = _dataProvider.GetDefaultBands();
            List <int> bandNos = new List <int>();

            for (int b = 1; b <= _dataProvider.BandCount; b++)
            {
                if (defaultBandNos != null && Array.IndexOf(defaultBandNos, b) >= 0)
                {
                    continue;
                }
                bandNos.Add(b);
            }
            otherBandNos = bandNos.Count > 0 ? bandNos.ToArray() : null;
        }
        private static int[] GetDefaultBands(IRasterDrawing drawing)
        {
            IRasterDataProvider prd = drawing.DataProvider;

            if (prd == null)
            {
                return(null);
            }
            int[] defaultBands = prd.GetDefaultBands();
            if (defaultBands == null)
            {
                defaultBands = new int[] { 1, 2, 3 }
            }
            ;
            return(defaultBands);
        }
示例#6
0
 private void GetOverview(IRasterDataProvider file, int[] bandNos, out Bitmap bmp)
 {
     try
     {
         if (bandNos == null || bandNos.Length == 0)
         {
             bandNos = file.GetDefaultBands();
         }
         if (bandNos == null || bandNos.Length == 0)
         {
             bandNos = new int[] { 1, 1, 1 }
         }
         ;
         bmp = GenerateOverview(file, bandNos);
     }
     catch
     {
         bmp = null;
     }
 }
示例#7
0
 private void GetOverview(IRasterDataProvider file, ISpatialReference spatialRef, int[] bandNos, out Bitmap bmp, out string errorMessage)
 {
     try
     {
         errorMessage = "";
         if (bandNos == null)
         {
             bandNos = new int[] { 1 }
         }
         ;
         if (!File.Exists(_prjFilename))
         {
             float resolution = 0.05f;
             if (file.DataIdentify != null && file.DataIdentify.Sensor == "VISSR")
             {
                 resolution = 0.1f;
             }
             if (file.DataIdentify != null && (file.DataIdentify.Satellite == "FY1D"))
             {
                 resolution = 0.1f;
             }
             PrjOutArg arg = new PrjOutArg(spatialRef, null, resolution, resolution, _prjFilename);
             arg.SelectedBands = bandNos.OrderBy((i) => { return(i); }).ToArray();
             ProjectionFactory proj  = new ProjectionFactory();
             string[]          files = proj.Project(file, arg, null, out errorMessage);
             if (files == null || files.Length == 0 || files[0] == null)
             {
                 bmp = null;
                 if (string.IsNullOrWhiteSpace(errorMessage))
                 {
                     errorMessage = "投影缩略图文件失败";
                 }
                 return;
             }
             _prjFilename = files[0];
         }
         using (IRasterDataProvider prd = GeoDataDriver.Open(_prjFilename) as IRasterDataProvider)
         {
             if (bandNos == null || bandNos.Length == 0)
             {
                 bandNos = prd.GetDefaultBands();
             }
             if (bandNos == null || bandNos.Length == 0)
             {
                 bmp = null;
                 if (string.IsNullOrWhiteSpace(errorMessage))
                 {
                     errorMessage = "获取缩略图显示波段列表为空";
                 }
                 return;
             }
             //bandNos = new int[] { 1, 1, 1 };
             int[]     orderBandMaps;
             PrjBand[] prjBands = BandNoToBand(bandNos, out orderBandMaps);
             bmp = GenerateOverview(prd, orderBandMaps);
         }
     }
     catch
     {
         bmp = null;
         throw;
     }
 }
示例#8
0
        private static BitmapObject[] GetBitmapObjects(string[] fnames, int maxSize, ICanvas canvas, out Size bmpSize,
                                                       out Size dataSize, out GeoDo.RSS.Core.DrawEngine.CoordEnvelope viewPrjEvp,
                                                       out GeoDo.RSS.Core.DF.CoordEnvelope viewGeoEvp,
                                                       out float resolution)
        {
            bmpSize    = Size.Empty;
            dataSize   = new Size();
            viewPrjEvp = null;
            viewGeoEvp = null;
            resolution = 0;
            List <BitmapObject> bmpObjs = new List <BitmapObject>();
            BitmapObject        bmpO;

            GeoDo.RSS.Core.DrawEngine.CoordEnvelope drawEvp = null;
            bool isFirst = true;

            foreach (string fname in fnames)
            {
                if (!File.Exists(fname))
                {
                    continue;
                }
                using (IRasterDataProvider prd = GeoDataDriver.Open(fname) as IRasterDataProvider)
                {
                    IOverviewGenerator ov = prd as IOverviewGenerator;
                    bmpSize = ov.ComputeSize(maxSize);
                    Bitmap         bmp      = new Bitmap(bmpSize.Width, bmpSize.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                    RasterIdentify identify = new RasterIdentify(fname);
                    object[]       sts      = GetColorTableFunc(prd, identify.ProductIdentify, identify.SubProductIdentify);
                    if (sts != null)
                    {
                        ov.Generate(new int[] { 1, 1, 1 }, sts, ref bmp);
                    }
                    else
                    {
                        int[] bands = prd.GetDefaultBands();
                        if (bands == null || bands.Length == 0)
                        {
                            return(null);
                        }
                        ov.Generate(bands, ref bmp);
                    }
                    drawEvp = GetDrawingEnvelop(canvas, prd);
                    if (isFirst)
                    {
                        viewPrjEvp = drawEvp;
                        ICoordinateTransform tans = canvas.CoordTransform;
                        viewGeoEvp = PrjToGeoCoordEvp(viewPrjEvp, tans);
                        resolution = prd.ResolutionX;
                        dataSize   = GetMaxDataSize(canvas, viewPrjEvp, prd, out viewGeoEvp);
                        isFirst    = false;
                    }
                    else
                    {
                        viewPrjEvp = viewPrjEvp.Union(drawEvp);
                        dataSize   = GetMaxDataSize(canvas, viewPrjEvp, prd, out viewGeoEvp);
                        //如果分辩率不相等则取最大的分辨率
                        if (resolution < prd.ResolutionX)
                        {
                            resolution = prd.ResolutionX;
                        }
                    }
                    bmpO = new BitmapObject(bmp, drawEvp);
                    bmpObjs.Add(bmpO);
                }
            }
            return(bmpObjs.Count != 0 ? bmpObjs.ToArray() : null);
        }