ArcGIS Engine自定义工具类.docx_第1页
ArcGIS Engine自定义工具类.docx_第2页
ArcGIS Engine自定义工具类.docx_第3页
ArcGIS Engine自定义工具类.docx_第4页
ArcGIS Engine自定义工具类.docx_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

ArcGIS Engine自定义工具类,实现添加图名,比例尺ArcGIS Engine自定义工具类,实现添加图名,比例尺,指北针作者:zhangche 文章来源:GIS空间站 点击数:526 更新时间:2010-2-8摘要:ArcGIS Engine自定义工具类,实现添加图名,比例尺,指北针等。 自定义工具类,实现添加图名,比例尺,指北针-添加图名-using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using ESRI.ArcGIS.Display;using ESRI.ArcGIS.SystemUI;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.Output;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.Geometry;using ESRI.ArcGIS.ADF.BaseClasses;using stdole;/自定义工具类,实现添加图名功能namespace WindowsApplication1 class addPageLayoutName:BaseTool public Form1 formTemp; TextBox textbox; AxPageLayoutControl axLayoutControl; IPoint pPoint; /double xMap, yMap; public static double xMap; public static double yMap; public override void OnMouseDown(int Button, int Shift, int X, int Y) if (Button=1) pPoint = formTemp.returnPageLayoutControl().ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); xMap = pPoint.X; yMap = pPoint.Y; formTemp.returnTextbox1().Location = new System.Drawing.Point(X,Y); formTemp.returnTextbox1().Visible = true; formTemp.returnTextbox1().Focus(); formTemp.returnTextbox1().Text = 请在此输入图名; public override void OnCreate(object hook) axLayoutControl = hook as AxPageLayoutControl; public void AddTextElement(AxPageLayoutControl PageLayoutControl,double x,double y,string textName) IPageLayout pPageLayout; IActiveView pAV; IGraphicsContainer pGraphicsContainer; IPoint pPoint; ITextElement pTextElement; IElement pElement; ITextSymbol pTextSymbol; IRgbColor pColor; pPageLayout = PageLayoutControl.PageLayout; pAV = (IActiveView)pPageLayout; pGraphicsContainer = (IGraphicsContainer)pPageLayout; pTextElement = new TextElementClass(); IFontDisp pFont = new StdFontClass() as IFontDisp; pFont.Bold = true; pFont.Name = 宋体; pFont.Size = 13; pColor = new RgbColorClass(); pColor.Red = 255; pTextSymbol = new TextSymbolClass(); pTextSymbol.Color = (IColor)pColor; pTextSymbol.Font = pFont; pTextElement.Text = textName; pTextElement.Symbol = pTextSymbol; pPoint = new PointClass(); pPoint.X = x; pPoint.Y = y; pElement = (IElement)pTextElement; pElement.Geometry = (IGeometry)pPoint; pGraphicsContainer.AddElement(pElement, 0); pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); 另外附加其它(添加比例尺,指北针的代码,也是通过自定义工具类实现的,下列只给出自定义工具类的代码!)-添加指北针-using System;using System.Collections.Generic;using System.Text;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.Display;using ESRI.ArcGIS.Geometry;using ESRI.ArcGIS.ADF.BaseClasses;namespace WindowsApplication1 sealed class addNorthArrow : BaseTool AxPageLayoutControl axPageLayout=null; IPoint pPoint; bool bInuse; INewEnvelopeFeedback pNewEnvelopeFeedback = null; public addNorthArrow() base.m_caption= 添加指北针; base.m_toolTip = 添加指北针; base.m_category = customCommands; base.m_message = 添加指北针; base.m_deactivate = true; public override void OnCreate(object hook) axPageLayout = (AxPageLayoutControl)hook; public override void OnMouseDown(int Button, int Shift, int X, int Y) pPoint = axPageLayout.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); bInuse = true; public override void OnMouseMove(int Button, int Shift, int X, int Y) if (bInuse=false) return; if (pNewEnvelopeFeedback=null) pNewEnvelopeFeedback = new NewEnvelopeFeedbackClass(); pNewEnvelopeFeedback.Display = axPageLayout.ActiveView.ScreenDisplay; pNewEnvelopeFeedback.Start(pPoint); pNewEnvelopeFeedback.MoveTo(axPageLayout.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); public override void OnMouseUp(int Button, int Shift, int X, int Y) if (bInuse=false) return; if (pNewEnvelopeFeedback=null) pNewEnvelopeFeedback = null; bInuse = false; return; IEnvelope pEnvelope=pNewEnvelopeFeedback.Stop(); if(pEnvelope.IsEmpty)|(pEnvelope.Width=0)|(pEnvelope.Height=0) pNewEnvelopeFeedback = null; bInuse = false; return; addNorthArrowForm northArrow = new addNorthArrowForm(); IStyleGalleryItem pStyleGalleryItemTemp = Form1.pStyleGalleryItem; if (pStyleGalleryItemTemp=null) return; IMapFrame pMapframe = axPageLayout.ActiveView.GraphicsContainer.FindFrame(axPageLayout.ActiveView.FocusMap)as IMapFrame; IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass(); pMapSurroundFrame.MapFrame = pMapframe; pMapSurroundFrame.MapSurround = (IMapSurround)pStyleGalleryItemTemp.Item; /在pageLayout中根据名称查要Element,找到之后删除已经存在的指北针 IElement pElement = axPageLayout.FindElementByName(NorthArrows); if (pElement!=null) axPageLayout.ActiveView.GraphicsContainer.DeleteElement(pElement); /删除已经存在的指北针 pElement = (IElement)pMapSurroundFrame; pElement.Geometry = (IGeometry)pEnvelope; axPageLayout.ActiveView.GraphicsContainer.AddElement(pElement, 0); axPageLayout.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); pNewEnvelopeFeedback = null; bInuse = false; -添加比例尺(Scale Bars)-using System;using System.Collections.Generic;using System.Text;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.Display;using ESRI.ArcGIS.Geometry;using ESRI.ArcGIS.ADF.BaseClasses;namespace WindowsApplication1 sealed class addScaleBar:BaseTool /- /发现的重大问题,如果用IHookHelper,就会出现问题,用AxPageLayoutControl则不会出现问题,以后注意 /private IHookHelper pHookHelper=null; private AxPageLayoutControl axPagelayoutControl = null; private IPoint pPoint; private INewEnvelopeFeedback pNewEnvelopeFeedback; private bool bInuse; public addScaleBar() base.m_caption = ScaleBar; base.m_category = myCustomCommands(C#); base.m_message = Add a scale bar map surround; base.m_name = myCustomCommands(C#)_ScaleBar; base.m_toolTip = Add a scale bar; base.m_deactivate = true; public override void OnCreate(object hook) /pHookHelper.Hook = hook; axPagelayoutControl = hook as AxPageLayoutControl; public override void OnMouseDown(int Button, int Shift, int X, int Y) pPoint = axPagelayoutControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); bInuse = true; public override void OnMouseMove(int Button, int Shift, int X, int Y) if (bInuse=false) return; if (pNewEnvelopeFeedback=null) pNewEnvelopeFeedback = new NewEnvelopeFeedbackClass(); pNewEnvelopeFeedback.Display = axPagelayoutControl.ActiveView.ScreenDisplay; pNewEnvelopeFeedback.Start(pPoint); pNewEnvelopeFeedback.MoveTo(axPagelayoutControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); public override void OnMouseUp(int Button, int Shift, int X, int Y) if (bInuse=false) return; if (pNewEnvelopeFeedback=null) pNewEnvelopeFeedback = null; bInuse = false; return; IEnvelope pEnvelope = pNewEnvelopeFeedback.Stop(); if (pEnvelope.IsEmpty)|(pEnvelope.Width=0)|(pEnvelope.Height=0) pNewEnvelopeFeedback = null; bInuse = false; return; AddScaleBarForm scaleBarForm = new AddScaleBarForm(); /scaleBarForm.Show(); IStyleGalleryItem pStyleItem = Form1.pStyleGalleryItem; if (pStyleItem = null) return; IMapFrame pMapframe = axPagelayoutControl.ActiveView.GraphicsContainer.FindFrame(axPagelayoutControl.ActiveView.FocusMap) as IMapFrame; IMapSurroundFrame pSurroundFrame = new MapSurroundFrameClass(); pSurroundFrame.MapFrame = pMapframe; pSurroundFrame.MapSurround = (IMapSurround)pStyleItem.Item; /在pageLayout中根据名称查要Element,找到之后删除已经存在的比例尺 IElement pelement = axPagelayoutControl.FindElementByName(ScaleBars); if (pelement != null) axPagelayoutControl.ActiveView.GraphicsContainer.DeleteElement(pelement); /删除已经存在的指北针 pelement = (IElement)pSurroundFrame; pelement.Geometry = (IGeometry)pEnvelope; axPagelayoutControl.ActiveView.GraphicsContainer.AddElement(pelement, 0); axPagelayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); pNewEnvelopeFeedback = null; bInuse = false; C#实现CAD数据转shape或mdb (转)C#实现CAD数据转shape或mdbpublicboolCadDataToShape(string_cadFilePath)/工作空间IWorkspaceFactorypWorkspaceFactory;IFeatureWorkspacepFeatureWorkspace;IFeatureLayerpFeatureLayer;IFeatureDatasetpFeatureDataset;/图层对应数据集ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClassfeaTofea=newFeatureClassToFeatureClass();ESRI.ArcGIS.Geoprocessor.GeoprocessorpGeoPro=newESRI.ArcGIS.Geoprocessor.Geoprocessor();trystringstrFullPath=_cadFilePath;intindex=strFullPath.LastIndexOf();stringfilePath=strFullPath.Substring(0,index);stringfileName=strFullPath.Substring(index+1);stringDataSaveFilePath=D:CADToShape;cadGISInfo=newstMdbInfo();cadGISInfo.mdbFeaturesName=newList();cadGISInfo.mdbname=fileName;/打开cad数据集pWorkspaceFactory=newCadWorkspaceFactoryClass();pFeatureWorkspace=(IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath,0);if(Directory.Exists(DataSaveFilePath+fileName)DirectoryInfodirInfo=newDirectoryInfo(DataSaveFilePath+fileName);foreach(FileInfofileindirInfo.GetFiles()file.Delete();Directory.Delete(DataSaveFilePath+fileName);Directory.CreateDirectory(DataSaveFilePath+fileName);cadGISInfo.mdbfilepath=DataSaveFilePath+fileName;/打开一个要素集pFeatureDataset=pFeatureWorkspace.OpenFeatureDataset(fileName);IFeatureClassContainerpFeatureClassContainer=(IFeatureClassContainer)pFeatureDataset;/对CAD文件中的要素进行遍历处理intcount=pFeatureClassContainer.ClassCount;for(intj=0;jpFeatureClassContainer.ClassCount;j+)IFeatureClasspFeatClass=pFeatureClassContainer.get_Class(j);cadGISInfo.mdbFeaturesName.Add(pFeatClass.AliasName+.shp);if(pFeatClass.FeatureType=esriFeatureType.esriFTCoverageAnnotation|pFeatClass.FeatureType=esriFeatureType.esriFTAnnotation)elsefeaTofea.in_features=strFullPath+pFeatClass.AliasName;feaTofea.out_path=DataSaveFilePath+fileName;feaTofea.out_feature_class=pFeatClass.AliasName;feaTofea.out_name=pFeatClass.AliasName;pGeoPro.Execute(feaTofea,null);returntrue;catchreturnfalse;finallypWorkspaceFactory=null;pFeatureDataset=null;pFeatureWorkspace=null;GC.Collect();下面的方法实现CAD数据转成本地的Personal Geodatbase,同时实现了注记图层的转换代码publicboolCadDataToGeodatabase(string_cadFilePath)/工作空间IWorkspaceFactorypWorkspaceFactory;IFeatureWorkspacepFeatureWorkspace;IFeatureLayerpFeatureLayer;IFeatureDatasetpFeatureDataset;/图层对应数据集/创建MDB工作空间IWorkspaceFactorypAccessWorkSpaceFactory;/这个conversionTools不包含注记图层的转换ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClassfeaTofea=newFeatureClassToFeatureClass();ESRI.ArcGIS.Geoprocessor.GeoprocessorpGeoPro=newESRI.ArcGIS.Geoprocessor.Geoprocessor();/ImportCADAnnotation功能,实现导入注记图层ESRI.ArcGIS.ConversionTools.ImportCADAnnotationimportCADAnno=newImportCADAnnotation();trystringstrFullPath=_cadFilePath;intindex=strFullPath.LastIndexOf();stringfilePath=strFullPath.Substring(0,index);stringfileName=strFullPath.Substring(index+1);stringDataSaveFilePath=D:CADToMDB;cadGISInfo=newstMdbInfo();cadGISInfo.mdbFeaturesName=newList();cadGISInfo.mdbname=fileName;/打开cad数据集pWorkspaceFactory=newCadWorkspaceFactoryClass();pFeatureWorkspace=(IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath,0);/创建mdb(personalgeodatabase)pAccessWorkSpaceFactory=newAccessWorkspaceFactoryClass();if(File.Exists(DataSaveFilePath+fileName+.mdb)File.Delete(DataSaveFilePath+fileName+.mdb);cadGISInfo.mdbfilepath=DataSaveFilePath+fileName+.mdb;/ltMdbFilePath.Add(DataSaveFilePath+fileName+.mdb);pAccessWorkSpaceFactory.Create(DataSaveFilePath,fileName+.mdb,null,0);/打开一个要素集pFeatureDataset=pFeatureWorkspace.OpenFeatureDataset(fileName);IFeatureClassContainerpFeatureClassContainer=(IFeatureClassContainer)pFeatureDataset;/对CAD文件中的要素进行遍历处理intcount=pFeatureClassContainer.ClassCount;for(intj=0;jpFeatureClassContainer.ClassCount;j+)IFeatureClasspFeatClass=pFeatureClassContainer.get_Class(j);cadGISInfo.mdbFeaturesName.Add(pFeatClass.AliasName);if(pFeatClass.FeatureType=esriFeatureType.esriFTCoverageAnnotation|pFeatClass.FeatureType=esriFeatureType.esriFTAnnotation)pFeatureLayer=newCadAnnotationLayerClass();/注记图层importCADAnno.input_features=strFullPath+pFeatClass.A

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论