【SQL开源代码栏目提醒】:网学会员SQL开源代码为您提供arcgis开发常用源码 - 技术总结参考,解决您在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也一样。
case quotZoomInquot: ICommand command new ControlsSceneZoomInTool//ControlsSceneZoomInToolClass command.OnCreatethis.axSceneControl1.Object this.axSceneControl1.CurrentTool command as ESRI.ArcGIS.SystemUI.ITool break case quottoolFlyquot: ICommand command new ControlsSceneFlyToolClass//ControlsSceneZoomInToolClass command.OnCreatethis.axSceneControl1.Object this.axSceneControl1.CurrentTool command as ESRI.ArcGIS.SystemUI.ITool break case quottoolSelectFeaturesquot: ICommand command new ControlsSceneSelectFeaturesToolClass//ControlsSceneZoomInToolClass command.OnCreatethis.axSceneControl1.Object this.axSceneControl1.CurrentTool command as ESRI.ArcGIS.SystemUI.ITool break case quottoolTargetZoomquot: ICommand command new ControlsSceneTargetZoomToolClass//ControlsSceneZoomInToolClass command.OnCreatethis.axSceneControl1.Object this.axSceneControl1.CurrentTool command as ESRI.ArcGIS.SystemUI.ITool break case quottoolFullExtentquot: ICommand command new ControlsSceneFullExtentCommandClass//ControlsSceneZoomInToolClass command.OnCreatethis.axSceneControl1.Object this.axSceneControl1.CurrentTool command as ESRI.ArcGIS.SystemUI.ITool break case quotZoomOutquot: ICommand command new ControlsSceneZoomOutTool command.OnCreatethis.axSceneControl1.Object this.axSceneControl1.CurrentTool command as ESRI.ArcGIS.SystemUI.ITool break case quotPanquot: ICommand command new ControlsScenePanTool command.OnCreatethis.axSceneControl1.Object this.axSceneControl1.CurrentTool command as ESRI.ArcGIS.SystemUI.ITool break case quotNavigatequot: ICommand command new ControlsSceneNavigateTool command.OnCreatethis.axSceneControl1.Object this.axSceneControl1.CurrentTool command as ESRI.ArcGIS.SystemUI.ITool 10.在C中如何连接ACCESS数据库 using System.Data.OleDb public string myConnstringquotProviderMicrosoft.Jet.OLEDB.4.0 Data SourcequotHttpContext.Current.Server.MapPathquotdata.mdbquot //data.mdb是你的数据库名称 OleDbConnection MyConnection MyConnection new OleDbConnectionmyConnstring strInsertquotquot //strinsert是你的
sql语句 OleDbCommand MyCommand new OleDbCommandstrInsertMyConnection MyConnection.Open MyCommand.ExecuteNonQuery MyConnection.Close 11.创建文件word //创建文件夹 System.Object Nothing System.Reflection.Missing.Value Directory.CreateDirectoryquotc:/CNSIquot //创建文件所在目录 string name quotCNSI_quot DateTime.Now.ToLongDateString quot.docquot object filename quotc://CNSI//quot name //文件保存路径 //创建Word文档 Microsoft.Office.Interop.Word.Application WordApp new Microsoft.Office.Interop.Word.ApplicationClass Microsoft.Office.Interop.Word.Document WordDoc WordApp.Documents.Addref Nothing ref Nothing ref Nothing ref Nothing IQueryFilter pQueryFilter pQueryFilter pFeatureWorkspace 保存文档 string name quoty00quot object filename quotc://CNSI//quot name//保存文件路径。
object Nothing System.Reflection.Missing.Value //Microsoft.Office.Interop.Word.Application WordApp new Microsoft.Office.Interop.Word.ApplicationClass Microsoft.Office.Interop.Word.Document WordDocs WordApp.Documents.Addref Nothing ref Nothing ref Nothing ref Nothing WordDocs.Closeref Nothing ref Nothing ref Nothing WordApp.Quitref Nothing ref Nothing ref Nothing WordDocs.SaveAsref filename ref Nothing ref Nothing ref Nothing ref Nothing ref Nothing ref Nothing ref Nothing ref Nothing ref Nothing ref Nothing ref Nothing ref Nothing ref Nothing ref Nothing ref Nothing //WordApp.Quitref Nothing ref Nothing ref Nothing message name quot文档生成成功以保存到C:CNSI下quot hy catch message quot文件导出异常quot string path quotE:yxltianjiadatabase2.mdbquot IWorkspace iW AccessWorkspaceFromPropertySetpath IFeatureWorkspace pFeatureWorkspace IFeatureWorkspaceiW ITable pTable pFeatureWorkspace.OpenTablequotdatabase2quot 12. C操作Access数据库的方法 //取得连接 public OleDbConnection getConn ConnectDatabase connstrnew ConnectDatabase string connStrconnstr.GetConnectionString OleDbConnection oledbnew OleDbConnectionconnStr return oledb 1采用OleDbCommandOleDbDataReader访问数据库 1.查询 public User getUserFromNamestring Searchname User tempUsernew User try OleDbConnection oleconngetConn//数据库连接 string strSelquotselect from MyUser where UserNamequotSearchnamequotquot//查询语句 OleDbCommand myCommandnew OleDbCommandstrSeloleconn//查询命令 oleconn.Open//打开数据库连接 OleDbDataReader reader readermyCommand.ExecuteReader//执行查询命令返回记录集 ifreader.Read tempUser.IDintreaderquotUserIDquot tempUser.NamereaderquotUserNamequot.ToString tempUser.SalaryfloatreaderquotUserSalaryquot tempUser.PasswordreaderquotUserPasswordquot.ToString tempUser.MemoreaderquotUserMemoquot.ToString tempUser.BirthdayDateTimereaderquotUserBirthdayquot tempUser.AddressreaderquotUserAddressquot.ToString else throw new Exceptionquot没有记录quot reader.Close//关闭记录集 oleconn.Close//关闭连接 catchException e throw new Exceptionquot打开数据库出错quote.Message return tempUser 2.插入记录 public void InsertUserUser insertuser try OleDbConnection oleconngetConn//数据库连接 oleconn.Open//打开数据库连接 string strSelquotinsert into MyUserUserNameUserPassword UserSalaryUserAddressUserBirthdayUserMemoquot //插入语句 strSelquot values quotinsertuser.Namequotquotinsertuser.Passwordquotquotinsertuser.Salary.ToSt ring strSelquotquotinsertuser.Addressquotquotinsertuser.Birthday.ToString quotquotinsertuser.Memoquotquot OleDbCommand myCommandnew OleDbCommandstrSeloleconn//查询命令 myCommand.ExecuteNonQuery oleconn.Close//关闭连接 catchException e throw new Exceptionquot打开数据库出错quote.Message 3.删除记录 public void DeleteUserint m_id try OleDbConnection oleconngetConn oleconn.Open string strSelquotDelete From Myuser where UserIDquotm_id.ToStr.