AE创建各种类型的featureclass代码
更新时间:2023-08-18 17:12:01 阅读量: 资格考试认证 文档下载
- ae请求创建未知属性类型推荐度:
- 相关推荐
代码由 ESRI 社区 GIScafe 提供
IFields pFields = new FieldsClass(); IFieldsEdit pFieldsEdit = pFields as IFieldsEdit; IField pField = new FieldClass(); IFieldEdit pFieldEdit = pField as IFieldEdit; _2 = "shape"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeome try;
//set up Geometry Definition IGeometryDef pGeometryDef = new GeometryDefClass(); IGeometryDefEdit pGeometryDefEdit = pGeometryDef a s IGeometryDefEdit;
pGeometryDefEdit.GeometryType_2 = esriGeometryType.e sriGeometryPoint; //Point,line,polygon et.
pGeometryDefEdit.SpatialReference_2 = axMapControl1. SpatialReference;
//新建字段 pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.Length_2 = 15; _2 = "SchoolName"; pFieldEdit.GeometryDef_2 = pGeometryDef; pFieldsEdit.AddField(pField);
pFieldEdit.AliasName_2 = "SchoolName"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeStrin g;
pFieldsEdit.AddField(pField);
string mappath = @"E:\data"; string layername="school"; IWorkspaceFactory pWorkspaceFactory = new ShapefileW orkspaceFactory();
IFeatureWorkspace pFeatureWorkspace = pWorkspaceFact ory.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 阅读(137) 所属分类:
AE 创建各种类型的 featureclass 代码 源码
''' <summary>
''' 创建 Annotation 类型的 featureclass
''' </summary>
''' <param name="pWorkspace">annotation 的工作空间</param>
''' <param name="pTextSymbol">annotation 的 symbol</param>
''' <param name="pRefeScale">annotation 的比例</param>
''' <param name="pAnnoFeatName">annotation 的名称</param>
''' <returns>创建的 Annotation Featureclass</returns>
''' <remarks></remarks>
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 IFeatureClass
Dim pField As IField
Dim pFields As IFields
Dim pSource As IClone
Dim pObjectClassDesc As IObjectClassDescription
Dim pFeatClassDesc As IFeatureClassDescription
''创建 Annotation 的 Fields
pObjectClassDesc = New AnnotationFeatureClassDescription
pFeatClassDesc = pObjectClassDesc
pSource = pObjectClassDesc.RequiredFields
pFields = pSource.Clone
''创建 Annotation 的 Geometry defintion
pField = pFields.Field(pFields.FindField(pFeatClassDesc.ShapeFieldName))
''创建 Reference scale
Dim pGraphicsLayerScale As IGraphicsLayerScale
pGraphicsLayerScale = New GraphicsLayerScale
pGraphicsLayerScale.ReferenceScale = pRefeScale
pGraphicsLayerScale.Units = esriUnits.esriMeters
''创建 Symbolcollection
Dim pSymbolColl As ISymbolCollection2
Dim 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 IOverposterProperties Dim pAnnoPropsColl As IAnnotateLayerPropertiesCollection
Dim 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 layer
Dim pAnnoLayerFactory As IAnnotationLayerFactory
Dim pAnnoLayer As IAnnotationLayer
pAnnoLayerFactory = New FDOGraphicsLayerFactory
pAnnoLayer = pAnnoLayerFactory.CreateAnnotationLayer(pWorkspace, Nothing, pAnnoFeatName,
pField.GeometryDef, Nothing, pAnnoPropsColl, pGraphicsLayerScale, pSymbolColl, False, False, False, True, pOverposterProperties, "")
Return CType(pAnnoLayer, IFeatureLayer).FeatureClass End Function
''' <summary>
''' 创建存于 Shapefile 中的 featureclass
''' </summary> ''' <param name="sDir"></param> ''' <param name="sName"></param> ''' <param name="shapeType"></param> ''' <param name="hasM"></param> ''' <param name="hasZ"></param> ''' <param name="pSR"></param> ''' <param name="pFields"></param> ''' <returns></returns> ''' <remarks></remarks>
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 IFeatureClass
Try
Dim shapeWorkspaceFactory As IWorkspaceFactory
shapeWorkspaceFactory = New ShapefileWorkspaceFactory
Dim shapeWorkspace As IFeatureWorkspace
shapeWorkspace = shapeWorkspaceFactory.OpenFromFile(sDir, 0)
If (Not shapeWorkspace Is Nothing) Then
If pFields Is Nothing Then pFields = CreateBasicFields(shapeType, hasM, hasZ, pSR) '
Dim pFClass As IFeatureClass
pFClass = shapeWorkspace.CreateFeatureClass(sName, pFields, Nothing, Nothing,
esriFeatureType.esriFTSimple, "Shape", "")
Return pFClass End If Return Nothing
Catch ex As Exception
MsgBox(ex.Message)
Return Nothing
End Try
End Function
''' <summary>
''' 创建存于内存中的 Featureclass
''' </summary> ''' <param name="pFields"></param>
''' <param name="featureClassName"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function GetSimpleFeatureClass(ByVal pFields As IFields, ByVal featureClassName As String) As IFeatureClass
Try Dim pSwf As IWorkspaceFactory = New InMemoryWorkspaceFactory
Dim 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 pFC Catch ex As Exception Return Nothing End Try End Function
''' <summary>
''' 创建存于 Access 中的 featureclass
''' </summary> ''' <param name="pFields"></param> ''' <param name="pAccessPath"></param> ''' <param name="pAccessName"></param> ''' <param name="featureClassName"></param> ''' <returns></returns>
''' <remarks></remarks>
Public Function CreateAccessFeatureClass(ByVal pFields As IFields, ByVal pAccessPath As String, ByVal pAccessName As String, ByVal featureClassName As String) As IFeatureClass
Try
Dim 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, New
UnknownCoordinateSystem)
Dim pFC As IFeatureClass = pFWS.CreateFeatureClass(featureClassName, pFields, Nothing, Nothing,
esriFeatureType.esriFTSimple, "Shape", Nothing)
Return pFC Catch ex As Exception Return Nothing End Try End Function
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;//鹰眼小地图的红框,IMov eEnvelopeFeedback,用来移动 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.esriViewForegro
und, 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.esriViewFore ground, 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 版。
正在阅读:
乌鲁木齐市初中学籍管理规定10-25
如何提升教师的科研能力04-13
Web安全测试规范01-18
我的超能力作文700字06-18
小学生成长的故事作文10篇.doc04-15
英译汉01-30
2011年内蒙古自治区数据基础理论大纲05-18
- 梳理《史记》素材,为作文添彩
- 2012呼和浩特驾照模拟考试B2车型试题
- 关于全面推进施工现场标准化管理实施的通知(红头文件)
- 江西省房屋建筑和市政基础设施工程施工招标文件范本
- 律师与公证制度第2阶段练习题
- 2019-2020年最新人教版PEP初三英语九年级上册精编单元练习unit6训练测试卷内含听力文件及听力原文
- 小升初数学模拟试卷(十四) 北京版 Word版,含答案
- 认识创新思维特点 探讨创新教育方法-精选教育文档
- 00266 自考 社会心理学一(复习题大全)
- 多媒体在语文教学中的运用效果
- 派出所派出所教导员述职报告
- 低压电工作业考试B
- 18秋福建师范大学《管理心理学》在线作业一4
- 中国铝业公司职工违规违纪处分暂行规定
- 13建筑力学复习题(答案)
- 2008年新密市师德征文获奖名单 - 图文
- 保安员培训考试题库(附答案)
- 银川市贺兰一中一模试卷
- 2011—2017年新课标全国卷2文科数学试题分类汇编 - 1.集合
- 湖北省襄阳市第五中学届高三生物五月模拟考试试题一
- featureclass
- 创建
- 各种
- 类型
- 代码
- 铝合金经硬质阳极氧化处理
- 常用材料标记示例
- 世界各国节假日表
- 2005年石油大学北京 沉积岩石学考研专业课
- 家长日常口语
- 新闻采访 试卷
- SAP-FI学习手册—应收账款2
- 室内吸毒植物大集合组图
- 入党思想汇报:树立正确的人生价值观
- 2013年麻疹类疫苗查漏补种活动摸底与接种情况登记表
- 中兴百货案例分析--重点讲解意识形态广告及后现代主义
- 广告发布合同--与商家
- 各部门、各类人员的岗位职责
- 全国2009年04月自学考试00179《谈判与推销技巧》历年真题
- 注射用重组人尿激酶原
- 2015 年个人理财作业满分答案网友提供
- 初级会计职称考试《初级会计实务》冲刺题(六)
- 力士乐A11V(L)O资料说明书
- 步进电机运动控制系统设计
- 职业规划大赛作品模板