//应用变量
        private void TryApplyVars(IGxdDocument doc, string fileName)
        {
            ILayoutTemplate             temp = doc.GxdTemplateHost.LayoutTemplate;
            RasterIdentify              rst  = new RasterIdentify(fileName);
            Dictionary <string, string> vars = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(rst.Satellite))
            {
                string sate = rst.Satellite.ToUpper();
                if (sate.Contains("FY3"))
                {
                    sate = sate.Replace("FY3", "FY-3");
                }
                vars.Add("{Satellite}", sate);
            }//changed by wangyu "FY3A"->"FY-3A"2012.10.20
            //vars.Add("{Satellite}", rst.Satellite);
            if (!string.IsNullOrEmpty(rst.Sensor))
            {
                vars.Add("{Sensor}", rst.Sensor);
            }
            if (!string.IsNullOrEmpty(rst.ProductName))
            {
                vars.Add("{Product}", rst.ProductName);
            }
            if (rst.OrbitDateTime != DateTime.MinValue)
            {
                rst.OrbitDateTime.AddHours(8);
                vars.Add("{OrbitDateTime}", rst.OrbitDateTime.AddHours(8).ToString("yyyy年MM月dd日 HH:mm") + " (北京时)");
            }
            //changed by wangyu,add displaying of hour and minutes 2012.10.20
            temp.ApplyVars(vars);
        }
        //internal void SetOrbitTimes(string[] orbitTimes)
        //{
        //    if (_template == null)
        //        return;
        //    ILayout layout = _template.Layout;
        //    IElement[] dfs = layout.QueryElements((e) => { return e is ILegendElement; });
        //    List<LegendItem> lg = new List<LegendItem>();
        //    for (int i = 0; i < orbitTimes.Length; i++)
        //    {
        //        lg.Add(new LegendItem(orbitTimes[i]));
        //    }
        //    ILegendElement legend = dfs[0] as ILegendElement;
        //    legend.LegendItems = lg.ToArray();
        //}

        public string CreateThematicGraphic(string dataFileName, string theme, string gxdFilename, string extInfos, params object[] options)
        {
            _template = LayoutTemplate.LoadTemplateFrom(theme);
            if (_template == null)
            {
                return(null);
            }
            if (_isNeedFitToTemplateWidth)
            {
                using (IRasterDataProvider prd = GeoDataDriver.Open(dataFileName) as IRasterDataProvider)
                {
                    if (prd != null)
                    {
                        FitTemplateWidth(_template.Layout, prd.Width, prd.Height);
                    }
                }
            }
            IGxdDocument _doc = GetDocument(dataFileName, _aoi, _template, options != null && options.Length > 0 ? options[0] : null);

            if (_doc == null)
            {
                return(null);
            }
            _doc.SaveAs(gxdFilename);
            return(gxdFilename);
        }
Exemple #3
0
        private void TrySetAttributesOfElements(IGxdDocument doc)
        {
            ILayout layout = doc.GxdTemplateHost.LayoutTemplate.Layout;

            //数据框
            IElement[] dfs = layout.QueryElements((e) => { return(e is IDataFrame); });
            ApplyAttributesOfDataFrame(doc.DataFrames, dfs, layout);
        }
Exemple #4
0
        public void SaveAsDocument(string gxdfilename)
        {
            IGxdDocument doc = GxdDocument.GenerateFrom(this);

            if (doc != null)
            {
                doc.SaveAs(gxdfilename);
            }
        }
Exemple #5
0
        private void button19_Click(object sender, EventArgs e)
        {
            GxdDocumentParser p     = new GxdDocumentParser();
            string            fname = "f:\\gxd.xml";
            IGxdDocument      doc   = p.Parse(fname);
            GxdRasterItem     it    = new GxdRasterItem("f:\\1.bmp", new PointF());
            XElement          ele   = it.ToXml();

            ele = doc.GxdTemplateHost.ToXml();
            doc.SaveAs("f:\\gxd2.xml");
        }
        /// <summary>
        /// 监测示意图显示/多通道合成图
        /// </summary>
        /// <param name="argument">template:沙尘监测示意图,监测示意图,DST,MCSI</param>
        /// <returns>专题图文档,IGxdDocument</returns>
        public string DisplayMonitorBitmap(ISmartSession session, string argument, out string subProductIdentify)
        {
            subProductIdentify = null;
            ICanvasViewer viewer = session.SmartWindowManager.ActiveCanvasViewer;

            if (viewer == null)
            {
                return(null);
            }
            ICanvas canvas = viewer.Canvas;

            if (canvas == null)
            {
                return(null);
            }
            string bitmapFileName = null;
            int    width          = 0;
            int    height         = 0;
            bool   isOk           = GetOrginBmpAndSave(canvas, out bitmapFileName, out width, out height);

            if (!isOk)
            {
                return(null);
            }
            CreatWorldFile(bitmapFileName, canvas, width, height);
            string[] parts = argument.Split(',');
            if (parts == null || parts.Length == 0)
            {
                return(null);
            }
            subProductIdentify = parts[parts.Length - 1];
            object[]        args = new object[] { parts[0] };
            ILayoutTemplate temp = GetTemplateByArg(parts[0]);

            if (temp == null)
            {
                return(null);
            }

            ILayout layout = temp.Layout;

            FitSizeToTemplateWidth(layout, width, height);

            string       rasterFname = (canvas.PrimaryDrawObject as IRasterDrawing).FileName;
            IGxdDocument gxdDoc      = GetDocument(session, rasterFname, bitmapFileName, temp, parts[1]);

            TryApplyVars(gxdDoc.GxdTemplateHost.LayoutTemplate, (canvas.PrimaryDrawObject as IRasterDrawing));

            string fname = GetOutputGxdFileName(rasterFname, parts[2]);

            gxdDoc.SaveAs(fname);
            return(fname);
        }
        public void Generate(string dataFileName, string templateName, int[] aoi, string extInfos, string outIdentify, params object[] options)
        {
            _doc   = null;
            _fname = null;
            ILayoutTemplate t = GetTemplateByName(dataFileName, templateName);

            if (t == null)
            {
                return;
            }
            _fname = GetOutputGxdFileName(dataFileName, outIdentify, extInfos);
            _doc   = GetDocument(dataFileName, aoi, t, options != null && options.Length > 0 ? options[0] : null);
        }
Exemple #8
0
 private void button21_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog dlg = new OpenFileDialog())
     {
         dlg.Filter = "Smart Layout Document(*.gxd)|*.gxd";
         if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             IGxdDocument doc = GxdDocument.LoadFrom(dlg.FileName);
             _host.ApplyGxdDocument(doc);
             _host.Render();
         }
     }
 }
Exemple #9
0
        //应用变量
        private void TryApplyVars(IGxdDocument doc, string fileName)
        {
            ILayoutTemplate             temp     = doc.GxdTemplateHost.LayoutTemplate;
            RasterIdentify              identify = new RasterIdentify(fileName);
            Dictionary <string, string> vars     = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(identify.Satellite))
            {
                string sate = identify.Satellite.ToUpper();
                if (sate.Contains("FY3"))
                {
                    sate = sate.Replace("FY3", "FY-3");
                }
                else if (sate.Contains("FY2"))
                {
                    sate = sate.Replace("FY2", "FY-2");
                }
                vars.Add("{Satellite}", sate);
            }
            if (!string.IsNullOrEmpty(identify.Sensor))
            {
                vars.Add("{Sensor}", identify.Sensor);
            }
            if (!string.IsNullOrEmpty(identify.ProductName))
            {
                vars.Add("{Product}", identify.ProductName);
            }
            if (string.IsNullOrWhiteSpace(DateString))
            {
                if (identify.OrbitDateTime != DateTime.MinValue)
                {
                    identify.OrbitDateTime.AddHours(8);
                    vars.Add("{OrbitDateTime}", identify.OrbitDateTime.AddHours(8).ToString("yyyy年MM月dd日 HH:mm") + " (北京时)");
                }
                if (identify.MaxOrbitDate != DateTime.MaxValue && identify.MinOrbitDate != DateTime.MinValue)
                {
                    DateTime minTime = identify.MinOrbitDate.AddHours(8);
                    DateTime maxTime = identify.MaxOrbitDate.AddHours(8);
                    vars.Add("{MinOrbitDateTime~MaxOrbitDateTime}", minTime.ToString("yyyy年MM月dd日 HH:mm") + " ~ " + maxTime.ToString("yyyy年MM月dd日 HH:mm"));
                }
            }
            else
            {
                vars.Add("{OrbitDateTime}", DateString);
                vars.Add("{MinOrbitDateTime~MaxOrbitDateTime}", DateString);
            }
            temp.ApplyVars(vars);
        }
        private void TrySetAttributesOfElements(IGxdDocument doc)
        {
            ILayout layout = doc.GxdTemplateHost.LayoutTemplate.Layout;

            ApplyAttributesOfLayout(layout);

            //图廓
            IBorder border = layout.GetBorder();

            ApplyAttributesOfLayoutBorder(border);
            //数据框
            IElement[] dfs = layout.QueryElements((e) => { return(e is IDataFrame); });
            ApplyAttributesOfDataFrame(doc.DataFrames, dfs, layout);
            //图列
            ApplyAttributesOfElement(layout.QueryElements((e) => { return(e != null); }));
        }
Exemple #11
0
        public string CreateMCSI(ISmartSession session)
        {
            IRasterDrawing drawing = GetRasterDrawingArugment(session);

            if (drawing == null)
            {
                return(null);
            }
            string theme = GetLayoutTheme("MCSI");

            if (string.IsNullOrWhiteSpace(theme))
            {
                return(null);
            }
            int    width, height;
            string bmpFilename = CreateViewBitmap(drawing, session, out width, out height);
            string gxdFilename = GetGxdFilename(drawing.FileName, "MCSI");

            if (string.IsNullOrWhiteSpace(gxdFilename))
            {
                return(null);
            }
            //加载模版
            ILayoutTemplate temp = GetTemplateByArg(theme);

            if (temp == null)
            {
                return(null);
            }
            ILayout layout = temp.Layout;

            FitSizeToTemplateWidth(layout, width, height);
            //生成文档,并应用变量
            IGxdDocument gxdDoc = GetDocument(bmpFilename, temp);

            TryApplyVars(gxdDoc.GxdTemplateHost.LayoutTemplate, drawing);
            TrySetAttributesOfElements(gxdDoc);
            gxdDoc.SaveAs(gxdFilename);
            //IExtractResult er = new FileExtractResult("MCSI", gxdFilename) as IExtractResult;
            return(gxdFilename);
        }
Exemple #12
0
        public string CreateThematicGraphic(string dataFileName, string outIdentify, string extInfos, params object[] options)
        {
            if (_isNeedFitToTemplateWidth)
            {
                using (IRasterDataProvider prd = GeoDataDriver.Open(dataFileName) as IRasterDataProvider)
                {
                    if (prd != null)
                    {
                        FitTemplateWidth(_template.Layout, prd.Width, prd.Height);
                    }
                }
            }
            string       _fname = GetOutputGxdFileName(dataFileName, outIdentify, extInfos);
            IGxdDocument _doc   = GetDocument(dataFileName, _aoi, _template, options != null && options.Length > 0 ? options[0] : null);

            if (_doc == null)
            {
                return(null);
            }
            if (options.Length > 1)
            {
                PrjEnvelope envelope = options[1] as PrjEnvelope;
                if (envelope != null)
                {
                    ILayout              layout = _doc.GxdTemplateHost.LayoutTemplate.Layout;
                    IElement[]           dfs    = layout.QueryElements((e) => { return(e is IDataFrame); });
                    List <IGxdDataFrame> list   = _doc.DataFrames;
                    if (dfs != null && list != null && dfs.Length > 0 && list.Count > 0)
                    {
                        for (int i = 0; i < dfs.Length; i++)
                        {
                            ApplyAttributesOfDataFrame(list[i], dfs[i] as IDataFrame, layout, envelope);
                        }
                    }
                }
            }
            _doc.SaveAs(_fname);
            return(_fname);
        }
Exemple #13
0
        public override bool Open(string fname, out bool memoryIsNotEnough)
        {
            memoryIsNotEnough = false;
            string        text   = OpenFileFactory.GetTextByFileName(fname);
            ILayoutViewer viewer = new LayoutViewer(text);

            (viewer as LayoutViewer).Tag = fname;
            (viewer as LayoutViewer).SetSession(_session);
            _session.SmartWindowManager.DisplayWindow(viewer);
            if (viewer != null)
            {
                string extName = Path.GetExtension(fname).ToUpper();
                switch (extName)
                {
                case ".GXT":
                    ILayoutTemplate template = LayoutTemplate.LoadTemplateFrom(fname);
                    if (template != null)
                    {
                        viewer.LayoutHost.ApplyTemplate(template);
                        viewer.LayoutHost.ToSuitedSize();
                        AnsynRefreshData(viewer);
                        _session.UIFrameworkHelper.ActiveTab("专题制图");
                    }
                    break;

                case ".GXD":
                    IGxdDocument doc = GxdDocument.LoadFrom(fname);
                    if (doc != null)
                    {
                        viewer.LayoutHost.ApplyGxdDocument(doc);
                        viewer.LayoutHost.ToSuitedSize();
                        AnsynRefreshData(viewer);
                        //_session.UIFrameworkHelper.ActiveTab("专题制图");
                    }
                    break;
                }
            }
            return(true);
        }
Exemple #14
0
        private string GenerateRasterThemeGraphy(string dstFile, string drawFName)
        {
            string          templatName    = GetLayoutTheme("0SDI");
            string          colorTabelName = "colortablename=" + "FLDDBLV";
            ILayoutTemplate t = GetTemplateByArg(templatName);

            if (t == null)
            {
                return(null);
            }
            ILayout layout = t.Layout;
            int     width, height;

            GeoDo.RSS.Core.DF.CoordEnvelope envelope = null;
            using (IRasterDataProvider dataPrd = GeoDataDriver.Open(dstFile) as IRasterDataProvider)
            {
                width    = dataPrd.Width;
                height   = dataPrd.Height;
                envelope = dataPrd.CoordEnvelope;
            }
            FitSizeToTemplateWidth(layout, width, height);
            //生成文档,并应用变量
            TryApplyVars(t, drawFName);
            IGxdDocument  gxdDoc = CreateDocument(t, string.IsNullOrEmpty(colorTabelName) ? null : colorTabelName);
            IGxdDataFrame gxdDf  = gxdDoc.DataFrames.Count > 0 ? gxdDoc.DataFrames[0] : null;

            if (gxdDf != null)
            {
                string[]       arguments = new string[] { string.IsNullOrEmpty(colorTabelName) ? null : colorTabelName };
                IGxdRasterItem rst       = new GxdRasterItem(dstFile, colorTabelName, arguments, colorTabelName);//这里传具体的色标定义标识
                gxdDf.GxdRasterItems.Add(rst);
            }
            TrySetAttributesOfElements(gxdDoc);
            string docFname = GetGxdFilename(dstFile, "0SDI");

            gxdDoc.SaveAs(docFname);
            return(docFname);
        }
Exemple #15
0
        public void ApplyGxdDocument(IGxdDocument doc)
        {
            if (doc == null)
            {
                return;
            }
            //
            Dictionary <string, ILayer> gridLayers = null;
            IGxdTemplateHost            tempHost   = doc.GxdTemplateHost;

            if (tempHost != null)
            {
                gridLayers = ApplyTemplate(tempHost.LayoutTemplate, false);
            }
            //
            List <IGxdDataFrame> dfs = doc.DataFrames;

            if (dfs != null && dfs.Count > 0)
            {
                foreach (IGxdDataFrame df in dfs)
                {
                    if (GxdDocument.GxdAddDataFrameExecutor != null)
                    {
                        GxdDocument.GxdAddDataFrameExecutor(doc.FullPath, df, this);
                    }
                    //将经纬网格添加到最上层
                    if (gridLayers != null && gridLayers.ContainsKey(df.Name))
                    {
                        IElement[] eles = _layout.QueryElements((e) => { return(e is IDataFrame && (e as IDataFrame).Name == df.Name); });
                        if (eles != null && eles.Length > 0)
                        {
                            ((eles[0] as IDataFrame).Provider as IDataFrameDataProvider).Canvas.LayerContainer.Layers.Add(gridLayers[df.Name]);
                        }
                    }
                }
            }
        }
        public void Generate(string dataFileName, string templateName, int[] aoi, string extInfos, string outIdentify, params object[] options)
        {
            _doc   = null;
            _fname = null;
            ILayoutTemplate t = GetTemplateByName(dataFileName, templateName);

            if (t == null)
            {
                return;
            }
            if (IsFitToTemplateWidth)
            {
                using (IRasterDataProvider prd = GeoDataDriver.Open(dataFileName) as IRasterDataProvider)
                {
                    if (prd != null)
                    {
                        FitTemplateWidth(t.Layout, prd.Width, prd.Height);
                    }
                }
            }
            _fname = GetOutputGxdFileName(dataFileName, outIdentify, extInfos);
            _doc   = GetDocument(dataFileName, aoi, t, options != null && options.Length > 0 ? options[0] : null);
            TrySetAttributesOfElements(_doc);
        }
Exemple #17
0
        public void ExportImageOfGxdFiles()
        {
            if (!AutoGeneratorSettings.CurrentSettings.IsOutputPng)
            {
                return;
            }
            if (AutoGeneratorSettings.CurrentSettings.GxdFileNames == null || AutoGeneratorSettings.CurrentSettings.GxdFileNames.Count == 0)
            {
                return;
            }
            bool isNeedCopy = !string.IsNullOrEmpty(AutoGeneratorSettings.CurrentSettings.FolderOfCopyTo);

            if (isNeedCopy)
            {
                AutoGeneratorSettings.CurrentSettings.GeneratedFileNames.Clear();
            }
            IContextMessage msg = Session.SmartWindowManager.SmartToolWindowFactory.GetSmartToolWindow(9006) as IContextMessage;

            if (msg != null)
            {
                msg.PrintMessage("开始导出专题图图片......");
            }
            foreach (string fname in GxdFileNames)
            {
                IGxdDocument doc = GxdDocument.LoadFrom(fname);
                if (doc == null)
                {
                    if (msg != null)
                    {
                        msg.PrintMessage("专题图\"" + fname + "\"打开失败。");
                    }
                    return;
                }
                using (LayoutViewer viewer = new LayoutViewer())
                {
                    viewer.LayoutHost.ApplyGxdDocument(doc);
                    using (Bitmap bm = viewer.LayoutHost.ExportToBitmap(System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                    {
                        if (bm == null)
                        {
                            if (msg != null)
                            {
                                msg.PrintMessage("专题图\"" + fname + "\"导出图片失败。");
                            }
                            return;
                        }
                        string fileName = Path.Combine(Path.GetDirectoryName(fname), Path.GetFileNameWithoutExtension(fname) + ".png");
                        bm.Save(fileName, ImageFormat.Png);
                        if (isNeedCopy)
                        {
                            AutoGeneratorSettings.CurrentSettings.GeneratedFileNames.Add(fileName);
                        }
                    }
                }
                if (msg != null)
                {
                    msg.PrintMessage("已导出专题图\"" + fname + "\"。");
                }
            }
            //
            if (msg != null)
            {
                msg.PrintMessage("导出专题图图片结束。");
            }
            //
            CopyFileToCopyFolder();
        }
        //应用变量
        private void TryApplyVars(IGxdDocument doc, string fileName)
        {
            ILayoutTemplate             temp     = doc.GxdTemplateHost.LayoutTemplate;
            RasterIdentify              identify = new RasterIdentify(fileName);
            Dictionary <string, string> vars     = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(identify.Satellite))
            {
                string sate = identify.Satellite.ToUpper();
                if (sate.Contains("FY3"))
                {
                    sate = sate.Replace("FY3", "FY-3");
                }
                else if (sate.Contains("FY2"))
                {
                    sate = sate.Replace("FY2", "FY-2");
                }
                vars.Add("{Satellite}", sate);
            }
            if (!string.IsNullOrEmpty(identify.Sensor))
            {
                vars.Add("{Sensor}", identify.Sensor);
            }
            if (!string.IsNullOrEmpty(identify.ProductName))
            {
                vars.Add("{Product}", identify.ProductName);
            }
            if (string.IsNullOrWhiteSpace(DateString))
            {
                if (identify.OrbitDateTime != DateTime.MinValue)
                {
                    identify.OrbitDateTime.AddHours(8);
                    vars.Add("{OrbitDateTime}", identify.OrbitDateTime.AddHours(8).ToString("yyyy年MM月dd日 HH:mm") + " (北京时)");
                }
                if (identify.MaxOrbitDate != DateTime.MaxValue && identify.MinOrbitDate != DateTime.MinValue)
                {
                    DateTime minTime = identify.MinOrbitDate.AddHours(8);
                    DateTime maxTime = identify.MaxOrbitDate.AddHours(8);
                    vars.Add("{MinOrbitDateTime~MaxOrbitDateTime}", minTime.ToString("yyyy年MM月dd日 HH:mm") + " ~ " + maxTime.ToString("yyyy年MM月dd日 HH:mm"));
                }
            }
            else
            {
                vars.Add("{OrbitDateTime}", DateString);
                vars.Add("{MinOrbitDateTime~MaxOrbitDateTime}", DateString);
            }
            if (!string.IsNullOrWhiteSpace(TimesCount))
            {
                vars.Add("{ValidDays}", "有效天数:" + TimesCount);
            }
            else
            {
                vars.Add("{ValidDays}", "");
            }

            if (!IsVector(fileName))
            {
                using (RasterDataProvider rdd = GeoDataDriver.Open(fileName) as RasterDataProvider)
                {
                    if (rdd != null)
                    {
                        string resolutionStr = Math.Round(rdd.ResolutionX, 4).ToString();
                        vars.Add("{resolution}", resolutionStr);
                        if (rdd.SpatialRef == null)
                        {
                            vars["{resolution}"] += "度";
                            vars.Add("{projection}", "等经纬度");
                        }
                        else if (rdd.SpatialRef.GeographicsCoordSystem == null)
                        {
                            vars.Add("{projection}", "");
                        }
                        else if (rdd.SpatialRef.ProjectionCoordSystem == null)
                        {
                            vars["{resolution}"] += "度";
                            vars.Add("{projection}", "等经纬度");
                        }
                        else
                        {
                            string targatName  = string.Empty;
                            string projectName = rdd.SpatialRef.ProjectionCoordSystem.Name.Name;
                            GetProjectName(projectName, out targatName);
                            vars.Add("{projection}", targatName);
                        }
                    }
                }
            }
            temp.ApplyVars(vars);
        }