【SQL开源代码栏目提醒】:网学会员鉴于大家对SQL开源代码十分关注,论文会员在此为大家搜集整理了“arcgis开发常用源码 - 技术总结”一文,供大家参考学习
arcgis开发常用源码 1.点上生成面的代码 if m_pFeatureLayer.FeatureClass.ShapeType esriGeometryType.esriGeometryPolygon IPointCollection m_pPointCollection new PolygonClass object missing Type.Missing int icount newFeature.XLIST.Count if icount lt 3 return for int i 0 i lt icount i IPoint point new PointClass point.PutCoordsnewFeature.XLIST newFeature.YLIST m_pPointCollection.AddPointpoint ref missing ref missing IPolygon m_pPolygon m_pPointCollection as IPolygon if m_pPolygon null System.Windows.Forms.MessageBox.Showquotnullquot return else ITopologicalOperator pTopo m_pPolygon as ITopologicalOperator if pTopo null pTopo.Simplify IWorkspaceEdit m_pWorkspaceEdit m_EngineEditor.EditWorkspace as IWorkspaceEdit m_pWorkspaceEdit.StartEditOperation IFeature m_pFeature m_pFeatureLayer.FeatureClass.CreateFeature m_pFeature.Shape m_pPolygon as IGeometry m_pFeature.Store m_pWorkspaceEdit.StopEditOperation 2.文件的打开 保存 另存的代码 using System using System.Windows.Forms using ESRI.ArcGIS.esriSystem using ESRI.ArcGIS.SystemUI using ESRI.ArcGIS.Carto namespace SaveMapDocument /// ltsummarygt /// Summary description for Form1. /// lt/summarygt public class SaveMapDocument : System.Windows.Forms.Form public System.Windows.Forms.TextBox txtMapDocument public System.Windows.Forms.Button cmdOpen public System.Windows.Forms.Button cmdSave public System.Windows.Forms.Button cmdSaveAs private System.Windows.Forms.OpenFileDialog openFileDialog1 private System.Windows.Forms.SaveFileDialog saveFileDialog1 private IMapDocument m_MapDocument private ESRI.ArcGIS.Controls.AxToolbarControl axToolbarControl1 private ESRI.ArcGIS.Controls.AxPageLayoutControl axPageLayoutControl1 private ESRI.ArcGIS.Controls.AxLicenseControl axLicenseControl1 private ESRI.ArcGIS.Controls.AxTOCControl axTOCControl1 /// ltsummarygt /// Required designer variable. /// lt/summarygt private System.ComponentModel.Container components null public SaveMapDocument // // Required for Windows Form Designer support // InitializeComponent // // TODO: Add any constructor code after InitializeComponent call // /// ltsummarygt /// Clean up any resources being used. /// lt/summarygt protected override void Dispose bool disposing //Release COM objects ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown if disposing if components null components.Dispose base.Dispose disposing region Windows Form Designer generated code /// ltsummarygt /// The main entry point for the application. /// lt/summarygt STAThread static void Main Application.Runnew SaveMapDocument private void Form1_Loadobject sender System.EventArgs e //Add toolbar definitions to the ToolbarControl axToolbarControl1.AddToolbarDefquotesriControls.ControlsPageLayoutToolbarquot -1 false 0 esriCommandStyles.esriCommandStyleIconOnly axToolbarControl1.AddToolbarDefquotesriControls.ControlsGraphicElementToolbarquot -1 true 0 esriCommandStyles.esriCommandStyleIconOnly //Set buddy control axToolbarControl1.SetBuddyControlaxPageLayoutControl1 axTOCControl1.SetBuddyControlaxPageLayoutControl1 cmdSave.Enabled false cmdSaveAs.Enabled false private void cmdOpen_Clickobject sender System.EventArgs e //Open a file dialog for opening map documents openFileDialog1.Title quotOpen Map Documentquot openFileDialog1.Filter quotMap Documents .mxd.mxdquot openFileDialog1.ShowDialog // Exit if no map document is selected string sFilePath openFileDialog1.FileName if sFilePath quotquot return //Open document OpenDocumentsFilePath if cmdSave.Enabled false cmdSave.Enabled true if cmdSaveAs.Enabled false cmdSaveAs.Enabled true private void cmdSave_Clickobject sender System.EventArgs e //Save changes to the current document SaveDocument private void cmdSaveAs_Clickobject sender System.EventArgs e 另存为 //Open a file dialog for saving map documents saveFileDialog1.Title quotSave Map Document Asquot saveFileDialog1.Filter quotMap Documents .mxd.mxdquot saveFileDialog1.ShowDialog //Exit if no map document is selected string sFilePath saveFileDialog1.FileName if sFilePath quotquot return if sFilePath m_MapDocument.DocumentFilename //Save changes to the current document SaveDocument else //SaveAs a new document with relative paths m_MapDocument.SaveAssFilePath true true //Open document OpenDocumentsFilePath MessageBox.ShowquotDocument saved successfullyquot private void OpenDocumentstring sFilePath if m_MapDocument null m_MapDocument.Close //Create a new map document m_MapDocument new MapDocumentClass //Open the map document selected m_MapDocument.OpensFilePathquotquot //Set the PageLayoutControl page layout to the map document page layout axPageLayoutControl1.PageLayout m_MapDocument.PageLayout txtMapDocument.Text m_MapDocument.DocumentFilename private void SaveDocument //Check that the document is not read only if m_MapDocument.get_IsReadOnlym_MapDocument.DocumentFilename true MessageBox.ShowquotThis map document is read onlyquot return //Save with the current relative path setting m_MapDocument.Savem_MapDocument.UsesRelativePathstrue MessageBox.ShowquotChanges saved successfullyquot 3.访问一个地图 static void OpenMXDViaMapDocumentstring path IMapDocument pMapDocument new MapDocumentClass if pMapDocument.get_IsMapDocumentpath pMapDocument.Openpathnull IMap pMap for int i 0 i lt pMapDocument.MapCount - 1 i pMap pMapDocument.get_Mapi Console.WriteLinepMap.Name IEnumLayer pEnumLayer pMap.get_Layersnulltrue pEnumLayer.Reset ILayer pLayer pEnumLayer.Next while pLayer null Console.WriteLinepLayer.Name pLayer pEnumLayer.Next 4、地图坐标 private void axMapControl1_OnMouseMoveobject sender IMapControlEvents2_OnMouseMoveEvent e string outx null string outy null IActiveView pActiveView axMapControl1.ActiveView BJAEINFunction.bj54tojingweiduAopActiveView e.mapX e.mapY ref outx ref outy labelItem1.Text quot地理坐标 经度quot outx quot 纬度quot outy //IFeatureLayer pFeatLyr //pFeatLyr axMapControl1.Map.get_Layer2 as IFeatureLayer //pFeatLyr.DisplayField quot面积quot //pFeatLyr.ShowTips true //string pTips //pTips pFeatLyr.get_TipTexte.mapX e.mapY pActiveView.FullExtent.Width / 100 //toolTip1.SetToolTipaxMapControl1 pTips 5、大地转北京54 public static void bj54tojingweiduAoIActiveView pActiveView double inx double iny ref string outx ref string outy try IMap pMap pActiveView.FocusMap SpatialReferenceEnvironment pSpRE new SpatialReferenceEnvironment IGeographicCoordinateSystem pGeoCS pSpRE.CreateGeographicCoordinateSystemintesriSRGeoCSType.esriSRGeoCS_Beijing1954 ISpatialReference pSpr pGeoCS IPoint pPoint new ESRI.ArcGIS.Geometry.Point pPoint.X inx pPoint.Y iny IGeometry pGeo pPoint pGeo.SpatialReference pMap.SpatialReference pGeo.ProjectpSpr//坐标转换由当前地图坐标转为北京54经纬度坐标 double jwd_jd pPoint.X double jwd_wd pPoint.Y //转化成度、分、秒 //经度 int Jd Wd Jf Wf double temp Single Jm Wm Jd intjwd_jd //度 temp jwd_jd - Jd 60 Jf inttemp //分 temp temp - Jf 60 Jm Convert.ToInt32temp //秒 //纬度 Wd intjwd_wd //度 temp jwd_wd - Wd 60 Wf inttemp //分 temp temp - Wf 60 Wm Convert.ToInt32temp //秒 outx Jd quot度quot Jf quot分quot Jm quot秒quot outy Wd quot度quot Wf quot分quot Wm quot秒quot catch Exception ex MessageBox.Showex.Message 6.拖动代码 private void btnClearSelction_Clickobject sender EventArgs e ICommand pCommand new ControlsMapIdentifyToolClass ITool pTool pCommand as ITool switch this.tabControl.SelectedTabIndex case 0: pCommand.OnCreatethis.mainMapControl.Object this.mainMapControl.CurrentTool pTool break case 1: pCommand.OnCreatethis.axPageLayoutControl.Object this.axPageLayoutControl.CurrentTool pTool break 7.axMapControl和axPagelayoutControl数据同步显示的程序 private void axMapControl1_OnMouseDownobject sender IMapControlEvents2_OnMouseDownEvent e axMapControl1.MousePointer esriControlsMousePointer.esriPointerCrosshair IGeometry pGeom axMapControl1.TrackRectangle DrawMapShapepGeom axMapControl1.CtlRefreshesriViewDrawPhase.esriViewGeography null null private void DrawMapShapeIGeometry pGeom IRgbColor pColor pColor new RgbColorClass pColor.Red 100 pColor.Green 100 pColor.Blue 100 ISimpleFillSymbol pFillsyl pFillsyl new SimpleFillSymbolClass pFillsyl.Color pColor object oFillsyl pFillsyl axMapControl1.DrawShapepGeom ref oFillsyl private void CopyAndOverwriteMap IObjectCopy objectCopy new ObjectCopyClass object toCopyMap axMapControl1.Map object copiedMap objectCopy.CopytoCopyMap object toOverwriteMap axPageLayoutControl1.ActiveView.FocusMap objectCopy.OverwritecopiedMap ref toOverwriteMap private void axMapControl1_OnAfterScreenDrawobject sender IMapControlEvents2_OnAfterScreenDrawEvent e IActiveView activeView IActiveViewaxPageLayoutControl1.ActiveView.FocusMap IDisplayTransformation displayTransformation activeView.ScreenDisplay.DisplayTransformation displayTransformation.VisibleBounds axMapControl1.Extent axPageLayoutControl1.ActiveView.Refresh CopyAndOverwriteMap private void axPageLayoutControl1_OnViewRefreshedobject sender IPageLayoutControlEvents_OnViewRefreshedEvent e axTOCControl1.CtlUpdate CopyAndOverwriteMap 8.放大 缩小 放大 ICommand pCommand new ControlsMapZoomInToolClass ITool pTool pCommand as ITool pCommand.OnCreatethis.axMapControl1.Object this.axMapControl1.CurrentTool pTool 缩小 ICommand pCommand new ControlsMapZoomOutToolClass ITool pTool pCommand as ITool pCommand.OnCreatethis.axMapControl1.Object this.axMapControl1.CurrentTool pTool 9. 在arcsence中的各个控件的应用 类似的arcmap也一样。