1、SpatialReference;pFieldEdit.GeometryDef_2 = pGeometryDef;pFieldsEdit.AddField(pField);/新建字段pField = new FieldClass();pFieldEdit = pField as IFieldEdit;pFieldEdit.Length_2 = 15;SchoolNamepFieldEdit.AliasName_2 = pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;string mappath = E:datastring layer
2、name=schoolIWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(mappath,0) as IFeatureWorkspace;pFeatureWorkspace.CreateFeatureClass(layername+.shp,pFields,null,null,esriFeatureType.esriFTSimple,);axMapControl1.Add
3、ShapeFile(mappath,layername+代码中路径名称可以自定义posted on 2008-07-12 15:28 duckweeds 阅读(137) 评论(0) 编辑 收藏 网摘 所属分类:AE+C#AE 创建各种类型的 featureclass 代码VB.Net 源码 创建 Annotation 类型的 featureclass/summaryparam name=pWorkspaceannotation 的工作空间pTextSymbolannotation 的 symbolpRefeScaleannotation 的比例pAnnoFeatNameannotation 的
4、名称创建的 Annotation FeatureclassremarksPrivate 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 IFie
5、lds Dim pSource As ICloneDim pObjectClassDesc As IObjectClassDescriptionDim pFeatClassDesc As IFeatureClassDescription创建 Annotation 的 FieldspObjectClassDesc = New AnnotationFeatureClassDescription pFeatClassDesc = pObjectClassDescpSource = pObjectClassDesc.RequiredFields pFields = pSource.Clone创建 An
6、notation 的 Geometry defintionpField = pFields.Field(pFields.FindField(pFeatClassDesc.ShapeFieldName)创建 Reference scaleDim pGraphicsLayerScale As IGraphicsLayerScalepGraphicsLayerScale = New GraphicsLayerScale pGraphicsLayerScale.ReferenceScale = pRefeScale pGraphicsLayerScale.Units = esriUnits.esriM
7、eters创建 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创建 Label 的相关属性Dim p
8、OverposterProperties As IOverposterPropertiesDim pAnnoPropsColl As IAnnotateLayerPropertiesCollectionDim pLabelEngineLP As ILabelEngineLayerProperties Dim pAnnotateLayerProps As IAnnotateLayerProperties pOverposterProperties = New BasicOverposterProperties pAnnoPropsColl = New AnnotateLayerPropertie
9、sCollection pLabelEngineLP = New LabelEngineLayerProperties pAnnotateLayerProps = pLabelEngineLP pAnnotateLayerProps.Class = pLabelEngineLP.Symbol = pTextSymbol pLabelEngineLP.SymbolID = pSymbolIdent.ID pAnnoPropsColl.Add(pLabelEngineLP)创建 Annotation layerDim pAnnoLayerFactory As IAnnotationLayerFac
10、tory Dim pAnnoLayer As IAnnotationLayer pAnnoLayerFactory = New FDOGraphicsLayerFactorypAnnoLayer = pAnnoLayerFactory.CreateAnnotationLayer(pWorkspace, Nothing, pAnnoFeatName, pField.GeometryDef, Nothing, pAnnoPropsColl, pGraphicsLayerScale, pSymbolColl, False, False, False, True, pOverposterPropert
11、ies, )Return CType(pAnnoLayer, IFeatureLayer).FeatureClassEnd Function 创建存于 Shapefile 中的 featureclasssDirsNameshapeTypehasMhasZpSRpFieldsPublic Shared Function CreateShapefile(ByVal sDir As String, ByVal sName As String, ByVal shapeType As esriGeometryType, _ByVal hasM As Boolean, ByVal hasZ As Bool
12、ean, 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 shapeWork
13、space 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 Except
14、ion MsgBox(ex.Message) Return NothingEnd Try 创建存于内存中的 FeatureclassfeatureClassNamePublic Shared Function GetSimpleFeatureClass(ByVal pFields As IFields, ByVal featureClassName As String) As IFeatureClassDim pSwf As IWorkspaceFactory = New InMemoryWorkspaceFactoryDim pWorkspaceName As IWorkspaceName
15、= 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, , Nothing)Return pFCCatch ex As Exception 创建存于 Access 中的 featureclas
16、spAccessPathpAccessNamePublic Function CreateAccessFeatureClass(ByVal pFields As IFields, ByVal pAccessPath As String, ByVal pAccessName As String, ByVal featureClassName As String) As IFeatureClassDim pSwf As IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory Dim pWorkspaceNa
17、me As IWorkspaceName = pSwf.Create(pAccessPath, pAccessName, Nothing, 0) Dim pFWS As IFeatureWorkspace = CType(pWorkspaceName, IName).Open()pFields = CreateBasicFields(esriGeometryType.esriGeometryPoint, False, False, NewUnknownCoordinateSystem)AE+C#实现鹰眼功能(二)(带鼠标拖动)vs2005+AE9.2 实现,主要功能:鹰眼视图里面鼠标左键画红框
18、,右键拖动代码中主视图为 Mapcontrol1,鹰眼视图为 MapControl2。 主要利用了 Envelope 进行视图范围传递,从而控制视图同步等。 代码如下:几个变量声明 :/变量IMapDocument pMapDocument = new MapDocumentClass();IEnvelope pEn = new EnvelopeClass();object oFillobject = new object();private void CreateOverviewSymbol()IRgbColor iRgb = new RgbColorClass();iRgb.RGB = 2
19、55;ILineSymbol pOutline = new SimpleLineSymbolClass();pOutline.Color = iRgb;pOutline.Width = 2.3;ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();pSimpleFillSymbol.Outline = pOutline;pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;oFillobject = pSimpleFillSymbol;控制拖动变量:p
20、rivate IMoveEnvelopeFeedback pSmallViewerEnvelope;/鹰眼小地图的红框,IMoveEnvelopeFeedback,用来移动 Envelope 的接口private IPoint pSmallViewerMouseDownPt;/拖动时鼠标落点private bool isTrackingSmallViewer = false; /标识是否在拖动static int moveCount = 0;/记录移动的个数,为移动过程中显示红框用。axMapControl1_OnMapReplaced 事件:axMapControl2.LoadMxFile(
21、axMapControl1.DocumentFilename); 两个视图加载数据可能存在鹰眼视图数据显示不完全(不知道是不是我电脑的毛病。),这 样加载可以控制数据的同步更新axMapControl1_OnExtentUpdated 事件:pEn = e.newEnvelope as IEnvelope;axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);axMapControl1_OnAfterDraw:esriViewDrawPhase viewDrawPhas
22、e = (esriViewDrawPhase)e.viewDrawPhase;if (viewDrawPhase = esriViewDrawPhase.esriViewForeground)axMapControl2.DrawShape(pEn, ref oFillobject);axMapControl2_OnMouseDown:if(e.button=1)/左键画红框pEn = axMapControl2.TrackRectangle();axMapControl1.Extent = pEn;if (e.button = 2)/右键拖动红框pSmallViewerMouseDownPt
23、= new PointClass();pSmallViewerMouseDownPt.PutCoords(e.mapX, e.mapY);axMapControl1.CenterAt(pSmallViewerMouseDownPt);isTrackingSmallViewer = true;if (pSmallViewerEnvelope = null)pSmallViewerEnvelope = new MoveEnvelopeFeedbackClass();pSmallViewerEnvelope.Display = axMapControl2.ActiveView.ScreenDispl
24、ay;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);pSmallViewerEnvelope.MoveTo(pSmallViewerMouseDownPt);axMapControl2_OnMouseUp:if (pSmallViewerEnvelope != null)pEn = pSmallViewerEnvelope.St
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1