Arcgis 符号库中图形到Grid控件的加载

2024-01-05 23:08

本文主要是介绍Arcgis 符号库中图形到Grid控件的加载,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

///调用方法
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            // 如果是符号样式列
            if (e.Column.Equals(colSTYLEIMAGE))
            {
                string strStyleCode = e.DisplayText;
                Rectangle r = e.Bounds;
                if (GISOpr.getInstance().AllStyleList.Contains(strStyleCode))
                {
                    ISymbol symbol = GISOpr.getInstance().AllStyleList[strStyleCode] as ISymbol;
                    if (symbol != null)
                    {
                        Image image = GISGlobal.SymbolToBitmp(symbol, r.Width, r.Height, 1);
                        e.Graphics.DrawImageUnscaled(image, r);
                        e.Handled = true;
                    }
                }
            }
        }
/// <summary>
        /// 全局初始化方法:
        ///     初始化数据库连接
        ///     初始化Nhibernate环境
        ///     加载Nhibernate类库及映射文件
        ///     同时获取初始化系统参数
        /// 该方法在所有方法之前调用
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool GlobalInit(ZUser user)
        {
            bool bresult = false;
            DBCore db = new DBCore(true);

            // 设置当前用户
            currUser = user;

            try
            {
                paramList = db.GetAll(typeof(Tbsysparams), "Paramid");
                foreach (Tbsysparams param in paramList)
                {
                    if (param.Paramenname.ToUpper() == "SDESERVER")
                        m_sServer = param.Paramvalue;
                    if (param.Paramenname.ToUpper() == "SDEINSTANCE")
                        m_sInstance = param.Paramvalue;
                    if (param.Paramenname.ToUpper() == "SDEVERSION")
                        m_sVersion = param.Paramvalue;
                    if (param.Paramenname.ToUpper() == "SDEUSER")
                        m_sUser = param.Paramvalue;
                    if (param.Paramenname.ToUpper() == "SDEPASSWORD")
                        m_sPassword = param.Paramvalue;
                    if (param.Paramenname.ToUpper() == "GEOOBJFIELDNAME")
                        m_sGeoObjFieldName = param.Paramvalue;
                    if (param.Paramenname.ToUpper() == "SERVERSTYLEFILENAME")
                        m_sRelStyleFileDir = param.Paramvalue;
                }
                bresult = true;
            }
            finally
            {
                db.CloseSession();
                db = null;
            }
            return bresult;
        }
/// <summary>
        /// 全局初始化ArcEngine组件 方法
        /// 与CloseGISLicense方法对应,只需要调用一次
        /// 该方法在OpenGISConn方法之前调用,以保证组件被正常初始化了
        /// </summary>
        /// <param name="err">返回初始化过程中的提示信息</param>
        /// <returns>返回true表示初始成功</returns>
        public bool InitGISLicense(out string err)
        {
            bool bresult = true;
            esriLicenseStatus licenseStatus;
            err = string.Empty;

            this.m_nLicenseSem += 1;

            // 初次初始化
            if (this.m_nLicenseSem == 1 && this.m_pAoInitialize == null)
            {

                // first try copy protection EngineGeoDB
                licenseStatus = this.CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
                if (licenseStatus == esriLicenseStatus.esriLicenseNotLicensed)
                {
                    // next try Desktop Desktop ArcEngine
                    licenseStatus = this.CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcEditor);

                    if (licenseStatus == esriLicenseStatus.esriLicenseNotLicensed ||
                        licenseStatus == esriLicenseStatus.esriLicenseUnavailable)
                        licenseStatus = this.CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcInfo);
                }

                if (licenseStatus == esriLicenseStatus.esriLicenseNotLicensed)
                {
                    err = "You are not licensed to run this product";
                    bresult = false;
                }
                else if (licenseStatus == esriLicenseStatus.esriLicenseUnavailable)
                {
                    err = "There are insufient licenses to run";
                    bresult = false;
                }
                else if (licenseStatus == esriLicenseStatus.esriLicenseFailure)
                {
                    err = "Unexpected license failure please contact you administrator";
                    bresult = false;
                }
                else if (licenseStatus == esriLicenseStatus.esriLicenseAlreadyInitialized)
                {
                    err = "You license has already been initialized please check you implementation";
                    bresult = false;
                }
                else if (licenseStatus == esriLicenseStatus.esriLicenseCheckedOut)
                    err = "Licenses checked out successfully";
            }

            return bresult;
        }
/// <summary>
        /// 初始化GIS环境,建立SDE数据连接,为地图加载做准备
        /// </summary>
        /// <returns></returns>
        public bool OpenGISConn()
        {
            Hashtable propList = new Hashtable();
            if (!bconnected)
            {
                try
                {
                    propList.Add("SERVER", m_sServer);
                    propList.Add("INSTANCE", m_sInstance);
                    propList.Add("VERSION", m_sVersion);
                    propList.Add("USER", m_sUser);
                    propList.Add("PASSWORD", m_sPassword);

                    ws = this.GetWorkspace(propList, "esriDataSourcesGDB.SdeWorkspaceFactory");
                    bconnected = true;
                }
                finally
                {
                    propList = null;
                }
            }

            return bconnected;
        }

        /// <summary>
        /// 加载系统所设置的ServerStyle符号
        /// 并将符号全部保存到当前的HashTable中,Key为地物代码,Value为对应符号的引用
        /// </summary>
        /// <returns></returns>
        public bool LoadServerStyle(string sAppPath)
        {
            // ServerStyle类
            ServerStyleGalleryClass styleFile = null;
            // 导入符号接口
            IStyleGallery pStyleGallery = null;
            // 设置符号文件位置
            IStyleGalleryStorage pStyleStore = null;
            // 符号枚举接口
            IEnumStyleGalleryItem pEnuStyleItem = null;
            // 单个符号对象
            IStyleGalleryItem pStyleItem = null;

            string sFullPath = sAppPath + "//" + m_sRelStyleFileDir;
            string sFileName = string.Empty;


            this.m_nStyleSem += 1;

            if (this.m_nStyleSem==1 && !bStyleLoaded && Directory.Exists(sFullPath))
            {
               
                styleFile = new ServerStyleGalleryClass();
                pStyleGallery = styleFile as IStyleGallery;
                pStyleStore = styleFile as IStyleGalleryStorage;

                string[] fileList = Directory.GetFiles(sFullPath, "*.ServerStyle");
                for (int i = 0; i < fileList.Length; i++)
                {
                    sFileName = fileList[i];
                    // 导入*.ServerStyle符号
                    pStyleGallery.ImportStyle(sFileName);
                    pStyleStore.TargetFile = sFileName;

                    // 枚举所有点符号
                    pEnuStyleItem = pStyleGallery.get_Items("Marker Symbols", sFileName, "");

                    pEnuStyleItem.Reset();
                    pStyleItem = pEnuStyleItem.Next();

                    while (pStyleItem != null)
                    {
                        // 名称,分类都设置为GeObjNum
                        if (!stylesList.Contains(pStyleItem.Name))
                            stylesList.Add(pStyleItem.Name, pStyleItem.Item);

                        pStyleItem = pEnuStyleItem.Next();
                    }

                    // 枚举所有线符号
                    pEnuStyleItem = pStyleGallery.get_Items("Line Symbols", sFileName, "");

                    pEnuStyleItem.Reset();
                    pStyleItem = pEnuStyleItem.Next();

                    while (pStyleItem != null)
                    {
                        // 名称,分类都设置为GeObjNum
                        if (!stylesList.Contains(pStyleItem.Name))
                            stylesList.Add(pStyleItem.Name, pStyleItem.Item);

                        pStyleItem = pEnuStyleItem.Next();
                    }

                    // 枚举所有面符号
                    pEnuStyleItem = pStyleGallery.get_Items("Fill Symbols", sFileName, "");

                    pEnuStyleItem.Reset();
                    pStyleItem = pEnuStyleItem.Next();

                    while (pStyleItem != null)
                    {
                        // 名称,分类都设置为GeObjNum
                        // 将符号的地物代码、及符号放入全局符号列表中
                        if (!stylesList.Contains(pStyleItem.Name))
                            stylesList.Add(pStyleItem.Name, pStyleItem.Item);

                        pStyleItem = pEnuStyleItem.Next();
                    }

                    bStyleLoaded = true;
                }
            }
            return bStyleLoaded;
        }

/// <summary>
        /// 将ISymbol 转换为bitmap对象
        /// </summary>
        /// <param name="pSymbol">符号对象</param>
        /// <param name="iwidth">显示的image宽</param>
        /// <param name="iheight">显示的image高</param>
        /// <param name="lGap">显示的image边距:1或2即可</param>
        /// <returns></returns>
        public static System.Drawing.Bitmap SymbolToBitmp(ESRI.ArcGIS.Display.ISymbol pSymbol, int iwidth, int iheight, int lGap)
        {
            ///根据高宽创建图象
            Bitmap bmp = new Bitmap(iwidth, iheight);
            Graphics gImage = Graphics.FromImage(bmp);//转化成Graphics
            gImage.Clear(Color.White);                //清除底色,设置为白色
            double dpi = gImage.DpiX;                 //

            IEnvelope pEnvelope = new EnvelopeClass();//创建矩形范围
            pEnvelope.PutCoords(0, 0, (double)bmp.Width, (double)bmp.Height);
        //设置边界值
            tagRECT deviceRect;
            deviceRect.left = lGap;
            deviceRect.right = bmp.Width - lGap;
            deviceRect.top = lGap;
            deviceRect.bottom = bmp.Height - lGap;

            IDisplayTransformation pDisplayTransformation = new DisplayTransformationClass();
            pDisplayTransformation.VisibleBounds = pEnvelope;
            pDisplayTransformation.Bounds = pEnvelope;
            pDisplayTransformation.set_DeviceFrame(ref deviceRect);
            pDisplayTransformation.Resolution = dpi;

            IGeometry pGeo = CreateSymShape(pSymbol, pEnvelope);

            System.IntPtr hdc = new IntPtr();
            hdc = gImage.GetHdc();

            pSymbol.SetupDC((int)hdc, pDisplayTransformation);
            pSymbol.Draw(pGeo);
            pSymbol.ResetDC();
            gImage.ReleaseHdc(hdc);
            gImage.Dispose();

            return bmp;

        }

        /// <summary>
        /// 根据符号类型 获取该符号的显示空间描述
        /// </summary>
        /// <param name="pSymbol"></param>
        /// <param name="pEnvelope"></param>
        /// <returns></returns>
        public static ESRI.ArcGIS.Geometry.IGeometry CreateSymShape(ISymbol pSymbol, IEnvelope pEnvelope)
        {
            ESRI.ArcGIS.Display.IMarkerSymbol IMarkerSym;
            IMarkerSym = pSymbol as IMarkerSymbol;
            if (IMarkerSym != null)
            {

                IArea pArea;
                pArea = pEnvelope as IArea;
                return pArea.Centroid as IGeometry;
            }
            else
            {

                ESRI.ArcGIS.Display.ILineSymbol IlineSym;
                ESRI.ArcGIS.Display.ITextSymbol ITextSym;
                IlineSym = pSymbol as ILineSymbol;
                ITextSym = pSymbol as ITextSymbol;
                if (IlineSym != null || ITextSym != null)
                {

                    ESRI.ArcGIS.Geometry.IPolyline IpLine;
                    IpLine = new PolylineClass();
                    IpLine.FromPoint = pEnvelope.LowerLeft;
                    IpLine.ToPoint = pEnvelope.UpperRight;
                    return IpLine as IGeometry;
                }
                else
                {

                    return pEnvelope as IGeometry;
                }
            }
        }

这篇关于Arcgis 符号库中图形到Grid控件的加载的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/574454

相关文章

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

Flutter 进阶:绘制加载动画

绘制加载动画:由小圆组成的大圆 1. 定义 LoadingScreen 类2. 实现 _LoadingScreenState 类3. 定义 LoadingPainter 类4. 总结 实现加载动画 我们需要定义两个类:LoadingScreen 和 LoadingPainter。LoadingScreen 负责控制动画的状态,而 LoadingPainter 则负责绘制动画。

lvgl8.3.6 控件垂直布局 label控件在image控件的下方显示

在使用 LVGL 8.3.6 创建一个垂直布局,其中 label 控件位于 image 控件下方,你可以使用 lv_obj_set_flex_flow 来设置布局为垂直,并确保 label 控件在 image 控件后添加。这里是如何步骤性地实现它的一个基本示例: 创建父容器:首先创建一个容器对象,该对象将作为布局的基础。设置容器为垂直布局:使用 lv_obj_set_flex_flow 设置容器

小程序button控件上下边框的显示和隐藏

问题 想使用button自带的loading图标功能,但又不需要button显示边框线 button控件有一条淡灰色的边框,在控件上了样式 border:none; 无法让button边框隐藏 代码如下: <button class="btn">.btn{border:none; /*一般使用这个就是可以去掉边框了*/} 解决方案 发现button控件有一个伪元素(::after

第六章习题11.输出以下图形

🌏个人博客:尹蓝锐的博客 希望文章能够给到初学的你一些启发~ 如果觉得文章对你有帮助的话,点赞 + 关注+ 收藏支持一下笔者吧~ 1、题目要求: 输出以下图形

MFC中Spin Control控件使用,同时数据在Edit Control中显示

实现mfc spin control 上下滚动,只需捕捉spin control 的 UDN_DELTAPOD 消息,如下:  OnDeltaposSpin1(NMHDR *pNMHDR, LRESULT *pResult) {  LPNMUPDOWN pNMUpDown = reinterpret_cast(pNMHDR);  // TODO: 在此添加控件通知处理程序代码    if

LibSVM学习(六)——easy.py和grid.py的使用

我们在“LibSVM学习(一)”中,讲到libSVM有一个tools文件夹,里面包含有四个python文件,是用来对参数优选的。其中,常用到的是easy.py和grid.py两个文件。其实,网上也有相应的说明,但很不系统,下面结合本人的经验,对使用方法做个说明。        这两个文件都要用python(可以在http://www.python.org上下载到,需要安装)和绘图工具gnup

使用WebP解决网站加载速度问题,这些细节你需要了解

说到网页的图片格式,大家最常想到的可能是JPEG、PNG,毕竟这些老牌格式陪伴我们这么多年。然而,近几年,有一个格式悄悄崭露头角,那就是WebP。很多人可能听说过,但到底它好在哪?你的网站或者项目是不是也应该用WebP呢?别着急,今天咱们就来好好聊聊WebP这个图片格式的前世今生,以及它值不值得你花时间去用。 为什么会有WebP? 你有没有遇到过这样的情况?网页加载特别慢,尤其是那

MFC 控件重绘(2) NM_CUSTOMDRAW, WM_DRAWITEM, 虚函数DrawItem

控件重绘有三种方法: 1 设定界面属性 2 利用Windows的消息机制,通过Windows消息映射(Message Mapping)和反映射(Message Reflecting),在合适的时机修改控件的状态和行为。此方式涉及NM_CUSTOMDRAW和WM_DRAWITEM 3 利用虚函数机制,重载虚函数。即DrawItem虚函数。 对于NM_CUSTOMDRAW,某些支持此消息的控件

一个图形引擎的画面风格是由那些因素(技术)决定的?

可能很多人第一直覺會認為shader決定了視覺風格,但我認為可以從多個方面去考慮。 1. 幾何模型 一個畫面由多個成分組成,最基本的應該是其結構,在圖形學中通常稱為幾何模型。 一些引擎,如Quake/UE,有比較強的Brush建模功能(或應稱作CSG),製作建築比較方便。而CE則有較強的大型地表、植被、水體等功能,做室外自然環境十分出色。而另一些遊戲類型專用的引擎,例