打開mxd文件
OpenFileDialog
axMapControl1.LoadMxFile(pFileName);
打開shp文件
IWorkspaceFactory pWorkspaceFactory = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(pFilePath, 0);
IFeatureWorkspace pFeatureWorkspace= new ShapefileWorkspaceFactory();
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(pFileName);
pFeatureLayer = new FeatureLayer();
pFeatureLayer.FeatureClass = pFeatureClass;
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
//ClearAllData();//刪除所有已加載的數(shù)據(jù)
axMapControl2.Map.AddLayer(pFeatureLayer);
IFeatureWorkspace 接口用于訪問和管理地理數(shù)據(jù)庫中的要素的重要成分 -- 數(shù)據(jù)集
IFeatureWorkspace.OpenFeatureClass 方法打開 workspace 中任何已存在的要素類
IFeatureClass 用于訪問控制要素類行為和屬性的成員
IFeatureClass 接口是獲取和設置要素類屬性的主要接口
IFeatureLayer 接口的第一個屬性 FeatureClass(讀寫,設置或者讀取此 layer 的要素類)
把shp放入Shape工作空間——》通過OpenFeatureClass訪問要素類——》 實例化FeatureLayer添加FeatureClass和Name 最后AddLayer
打開cad文件
把cad放入CadWorkspaceFactory工作空間——》通過OpenFeatureClass訪問要素類——》 實例化FeatureLayer添加FeatureClass和Name 最后AddLayer
IWorkspaceFactory pWorkspaceFactory = new CadWorkspaceFactory();
保存文件
IMapDocument pMapDocument = new MapDocumentClass();
pMapDocument.New(sMxdFileName);
pMapDocument.ReplaceContents(axMapControl1.Map as IMxdContents);
pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
拉框放大
Click事件
pMouseOperate = "ZoomIn"; 和改變鼠標狀態(tài)
OnMouseDown事件
axMapControl1.TrackRectangle(); 創(chuàng)建橡皮條返回IEnvelope
IActiveView 接口的Extent屬性與IEnvelope連接
拉框縮小
拉框范圍為中心,縮小倍數(shù)為:當前視圖范圍/拉框范圍
漫游
axMapControl1.Pan();
拉框選擇
IGeometry geometry = axMapControl1.TrackRectangle();
axMapControl2.Map.SelectByShape(geometry, null, false); Imap接口的SelectByShape方法
formSelection.CurrentMap = axMapControl1.Map; //把地圖對象傳走
距離量算
NewLineFeedbackClass接口
Start //設置起點,開始動態(tài)線繪制
AddPoint //添加當前鼠標點
Display
面積量算
NewPolygonFeedback接口
Display
Start
AddPoint
if (pNewLineFeedback == null)
{
//實例化追蹤線對象
pNewLineFeedback = new NewLineFeedbackClass();
pNewLineFeedback.Display = (axMapControl1.Map as IActiveView).ScreenDisplay;
//設置起點,開始動態(tài)線繪制
pNewLineFeedback.Start(pPointPt);
dToltalLength = 0;
}
else //如果追蹤線對象不為空,則添加當前鼠標點
{
pNewLineFeedback.AddPoint(pPointPt);
}
//pGeometry = m_PointPt;
放大
IEnvelope接口的Expand
和IActiveView接口的Extent
縮小
IEnvelope接口的Expand
和IActiveView接口的Extent
全圖顯示
axMapControl1.Extent = axMapControl1.FullExtent;
前視圖和后視圖
axMapControl1.ActiveView.ExtentStack;
IExtentStack接口的
Undo();
Redo();
添加圖例

添加指北針

添加比例尺

pGraphicsContainer.AddElement(pElement, 0); //像圖中添加元素


顯示網絡的流向




流向的繪制

網絡追蹤分析

爆管分析的 步驟
