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);
}
}
}
Arcgis---从数据库中获取数据绘制道路
最新推荐文章于 2024-04-17 21:52:47 发布