Ejemplo n.º 1
0
 public static void Init()
 {
     //为数据框注册添加栅格数据的委托
     GeoDo.RSS.Layout.DataFrm.DataFrame.AddFileToCanvasViewerExecutor = (fname, argument, canvas, fileOpenargs, colorTableName) =>
     {
         //IRgbStretcherProvider rgbStretcherpProvider = null;
         //if (fname.ToUpper().EndsWith(".DAT"))
         //    rgbStretcherpProvider = new RgbStretcherProvider();
         IRgbStretcherProvider rgbStretcherpProvider = new RgbStretcherProvider();
         if (string.IsNullOrWhiteSpace(colorTableName))
         {
             colorTableName = GetColorTableName(argument);//兼容最早colortablename放在argument中的模式
         }
         else
         {
             colorTableName = "colortablename=" + colorTableName;
         }
         List <string> options = new List <string>();
         if (!string.IsNullOrWhiteSpace(colorTableName))
         {
             options.Add(colorTableName);
         }
         if (fileOpenargs != null)
         {
             options.AddRange(fileOpenargs);
         }
         IRasterDrawing drawing = new RasterDrawing(fname, canvas, rgbStretcherpProvider, options.ToArray());
         drawing.SelectedBandNos = GetDefaultBands(drawing);
         IRasterLayer lyr = new RasterLayer(drawing);
         canvas.LayerContainer.Layers.Add(lyr);
         canvas.PrimaryDrawObject = drawing;
         canvas.CurrentEnvelope   = drawing.OriginalEnvelope;
         drawing.StartLoading(null);
         TryLoadAOIMaskLayer(canvas, drawing, fname);
     };
     //为栅格图例注册颜色表获取委托
     GeoDo.RSS.Layout.RasterLegendElement.RasterLegendItemsGetter = (colorTableName) =>
     {
         ProductColorTable colorTable = ProductColorTableFactory.GetColorTable(colorTableName);
         if (colorTable == null)
         {
             return(null);
         }
         List <LegendItem> items = new List <LegendItem>();
         foreach (ProductColor c in colorTable.ProductColors)
         {
             if (!c.DisplayLengend)
             {
                 continue;
             }
             string txt = c.LableText;
             items.Add(new LegendItem(txt, c.Color));
         }
         return(items.Count > 0 ? items.ToArray() : null);
     };
 }
Ejemplo n.º 2
0
        private bool CheckMemory(string strRasName)
        {
            float availableSize = PerformanceMonitoring.GetAvailableRAM();

            if (availableSize < 0)
            {
                return(true);
            }
            int   memoryOfTile, tileCount;
            float requiredSize = RasterDrawing.EstimateRequiredMemory(strRasName, out memoryOfTile, out tileCount);

            IRasterDataProvider prd = GeoDataDriver.Open(strRasName) as IRasterDataProvider;
            int          nHeight    = prd.Height;
            int          nWidth     = prd.Width;
            enumDataType dataType   = prd.DataType;
            int          nByteCount = DataTypeHelper.SizeOf(dataType);

            requiredSize = requiredSize * 2 + nByteCount * nHeight * nWidth / 1024 / 1024;

            if (availableSize < requiredSize + 200)//预留200MB
            {
                return(false);
            }
            else                //内存碎片的可能性非常大,需要先尝试内存申请能否成功
            {
                for (int i = 0; i < tileCount; i++)
                {
                    try
                    {
                        byte[] tileBuffer = new byte[memoryOfTile];
                    }
                    catch
                    {
                        return(false);
                    }
                }

                try
                {
                    byte[] dataBuffer = new byte[nByteCount * nHeight * nWidth];
                }
                catch
                {
                    return(false);
                }

                return(true);
            }
        }
Ejemplo n.º 3
0
        private void CreatWorldFile(string fileName, ICanvas canvas, int width, int height)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            if (canvas == null)
            {
                return;
            }
            if (canvas.PrimaryDrawObject == null)
            {
                return;
            }
            if (width == 0 || height == 0)
            {
                return;
            }
            WorldFile wf = new WorldFile();

            if (canvas.PrimaryDrawObject.OriginalEnvelope == null)
            {
                return;
            }
            RasterDrawing drawing = canvas.PrimaryDrawObject as RasterDrawing;

            if (drawing == null)
            {
                return;
            }
            if (drawing.DataProvider == null)
            {
                return;
            }
            IRasterDataProvider prd = drawing.DataProvider;

            if (prd.SpatialRef == null)
            {
                return;
            }
            double bmpResolutionX = (prd.CoordEnvelope.MaxX - prd.CoordEnvelope.MinX) / width;
            double bmpResolutionY = (prd.CoordEnvelope.MaxY - prd.CoordEnvelope.MinY) / height;

            wf.CreatWorldFile(bmpResolutionX, -bmpResolutionY, prd.CoordEnvelope.MinX, prd.CoordEnvelope.MaxY, fileName);
            wf.CreatXmlFile(prd.SpatialRef, fileName);
        }
Ejemplo n.º 4
0
        public static bool MemoryIsEnoughForRaster(string rasterFileName)
        {
            float availableSize = PerformanceMonitoring.GetAvailableRAM();

            if (availableSize < 0)
            {
                return(true);
            }
            int   memoryOfTile, tileCount;
            float requiredSize    = RasterDrawing.EstimateRequiredMemory(rasterFileName, out memoryOfTile, out tileCount);
            int   countOfDrawing  = 0;
            float memoryOfLoading = GetMemoryOfTileLoading(out countOfDrawing);

            //Console.WriteLine("AvailableSize:" + availableSize.ToString() + " , RequiredSize:" + requiredSize.ToString() + " , SizeOfLoading:" + memoryOfLoading.ToString());
            availableSize -= memoryOfLoading;
            int host_min_mem_size = HOST_MIN_MEMORY_SIZE;

            if (countOfDrawing == 0)
            {
                host_min_mem_size = 0;
            }
            if (availableSize < requiredSize + host_min_mem_size)//预留200MB
            {
                return(false);
            }
            else if (availableSize < requiredSize)//内存碎片的可能性非常大,需要先尝试内存申请能否成功
            {
                for (int i = 0; i < tileCount; i++)
                {
                    try
                    {
                        byte[] tileBuffer = new byte[memoryOfTile];
                    }
                    catch
                    {
                        Console.WriteLine("内存空间足够,但因内存碎片无法申请成功空间。");
                        return(false);
                    }
                }
                return(true);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="session"></param>
        /// <param name="canvas"></param>
        /// <param name="fname"></param>
        /// <param name="args">
        /// 支持各种类型的多个参数
        /// 其中string[]类型的数据会作为RasterDrawing的options
        /// </param>
        /// <returns></returns>
        public static IRasterLayer CreateAndLoadRasterLayer(ISmartSession session, ICanvas canvas, string fname, params object[] args)
        {
            //bool isImage = IsImage(fname);
            //IRasterDrawing drawing = new RasterDrawing(fname, canvas, isImage ? null : GetStretcherProvider(args));
            string[]       options = GetOptions(args);
            IRasterDrawing drawing = new RasterDrawing(fname, canvas, GetStretcherProvider(args), options);

            //此处应走配置文件
            drawing.SelectedBandNos = GetDefaultBands(drawing);
            if (args != null && args.Length == 1 && args[0] is int[])
            {
                drawing.SelectedBandNos = (int[])args[0];
            }
            IRasterLayer rstLayer = new RasterLayer(drawing);

            canvas.LayerContainer.Layers.Add(rstLayer);
            canvas.PrimaryDrawObject = drawing;
            canvas.CurrentEnvelope   = drawing.OriginalEnvelope;
            int w = drawing.DataProvider.Width;
            int h = drawing.DataProvider.Height;
            //小图像不显示进度条
            int times = drawing.GetOverviewLoadTimes();

            if (times == -1)
            {
                drawing.StartLoading(null);
                return(rstLayer);
            }
            string tipstring = "正在读取文件\"" + Path.GetFileName(fname) + "\"...";

            try
            {
                session.ProgressMonitorManager.DefaultProgressMonitor.Reset(tipstring, times);
                session.ProgressMonitorManager.DefaultProgressMonitor.Start(false);
                drawing.StartLoading((t, p) =>
                {
                    session.ProgressMonitorManager.DefaultProgressMonitor.Boost(p, tipstring);
                });
            }
            finally
            {
                session.ProgressMonitorManager.DefaultProgressMonitor.Finish();
            }
            return(rstLayer);
        }
Ejemplo n.º 6
0
        private void button15_Click(object sender, EventArgs e)
        {
            IDataFrame df = _host.ActiveDataFrame;

            if (df == null)
            {
                return;
            }
            string fname = null;

            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    fname = dlg.FileName;
                }
                else
                {
                    return;
                }
            }
            ICanvas        canvas  = (df.Provider as IDataFrameDataProvider).Canvas;
            IRasterDrawing drawing = new RasterDrawing(fname, canvas, null);

            drawing.SelectedBandNos = GetDefaultBands(drawing);
            IRasterLayer lyr = new RasterLayer(drawing);

            canvas.LayerContainer.Layers.Add(lyr);
            canvas.PrimaryDrawObject = drawing;
            canvas.CurrentEnvelope   = drawing.OriginalEnvelope;
            //  AddVectorHost(canvas);
            drawing.StartLoading(null);
            canvas.Refresh(enumRefreshType.All);

            //
            fname = @"F:\产品与项目\MAS-II\源代码0618-night\【控制】UI框架\SMART\bin\Release\数据引用\基础矢量\矢量地图\world.mcd";
            IVectorHostLayer vHost = new VectorHostLayer(null);

            vHost.IsEnableDummyRender = false;
            canvas.LayerContainer.Layers.Add(vHost as ILayer);
            canvas.Refresh(enumRefreshType.All);
            //
            _host.Render();
        }
Ejemplo n.º 7
0
        private void AddRasterLayer(string strRasName)
        {
            if (_isOnlyOneImg)
            {
                bool memoryIsEnough = CheckMemory(strRasName);
                if (!memoryIsEnough)
                {
                    MsgBox.ShowInfo("系统可用内存不足以对以下文件执行几何精校正操作。\n\n" + strRasName);
                    return;
                }
            }

            IRasterDrawing drawing = new RasterDrawing(strRasName, canvasHost1.Canvas, GetRgbStretcherProvider(strRasName));

            drawing.SelectedBandNos = GetDefaultBands(drawing);
            IRasterLayer rstLayer = new RasterLayer(drawing);

            canvasHost1.Canvas.LayerContainer.Layers.Add(rstLayer);
            canvasHost1.Canvas.PrimaryDrawObject = drawing;
            canvasHost1.Canvas.CurrentEnvelope   = drawing.OriginalEnvelope;

            int times = drawing.GetOverviewLoadTimes();

            if (times == -1)
            {
                drawing.StartLoading(null);
                return;
            }
            string tipstring = "正在读取文件\"" + Path.GetFileName(_strRasterName) + "\"...";

            try
            {
                _smartSession.ProgressMonitorManager.DefaultProgressMonitor.Reset(tipstring, times);
                _smartSession.ProgressMonitorManager.DefaultProgressMonitor.Start(false);
                drawing.StartLoading((t, p) =>
                {
                    _smartSession.ProgressMonitorManager.DefaultProgressMonitor.Boost(p, tipstring);
                });
            }
            finally
            {
                _smartSession.ProgressMonitorManager.DefaultProgressMonitor.Finish();
            }
        }
Ejemplo n.º 8
0
        private void AddRasterLayer(string strRasName, ICanvas canvas, double minValue, double maxValue)
        {
            IRasterDrawing drawing = new RasterDrawing(strRasName, canvas, GetRgbStretcherProvider(strRasName));

            drawing.SelectedBandNos = GetDefaultBands(drawing);
            Color[] colors = GetDefColors(200);
            ColorMapTable <double> colorTable = GetColorTable(colors, maxValue, minValue);

            if (colorTable == null)
            {
                return;
            }
            drawing.ApplyColorMapTable(colorTable);
            IRasterLayer rstLayer = new RasterLayer(drawing);

            canvas.LayerContainer.Layers.Add(rstLayer);
            canvas.PrimaryDrawObject = drawing;
            canvas.CurrentEnvelope   = drawing.OriginalEnvelope;

            int times = drawing.GetOverviewLoadTimes();

            if (times == -1)
            {
                drawing.StartLoading(null);
                return;
            }
            string tipstring = "正在读取文件\"" + Path.GetFileName(strRasName) + "\"...";

            try
            {
                _smartSession.ProgressMonitorManager.DefaultProgressMonitor.Reset(tipstring, times);
                _smartSession.ProgressMonitorManager.DefaultProgressMonitor.Start(false);
                drawing.StartLoading((t, p) =>
                {
                    _smartSession.ProgressMonitorManager.DefaultProgressMonitor.Boost(p, tipstring);
                });
            }
            finally
            {
                _smartSession.ProgressMonitorManager.DefaultProgressMonitor.Finish();
            }
        }
Ejemplo n.º 9
0
        private void CreateCanvasViewer(string fname)
        {
            CanvasViewer cv = new CanvasViewer(OpenFileFactory.GetTextByFileName(fname), _session);

            cv.Tag = fname;
            _session.SmartWindowManager.DisplayWindow(cv);
            RasterLayerBuilder.CreateAndLoadRasterLayer(_session, cv.Canvas, fname);
            //自动翻转升轨数据
            RasterDrawing drawing = cv.ActiveObject as RasterDrawing;

            if (drawing != null && drawing.DataProvider != null)
            {
                DataIdentify idt = drawing.DataProvider.DataIdentify;
                if (idt != null && idt.IsOrbit && idt.IsAscOrbitDirection)
                {
                    cv.Canvas.IsReverseDirection = true;
                    cv.Canvas.Refresh(Core.DrawEngine.enumRefreshType.RasterLayer);
                }
            }
            //轨道数据自动全屏显示
            (cv.Canvas as Canvas).SetToFitWidth();
        }
Ejemplo n.º 10
0
        private void btnCreateRasterDrawing_Click(object sender, EventArgs e)
        {
            string fname = null;

            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Filter = "(*.ldf)|*.ldf";
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    fname = dlg.FileName;
                }
                else
                {
                    return;
                }
            }

            string ops = null;

            if (fname.EndsWith(".txt"))
            {
                ops = "ComponentID=0000000";
            }
            IRasterDrawing drawing = new RasterDrawing(fname, _canvas, null, ops);

            drawing.LoadingSubscribers.Add(this);
            drawing.SelectedBandNos = new int[] { 1, 2, 3 };
            IRasterLayer lyr = new RasterLayer(drawing);

            _canvas.LayerContainer.Layers.Add(lyr);
            _canvas.PrimaryDrawObject = drawing;
            _canvas.CurrentEnvelope   = drawing.OriginalEnvelope;
            drawing.StartLoading((t, p) => { Text = p.ToString() + "/" + t.ToString(); });
            _canvas.Refresh(enumRefreshType.All);
            _rasterLayer = lyr;
            //_canvas.OnEnvelopeChanged += new EventHandler(CanvasEnvelopeChanged);
        }