Arcgis---使用sql数据库中的数据刷新图层

使用sql语句select需要的数据,通过Arcgis的API插入到相应图层文件中,插入的数据可以在.dbf文件中查看,最后使用Arcgis的API刷新图层即可

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Analyst3D;
using Wellcomm.DBUtility.Ibatis;   // 自定义
using Wellcomm.Model;              // 自定义

namespace Wellcomm.BLL.GIS
{
    /// <summary>
    /// 覆盖网格,gxid,gyid,enodeb,ci,cellname
    /// </summary>
    public class OperateCoverGirdLayer
    {
        private IFeatureLayer pFeatureLayer;
        private IFeatureClass pFeatureClass;
        private int RecePowerIndex;
        private int PathLossIndex;
        private int GXIDIndex;
        private int GYIDIndex;
        private int cellNameIndex;
        private int eNodeBIndex;
        private int CIIndex;

        // 列名
        public OperateCoverGirdLayer()
        {
            pFeatureLayer = GISMapApplication.Instance.GetLayer("覆盖") as IFeatureLayer;
            pFeatureClass=pFeatureLayer.FeatureClass;
            this.RecePowerIndex=pFeatureClass.FindField("RecePower");
            this.PathLossIndex=pFeatureClass.FindField("PathLoss");
            this.GXIDIndex = pFeatureClass.FindField("GXID");
            this.GYIDIndex = pFeatureClass.FindField("GYID");
            this.cellNameIndex = pFeatureClass.FindField("CellName");
            this.eNodeBIndex = pFeatureClass.FindField("eNodeB");
            this.CIIndex = pFeatureClass.FindField("CI");
        }


        /// <summary>
        /// 删除图层所有要素
        /// </summary>
        public void ClearLayer()
        {
            FeatureUtilities.DeleteFeatureLayerFeatrues(this.pFeatureLayer);
        }

        /// <summary>
        /// 构造小区覆盖网格
        /// </summary>
        /// <param name="cellname"></param>
        /// <param name="enodeb"></param>
        /// <param name="ci"></param>
        public void constuctCellGrids(string cellname, int enodeb, int ci)
        {
            DataTable gridTable = new DataTable();
            Hashtable ht = new Hashtable();
            ht["eNodeB"] = enodeb;
            ht["CI"] = ci;
            gridTable = IbatisHelper.ExecuteQueryForDataTable("GetSpecifiedCellGrids", ht);
            /*
             * 通过xml读取数据库
             * <!--获取指定小区名称的网格-->
                <select id="GetSpecifiedCellGrids" parameterClass="Hashtable">
                    select a.GXID, a.GYID, b.MinLong, b.MinLat, b.MaxLong, b.MaxLat, a.ReceivedPowerdbm, a.PathLoss 
             *      from tbGridPathloss a, tbGridDem b 
             *      where a.GXID = b.GXID and a.GYID = b.GYID 
             *      and a.eNodeB = '$eNodeB$' and a.CI = '$CI$' 
             *      and a.ReceivedPowerdbm > -130
                </select>
             */

            IDataset dataset = (IDataset)pFeatureLayer.FeatureClass;
            IWorkspace workspace = dataset.Workspace;
            IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;
            workspaceEdit.StartEditing(true);
            workspaceEdit.StartEditOperation();

            IFeatureCursor pFeatureCursor = pFeatureClass.Insert(true);
            IFeatureBuffer pFeatureBuffer;

            int gxid, gyid;
            float x1, y1, x2, y2;
            float recePower, pathLoss;
            //循环添加
            foreach (DataRow dataRow in gridTable.Rows)
            {
                gxid = int.Parse(dataRow[0].ToString());
                gyid = int.Parse(dataRow[1].ToString());

                if (!(float.TryParse(dataRow[2].ToString(), out x1) && float.TryParse(dataRow[3].ToString(), out y1) && float.TryParse(dataRow[4].ToString(), out x2) && float.TryParse(dataRow[5].ToString(), out y2) && float.TryParse(dataRow[6].ToString(), out recePower) && float.TryParse(dataRow[7].ToString(), out pathLoss)))
                    continue;

                IPoint pointA = GeometryUtilities.ConstructPoint2D(x1, y1);
                IPoint pointB = GeometryUtilities.ConstructPoint2D(x2, y1);
                IPoint pointC = GeometryUtilities.ConstructPoint2D(x2, y2);
                IPoint pointD = GeometryUtilities.ConstructPoint2D(x1, y2);

                IGeometryCollection pGeometryColl = GeometryUtilities.ConstructPolygon(new IPoint[] { pointA, pointB, pointC, pointD });


                pFeatureBuffer = pFeatureClass.CreateFeatureBuffer();
                pFeatureBuffer.Shape = pGeometryColl as IGeometry;   // 形状
                pFeatureBuffer.set_Value(this.GXIDIndex, gxid);
                pFeatureBuffer.set_Value(this.GYIDIndex, gyid);
                pFeatureBuffer.set_Value(this.eNodeBIndex, enodeb);
                pFeatureBuffer.set_Value(this.CIIndex, ci);
                pFeatureBuffer.set_Value(this.cellNameIndex, cellname);
                pFeatureBuffer.set_Value(this.RecePowerIndex, recePower);
                pFeatureBuffer.set_Value(this.PathLossIndex, pathLoss);
                pFeatureCursor.InsertFeature(pFeatureBuffer);
            }

            //一次性提交
            pFeatureCursor.Flush();

            //stop editing   
            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);

            GISMapApplication.Instance.RefreshLayer(pFeatureLayer);
        }
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Analyst3D;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;

namespace Wellcomm.BLL.GIS
{
    /// <summary>
    /// GIS的入口操作(采用单例模式) 
    /// </summary>
    public class GISMapApplication
    {
        private static GISMapApplication instance = null; //当前对象的实例
        private AxSceneControl m_axSceneControl = null;
        private ISceneControl m_sceneControl = null;

        public AxSceneControl AxSceneControl
        {
            get { return m_axSceneControl; }
            set { m_axSceneControl = value; }
        }

        /// <summary>
        /// 地图控件的引用
        /// </summary>
        public ISceneControl SceneControl
        {
            get { return m_sceneControl; }
            set { m_sceneControl = value; }
        }

        /// <summary>
        /// 初始化的一些方法
        /// </summary>
        public void Init(AxSceneControl axSceneControl)
        {
            if (axSceneControl != null)
            {
                this.m_axSceneControl = axSceneControl;
                m_sceneControl = axSceneControl.Object as ISceneControl;
            }
        }

        /// <summary>
        /// 当前实例对象(单例模式)
        /// </summary>
        public static GISMapApplication Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (m_syncObject)
                    {
                        if (instance == null)
                        {
                            instance = new GISMapApplication();
                        }
                    }

                }
                return instance;
            }
        }

        /// <summary>
        /// 刷新指定图层
        /// </summary>
        /// <param name="pObject"></param>
        public void RefreshLayer(object pObject)
        {
            if (this.m_sceneControl == null)
                return;

            ISceneGraph pSceneGragh = m_sceneControl.SceneGraph;
            pSceneGragh.Invalidate(pObject, true, false);
            pSceneGragh.ActiveViewer.Redraw(true);
            pSceneGragh.RefreshViewers();
        }
    }
using System;
using System.Linq;
using System.Collections.Generic;
using Wellcomm.BLL.Geometric;
using ESRI.ArcGIS.Geometry;

namespace Wellcomm.BLL.GIS
{
    public static class GeometryUtilities
    {
        public static IGeometryCollection ConstructPolygon(IPoint[] pointArray)
        {
            //创建一个Ring对象,通过ISegmentCollection接口向其中添加Segment对象
            object o = Type.Missing;
            ISegmentCollection pSegCollection = new RingClass();
            for (int i = 0; i < pointArray.Length-1; i++)
            {
                IPoint from = pointArray[i];
                IPoint to = pointArray[i+1];

                ILine pLine = new LineClass();
                //设置Line对象的起始终止点
                pLine.PutCoords(from, to);
                //QI到ISegment
                ISegment pSegment = pLine as ISegment;
                pSegCollection.AddSegment(pSegment, ref o, ref o);
            }
            //QI到IRing接口封闭Ring对象,使其有效
            IRing pRing = pSegCollection as IRing;
            pRing.Close();

            //使用Ring对象构建Polygon对象
            IGeometryCollection pGeometryColl = new PolygonClass();
            pGeometryColl.AddGeometry(pRing, ref o, ref o);

            return pGeometryColl; 
        }
    }

}
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值