AE创建各种类型的featureclass代码
更新时间:2023-07-17 10:35: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 版。
正在阅读:
数控技术专业建设规划03-12
市场营销策划实训计划10-09
2009年科技示范户集中培训方案01-05
亭湖区南港小学解说词12-29
12#层81216面规程05-12
云南省广南县一中2018年下学期6月份考试 高二生物12-18
CRTS-I型板式无砟轨道道床施工监理实施细则 - 图文04-23
电力系统污区分布图使用导则01-10
- 教学能力大赛决赛获奖-教学实施报告-(完整图文版)
- 互联网+数据中心行业分析报告
- 2017上海杨浦区高三一模数学试题及答案
- 招商部差旅接待管理制度(4-25)
- 学生游玩安全注意事项
- 学生信息管理系统(文档模板供参考)
- 叉车门架有限元分析及系统设计
- 2014帮助残疾人志愿者服务情况记录
- 叶绿体中色素的提取和分离实验
- 中国食物成分表2020年最新权威完整改进版
- 推动国土资源领域生态文明建设
- 给水管道冲洗和消毒记录
- 计算机软件专业自我评价
- 高中数学必修1-5知识点归纳
- 2018-2022年中国第五代移动通信技术(5G)产业深度分析及发展前景研究报告发展趋势(目录)
- 生产车间巡查制度
- 2018版中国光热发电行业深度研究报告目录
- (通用)2019年中考数学总复习 第一章 第四节 数的开方与二次根式课件
- 2017_2018学年高中语文第二单元第4课说数课件粤教版
- 上市新药Lumateperone(卢美哌隆)合成检索总结报告
- featureclass
- 创建
- 各种
- 类型
- 代码
- 病历书写规范2010年版(2011年3月)
- 学生管理信息系统可行性分析报告
- LEED认证-必维国际检验集团资料
- 电力系统稳态实验报告
- 财务管理习题集(最新)
- 铝合金经硬质阳极氧化处理
- 一年级第二学期健康教育课教案全集
- 论中华文明起源与发展的动力与机制
- 材料作文“曲与直”分析与讲评(整理精校版)
- 2014版核电站设备及零部件制造项目(立项及贷款用)可行性研究报告编制机构服务流程及案例展示
- 用CP成形的整体管在电炉炉底出钢口上的应用I
- 人教版英语必修2 Unit1 cultural relics 知识点详解
- 各部门、各类人员的岗位职责
- 教科版二年级上语文模拟卷
- “建设学风&160;从我做起”主题班会活动总结
- 国外公众参与旅游目的地公共事务研究综述
- 中兴百货案例分析--重点讲解意识形态广告及后现代主义
- 2014-2020年中国电磁炉行业调研与投资前景研究报
- 计算机模拟试卷4及答案
- 县长在全市安全生产约谈会上的表态发言