已阅读5页,还剩16页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
AE 中新建 shapefile,自定义字段代码由 ESRI 社区 GIScafe 提供IFields pFields = new FieldsClass();IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;IField pField = new FieldClass();IFieldEdit pFieldEdit = pField as IFieldEdit;pFieldEdit.Name_2 = shape;pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;/set up Geometry DefinitionIGeometryDef pGeometryDef = new GeometryDefClass();IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;/Point,line,polygon et.pGeometryDefEdit.SpatialReference_2 = axMapControl1.SpatialReference;pFieldEdit.GeometryDef_2 = pGeometryDef;pFieldsEdit.AddField(pField);/新建字段pField = new FieldClass();pFieldEdit = pField as IFieldEdit;pFieldEdit.Length_2 = 15;pFieldEdit.Name_2 = SchoolName;pFieldEdit.AliasName_2 = SchoolName;pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;pFieldsEdit.AddField(pField);string mappath = E:data;string layername=school;IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(mappath,0) as IFeatureWorkspace;pFeatureWorkspace.CreateFeatureClass(layername+.shp,pFields,null,null,esriFeatureType.esriFTSimple,shape,);axMapControl1.AddShapeFile(mappath,layername+.shp);代码中路径名称可以自定义posted on 2008-07-12 15:28 duckweeds 阅读(137) 评论(0) 编辑 收藏 网摘 所属分类:AE+C#AE 创建各种类型的 featureclass 代码VB.Net 源码 创建 Annotation 类型的 featureclass annotation 的工作空间 annotation 的 symbol annotation 的比例 annotation 的名称 创建的 Annotation Featureclass Private Function CreateAnnoFeatCls(ByVal pWorkspace As IFeatureWorkspace, ByVal pTextSymbol As ITextSymbol, ByVal pRefeScale As Double, ByVal pAnnoFeatName As String, Optional ByVal pSymbolID As Integer = 0) As IFeatureClassDim pField As IField Dim pFields As IFields Dim pSource As ICloneDim pObjectClassDesc As IObjectClassDescriptionDim pFeatClassDesc As IFeatureClassDescription创建 Annotation 的 FieldspObjectClassDesc = New AnnotationFeatureClassDescription pFeatClassDesc = pObjectClassDescpSource = pObjectClassDesc.RequiredFields pFields = pSource.Clone创建 Annotation 的 Geometry defintionpField = pFields.Field(pFields.FindField(pFeatClassDesc.ShapeFieldName)创建 Reference scaleDim pGraphicsLayerScale As IGraphicsLayerScalepGraphicsLayerScale = New GraphicsLayerScale pGraphicsLayerScale.ReferenceScale = pRefeScale pGraphicsLayerScale.Units = esriUnits.esriMeters创建 SymbolcollectionDim pSymbolColl As ISymbolCollection2Dim pSymbolIdent As ISymbolIdentifier2 = New SymbolIdentifier pSymbolColl = New SymbolCollection pSymbolColl.AddSymbol(pTextSymbol, Default, pSymbolIdent)If pSymbolID = 1 Then pSymbolColl.AddSymbol(pTextSymbol, Default 1, pSymbolIdent)创建 Label 的相关属性Dim pOverposterProperties As IOverposterPropertiesDim pAnnoPropsColl As IAnnotateLayerPropertiesCollectionDim pLabelEngineLP As ILabelEngineLayerProperties Dim pAnnotateLayerProps As IAnnotateLayerProperties pOverposterProperties = New BasicOverposterProperties pAnnoPropsColl = New AnnotateLayerPropertiesCollection pLabelEngineLP = New LabelEngineLayerProperties pAnnotateLayerProps = pLabelEngineLP pAnnotateLayerProps.Class = Default pLabelEngineLP.Symbol = pTextSymbol pLabelEngineLP.SymbolID = pSymbolIdent.ID pAnnoPropsColl.Add(pLabelEngineLP)创建 Annotation layerDim pAnnoLayerFactory As IAnnotationLayerFactory Dim pAnnoLayer As IAnnotationLayer pAnnoLayerFactory = New FDOGraphicsLayerFactorypAnnoLayer = pAnnoLayerFactory.CreateAnnotationLayer(pWorkspace, Nothing, pAnnoFeatName, pField.GeometryDef, Nothing, pAnnoPropsColl, pGraphicsLayerScale, pSymbolColl, False, False, False, True, pOverposterProperties, )Return CType(pAnnoLayer, IFeatureLayer).FeatureClassEnd Function 创建存于 Shapefile 中的 featureclass Public Shared Function CreateShapefile(ByVal sDir As String, ByVal sName As String, ByVal shapeType As esriGeometryType, _ByVal hasM As Boolean, ByVal hasZ As Boolean, ByVal pSR As ISpatialReference, ByVal pFields As IFields) As IFeatureClassTryDim shapeWorkspaceFactory As IWorkspaceFactory shapeWorkspaceFactory = New ShapefileWorkspaceFactory Dim shapeWorkspace As IFeatureWorkspaceshapeWorkspace = shapeWorkspaceFactory.OpenFromFile(sDir, 0) If (Not shapeWorkspace Is Nothing) ThenIf pFields Is Nothing Then pFields = CreateBasicFields(shapeType, hasM, hasZ, pSR) Dim pFClass As IFeatureClasspFClass = shapeWorkspace.CreateFeatureClass(sName, pFields, Nothing, Nothing, esriFeatureType.esriFTSimple, Shape, )Return pFClassEnd IfReturn NothingCatch ex As Exception MsgBox(ex.Message) Return NothingEnd TryEnd Function 创建存于内存中的 Featureclass Public Shared Function GetSimpleFeatureClass(ByVal pFields As IFields, ByVal featureClassName As String) As IFeatureClassTryDim pSwf As IWorkspaceFactory = New InMemoryWorkspaceFactoryDim pWorkspaceName As IWorkspaceName = pSwf.Create(, MyWorkspace, Nothing, 0) Dim pFWS As IFeatureWorkspace = CType(pWorkspaceName, IName).Open()Dim pFC As IFeatureClass = pFWS.CreateFeatureClass(featureClassName, pFields, Nothing, Nothing, esriFeatureType.esriFTSimple, Shape, Nothing)Return pFCCatch ex As ExceptionReturn NothingEnd TryEnd Function 创建存于 Access 中的 featureclass Public Function CreateAccessFeatureClass(ByVal pFields As IFields, ByVal pAccessPath As String, ByVal pAccessName As String, ByVal featureClassName As String) As IFeatureClassTryDim pSwf As IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory Dim pWorkspaceName As IWorkspaceName = pSwf.Create(pAccessPath, pAccessName, Nothing, 0) Dim pFWS As IFeatureWorkspace = CType(pWorkspaceName, IName).Open()pFields = CreateBasicFields(esriGeometryType.esriGeometryPoint, False, False, NewUnknownCoordinateSystem)Dim pFC As IFeatureClass = pFWS.CreateFeatureClass(featureClassName, pFields, Nothing, Nothing, esriFeatureType.esriFTSimple, Shape, Nothing)Return pFCCatch ex As ExceptionReturn NothingEnd TryEnd FunctionAE+C#实现鹰眼功能(二)(带鼠标拖动)vs2005+AE9.2 实现,主要功能:鹰眼视图里面鼠标左键画红框,右键拖动代码中主视图为 Mapcontrol1,鹰眼视图为 MapControl2。 主要利用了 Envelope 进行视图范围传递,从而控制视图同步等。 代码如下:几个变量声明 :/变量IMapDocument pMapDocument = new MapDocumentClass();IEnvelope pEn = new EnvelopeClass();object oFillobject = new object();private void CreateOverviewSymbol()IRgbColor iRgb = new RgbColorClass();iRgb.RGB = 255;ILineSymbol pOutline = new SimpleLineSymbolClass();pOutline.Color = iRgb;pOutline.Width = 2.3;ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();pSimpleFillSymbol.Outline = pOutline;pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;oFillobject = pSimpleFillSymbol;控制拖动变量:private IMoveEnvelopeFeedback pSmallViewerEnvelope;/鹰眼小地图的红框,IMoveEnvelopeFeedback,用来移动 Envelope 的接口private IPoint pSmallViewerMouseDownPt;/拖动时鼠标落点private bool isTrackingSmallViewer = false; /标识是否在拖动static int moveCount = 0;/记录移动的个数,为移动过程中显示红框用。axMapControl1_OnMapReplaced 事件:axMapControl2.LoadMxFile(axMapControl1.DocumentFilename); 两个视图加载数据可能存在鹰眼视图数据显示不完全(不知道是不是我电脑的毛病。),这 样加载可以控制数据的同步更新axMapControl1_OnExtentUpdated 事件:pEn = e.newEnvelope as IEnvelope;axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);axMapControl1_OnAfterDraw:esriViewDrawPhase viewDrawPhase = (esriViewDrawPhase)e.viewDrawPhase;if (viewDrawPhase = esriViewDrawPhase.esriViewForeground)axMapControl2.DrawShape(pEn, ref oFillobject);axMapControl2_OnMouseDown:if(e.button=1)/左键画红框pEn = axMapControl2.TrackRectangle();axMapControl1.Extent = pEn;axMapControl2.DrawShape(pEn, ref oFillobject);if (e.button = 2)/右键拖动红框pSmallViewerMouseDownPt = new PointClass();pSmallViewerMouseDownPt.PutCoords(e.mapX, e.mapY);axMapControl1.CenterAt(pSmallViewerMouseDownPt);isTrackingSmallViewer = true;if (pSmallViewerEnvelope = null)pSmallViewerEnvelope = new MoveEnvelopeFeedbackClass();pSmallViewerEnvelope.Display = axMapControl2.ActiveView.ScreenDisplay;pSmallViewerEnvelope.Symbol = (ISymbol)oFillobject;pSmallViewerEnvelope.Start(pEn, pSmallViewerMouseDownPt);axMapControl2_OnMouseMove:if (isTrackingSmallViewer)moveCount+;if (moveCount % 4 = 0)/因为一刷新,红框就没了。所以每移动 4 次就刷新一下,保持红框的连续性。axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);pSmallViewerMouseDownPt.PutCoords(e.mapX, e.mapY);pSmallViewerEnvelope.MoveTo(pSmallViewerMouseDownPt);axMapControl2_OnMouseUp:if (pSmallViewerEnvelope != null)pEn = pSmallViewerEnvelope.Stop();axMapControl1.Extent = pEn;isTrackingSmallViewer = false;Form 初始化:axMapControl1.LoadMxFile(load data);pEn = axMapControl1.Extent;/鹰眼红框初始化CreateOverviewSymbol();经过测试可以实现鹰眼中画红框和拖动功能。 现在存在问题是,拖动功能还不太完善,抓紧研究,有了结果在贴上来。 其中,拖动部分思路即代码来自 ESRI 中国社区 AE 版。FeatureLayer,FeatureDataset,FeatureClass,Feature 几个概念一点点总结,欢迎指教刚学 AE,其中很多概念都模糊不清。经过一段时间的摸索总结,对 FeatureLayer,FeatureDataset,FeatureClass,Feature 几个概念有了一点认识。拿出来分享一下, 有错误的请多多指教,共同进步.FeatureLayer: 要素图层,承载要素数据。几个重要的接口如下:IFeatureLayer 接口,用于管理要素图层的数据源,即要素类(FeatureClass)。具体察看IFeatureLayer.DataSourceType 条目。IFeatureLayer:FeatureClass 属性可以返回要素图层使用的要素类。IFeatureLayer:search 方法,返回一个 ICursor 对象,仅仅指向一个要 素指针。IFeatureSelection 接口负责管理一个图层中的要素的选择集的方法和属性。IFeatureSelection:SelectFeatures 使用一个过滤器把符合要求的要素 放入图层的选择中(IEnumFeature)。ILayerFields 接口,可以直接获得一个要素图层的要素类字段结构。FeatureDataset: 先看官方解释:A FeatureDataset is a container for feature classes that share the same spatial refrence.要素数据集对象在 GeoDatabase 是一个简单的要素类的容器,在这个容 器内放置着相同空间参考的要素类FeatureClass:(要素类)是用来存储空间数据的对象类,是 ObjectClass 的扩展。在一个 要素类中的所有的要素都使用同样的字段结构,要素类不表,对象类最大的区别是它有一个几何字段,即 Shape 字段,用于存储要素的几何信息,这样使得用户可以在地图上看到一个要素的形状和位置。在地图上,要素类是离散对象,”小”对象(small objects)表示为点 要素,”长”对象表示为线要素,”大”对象表示为多边形要素.(丌要老往 Shapefile 上面想), 丌包含 Raster。IFields 接口,字段集可以通过 ITable:Fields 获取(IFeatureClass.Fields)IFields 有 2 个属性,其中一个是 Field(index),通过传入丌同的字段索引值可以返回某个字段。两个方法, 一个是 FindField,用字段名作为字段的索引。IField 接口是字段对象的主要接口,可以个 从这个接口中得到字段的主要属性,如名称、别名,字段的值域,字段的类型等。Feature: 是要素类中一条记录,主要接口是 IFeature,定义了要素对象特有的属性。 IFeature :get_Value(i)可以获得索引值为 i 的要素的属性值。通过循环就可 以获得所有属性值。还是图最清楚:自己总结的,如有不对的地方,请各位大虾多多指教.共同进步:)新建 shapefile,自定义字段,新加入记录/生成新的 shapefileIFields pFields = new FieldsClass();IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;IField pField = new FieldClass();IFieldEdit pFieldEdit = pField as IFieldEdit;pFieldEdit.Name_2 = shape;pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;IGeometryDef pGeometryDef = new GeometryDefClass();IGeometryDefEdit pGeoDefEdit = pGeometryDef as IGeometryDefEdit;pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;pGeoDefEdit.SpatialReference_2 = axMapControl1.SpatialReference;pFieldEdit.GeometryDef_2 = pGeometryDef;pFieldsEdit.AddField(pField);pField = new FieldClass();pFieldEdit = pField as IFieldEdit;pFieldEdit.Length_2 = 10;pFieldEdit.Name_2 = CODE;pFieldEdit.AliasName_2 = CODE;pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;pFieldsEdit.AddField(pField);String MapPath = E:dataresult;String LayerName = AddFeature;IWorkspaceFactory pWsf = new ShapefileWorkspaceFactory();IFeatureWorkspace pFws=pWsf.OpenFromFile(MapPath,0) as IFeatureWorkspace;IFeatureClass pFeatureClass=pFws.CreateFeatureClass(LayerName + .shp, pFields, null, null, esriFeatureType.esriFTSimple, shape, );新建 shapefile,自定义字段,路径自定义。 在文件里加入 POLYGON,自定义字段值IDataset pDataset = (IDataset)pFeatureClass;pFws = (IFeatureWorkspace)pDataset.Workspace;IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pFws;pWorkspaceEdit.StartEditing(true);pWorkspaceEdit.StartEditOperation();IFeatureBuffer pFeatureBuffer = pFeatureClass.CreateFeatureBuffer();/Create insert Feature Cursor using buffering = true.IFeatureCursor pFeatCursor = pFeatureClass.Insert(true);object featureOID;/定义新加元素的值pFeatureBuffer.set_Value(pFeatureBuffer.Fields.FindField(CODE),CODE);/生成 Polygon*IPolygon poly = new PolygonClass();IPoint pPoint = new PointClass();object o = Type.Missing;IPointCollection pPc = new MultipointClass();pPc = (IPointCollection)poly;for (int i = 0; i = 0; i+ )pPoint.PutCoords(200, 400);pPc.AddPoint(pPoint, ref o, ref o);pPoint.PutCoords(400, 400);pPc.AddPoint(pPoint, ref o, ref o);pPoint.PutCoords(400, 200);pPc.AddPoint(pPoint, ref o, ref o);pPoint.PutCoords(200, 200);pPc.AddPoint(pPoint, ref o, ref o);/生成完毕*pFeatureBuffer.Shape = poly;featureOID = pFeatCursor.InsertFeature(pFeatureBuffer);/Flush the feature cursor to the database/Calling flush allows you to handle any errors at a known time rather then on the cursor destruction.pFeatCursor.Flush();pWorkspaceEdit.StopEditOperation();pWorkspaceEdit.StopEditing(true);/释放 CursorSystem.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatCursor);axMapControl1.AddShapeFile(MapPath,LayerName+.shp);图层属性操作(一)加载 MXD 地图后,添加 2 个 Combox,其中 comboBoxLayer 用于显示地图 Layer,comboBoxField 用于显示图层字段。一个 Listbox,用于获得字段的值。获得地图 Layer 的函数代码:1/加载 Layer 函数2private void AddLayerToCombox(ComboBox comboxLayer)34int LyrCount = axMapControl1.LayerCount;5for (int i = 0; i = LyrCount - 1; i+)67comboBoxLayer.Items.Add(axMapControl1.get_Layer(i).Name);8/亦或 comboBoxLayer.Items.Insert(i, axMapControl1.get_Layer(i).Name);910获得字段函数代码:1private void AddFieldToCombox(ComboBox ComboxLayer,ComboBox ComboxField)23if (comboBoxLayer.Items.Count = 0) return;4else56IFeatureLayer pFeatureLayer=axMapControl1.get_Layer(comboBoxLayer.SelectedIndex) as IFeatureLayer;/或者通过名称来定位到图层7IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;8int FieldCount = pFeatureClass.Fields.FieldCount;9for (int i = 0; i = FieldCount - 1;i+ )1011IField pField = pFeatureClass.Fields.get_Field(i);/或者将 IFeatureLayer 转化为 ILayerFields 类,进行字段查询12comboBoxField.Items.Add(pField.Name);131415获得字段全部属性值函数代码:1private int FindFieldValue(IFeatureLayer pFeatureLayer,string pFieldName,ListBox ListBox)23int FieldCount=0;4IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;5IFeatureCursor pFeatureCursor = pFeatureClass.Search(null,true);6IFeature pFeature = pFeatureCursor.NextFeature();7int index = pFeatureClass.FindField(pFieldName);89while(pFeature!=null)1011string strValue = pFeature.get_Value(index).ToString();12ListBox.Items.Add(strValue);13pFeature = pFeatureCursor.NextFeature();1415FieldCount=ListBox.Items.Count;16return FieldCount;17 函数返回了属性值的个数,并将属性值添加到 ListBox。其中第一个参数是 comboBoxLayer 中当前选中图层,第二个参数为 comboBoxField 当前选中字段,第三个参数为需要显示属 性值的 Listbox。这样就可以获得了类似于 ArcMap 中属性表查询中获得字段全部属性值(Get Unique Value) 的功能,为后面的属性查询奠定基础。属性查询可以通过 IQueryFilter 接口实现,日后在贴 矢量转栅格转自:/mynama/default.html?page=1IMap pMap = axMapControl1.Map;IFeatureLayer pFeatLyr = (IFeatureLayer)axMapControl1.get_Layer(0);IFeatureClass pFeatClass = pFeatLyr.FeatureClass;IFeatureClassDescriptor pFClsDp = new FeatureClassDescriptorClass();pFClsDp.Create(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- ERP系统实施方案实例解析
- 工业重点设施安全隐患检查记录
- 初中数学教研组年度工作计划书
- 电气设备安全标识制作标准
- 江苏省淮安市洪泽县2026届九年级物理第一学期期末经典模拟试题含解析
- 2026届辽宁省沈阳市法库县九年级物理第一学期期末经典模拟试题含解析
- 重庆市实验学校2026届物理九上期中达标检测试题含解析
- 2026届浙江省杭州市杭州市萧山区高桥初级中学物理九年级第一学期期末监测试题含解析
- 河北省廊坊市5月份2026届九上物理期中质量检测试题含解析
- 福建省龙岩市北城中学2026届物理九上期中联考试题含解析
- 国家开放大学《Python语言基础》实验4:条件分支结构基本应用参考答案
- 预防错装漏装措施
- 船舶火灾的危险性及预防范本
- 主要树种树高级立木材积表
- JJG 443-2023燃油加油机(试行)
- 历年大学英语四六级翻译真题
- 燃气管网新建及改造冬雨季施工措施
- 备品备件仓库管理规定培训课件
- 【老年患者留置导尿漏尿的护理措施综述报告4000字】
- 全国中学生英语能力竞赛(NEPCS)高一组决赛(含答案和听力)
- (完整版)软件工程导论(第六版)张海藩牟永敏课后习题答案
评论
0/150
提交评论