Arcgis---从数据库中获取数据绘制道路

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
{

    public class OperateRoadLayer
    {
        private IFeatureLayer pFeatureLayer;
        private IFeatureClass pFeatureClass;

        // 列名
        public OperateRoadLayer()
        {
            pFeatureLayer = GISMapApplication.Instance.GetLayer(LayerNames.Street) as IFeatureLayer;
            pFeatureClass = pFeatureLayer.FeatureClass;
        }


        /// <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 constucRoad(ref DataTable gridTable)
        {
            //DataTable gridTable = new DataTable();
            //Hashtable ht = new Hashtable();
            //ht["minX"] = minX;
            //ht["minY"] = minY;
            //ht["maxX"] = maxX;
            //ht["maxY"] = maxY;
            //gridTable = IbatisHelper.ExecuteQueryForDataTable("GetStreet", ht);

            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;

            if (gridTable.Rows.Count == 0)
            {
                return;
            }

            double x, y;
            int roadID;
            DataRow dataRow = gridTable.Rows[0];
            if (!(Double.TryParse(dataRow[2].ToString(), out x) && Double.TryParse(dataRow[3].ToString(), out y)))
                return;
            if (!Int32.TryParse(dataRow[0].ToString(), out roadID))
                return; 
            IPoint from = GeometryUtilities.ConstructPoint2D(x, y);

            //循环添加
            List<ESRI.ArcGIS.Geometry.IPoint> linePoints = new List<ESRI.ArcGIS.Geometry.IPoint>();
            linePoints.Add(from);
            for(int i=1; i<gridTable.Rows.Count; i++)
            {
                dataRow = gridTable.Rows[i];
                if (! (Double.TryParse(dataRow[2].ToString(), out x) && Double.TryParse(dataRow[3].ToString(), out y)) )
                    continue;

                int id;
                if (!Int32.TryParse(dataRow[0].ToString(), out id))
                    return; 

                IPoint to = GeometryUtilities.ConstructPoint2D(x, y);

                if (id == roadID)  // 该点位于当前道路上
                {
                    linePoints.Add(to);
                }
                else   // 一条新路
                {
                    roadID = id;

                    if (linePoints.Count >= 2)  // 根据一系列点绘制线上一条路
                    {
                        ISegmentCollection pPath = new PathClass();

                        object o = Type.Missing;
                        for(int k=1; k<linePoints.Count; k++)
                        {
                            ILine pLine = new LineClass();
                            pLine.PutCoords(linePoints[k-1], linePoints[k]);
                            ISegment pSeg = pLine as ISegment;
                            pPath.AddSegment(pSeg, ref o, ref o);
                        }

                        IGeometryCollection pPolyLine = new PolylineClass();
                        pPolyLine.AddGeometry(pPath as IGeometry);

                        pFeatureBuffer = pFeatureClass.CreateFeatureBuffer();
                        pFeatureBuffer.Shape = pPolyLine as IGeometry;
                        pFeatureCursor.InsertFeature(pFeatureBuffer);
                    }

                    linePoints.Clear();
                    linePoints.Add(to);
                }
            }

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

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

            GISMapApplication.Instance.RefreshLayer(pFeatureLayer);
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值