码迷,mamicode.com
首页 > 其他好文 > 详细

ArcEngine 创建线要素图层

时间:2016-05-13 12:31:23      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

在创建要素图层的时候,默认的几何类型是Polygon:

Dim objectClassDescription As IObjectClassDescription = New FeatureClassDescription
Dim fields2 As Fields = objectClassDescription.RequiredFields

上面代码的fields2包含2个字段,一个OBJECTID字段和一个SHAPE字段,而SHAPE字段决定了要素的几何类型(GeometryType),这个是环境自己生成,他的几何类型是Polygon。

如果想生成其他的几何类型的要素图层就要自己手动创建这两个字段,并在SHAPE添加几何类型的信息,下面图层的要素类型为Polyline。如下代码所示:

 Dim featureClassName As String = "图层名称" 临时图层名称
        Dim workspaceFactory As IWorkspaceFactory = New InMemoryWorkspaceFactory() 内存空间
        Dim WorkspaceName As IWorkspaceName = workspaceFactory.Create("", "MyWorkspace", Nothing, 0)
        Dim name As IName = WorkspaceName
        Dim workspace As IWorkspace = name.Open()
        Dim featureWorkspace As IFeatureWorkspace = workspace

        Dim workspace2 As IWorkspace2 = workspace
        Dim fields As IFields = Nothing
        Dim CLSID As ESRI.ArcGIS.esriSystem.UID = Nothing
        Dim CLSEXT As ESRI.ArcGIS.esriSystem.UID = Nothing
        Dim strConfigKeyword As String = ""
        Dim featureClass As IFeatureClass
         赋值类ID如果未分配
        If CLSID Is Nothing Then
            CLSID = New ESRI.ArcGIS.esriSystem.UID
            CLSID.Value = "esriGeoDatabase.Feature"
        End If
        环境默认生成的两个字段,字段的几何类型为Polygon,决定了要素图层的集合类型
        Dim objectClassDescription As IObjectClassDescription = New FeatureClassDescription
        Dim fields2 As Fields = objectClassDescription.RequiredFields
        If fields Is Nothing Then
             创建要素几何信息
            Dim pGeometryDef As IGeometryDef = New GeometryDef()  为esriFieldTypeGeometry类型的字段创建几何定义,包括类型和空间参照    
            Dim pGeometryDefEdit As IGeometryDefEdit = pGeometryDef
            pGeometryDefEdit.GridCount_2 = 1
            pGeometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline 决定要素图层的几何类型
            pGeometryDefEdit.SpatialReference_2 = pMap.SpatialReference

            fields = New Fields
            Dim fieldsEdit As IFieldsEdit = CType(fields, IFieldsEdit)
            自己创建OBJECTID字段
            Dim fieldOID As IField = New Field()
            Dim fieldEditOID As IFieldEdit = CType(fieldOID, IFieldEdit)
            fieldEditOID.Name_2 = "OBJECTID"
            fieldEditOID.AliasName_2 = "OBJECTID"
            fieldEditOID.Type_2 = esriFieldType.esriFieldTypeOID
            fieldEditOID.Editable_2 = False
            fieldsEdit.AddField(fieldOID)

            自己创建几何字段,
            Dim fieldShape As IField = New Field()
            Dim fieldEditShape As IFieldEdit = CType(fieldShape, IFieldEdit)
            fieldEditShape.Name_2 = "SHAPE"
            fieldEditShape.AliasName_2 = "SHAPE"
            fieldEditShape.Type_2 = esriFieldType.esriFieldTypeGeometry
            fieldEditShape.GeometryDef_2 = pGeometryDef
            fieldEditShape.Editable_2 = True
            fieldsEdit.AddField(fieldShape)



            Dim field As IField = New Field
            Dim fieldEdit As IFieldEdit = CType(field, IFieldEdit)  显示转换
             设置字段属性
            fieldEdit.Name_2 = "RISK"
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble
            fieldEdit.IsNullable_2 = False
            fieldEdit.AliasName_2 = "RISK"
            fieldEdit.DefaultValue_2 = 0
            fieldEdit.Editable_2 = True
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry
            fieldsEdit.AddField(field)
            Dim field2 As IField = New Field
            Dim fieldEdit2 As IFieldEdit = CType(field2, IFieldEdit)  显示转换
             设置字段属性
            fieldEdit2.Name_2 = "管线ObjId"
            fieldEdit2.Type_2 = esriFieldType.esriFieldTypeInteger
            fieldEdit2.IsNullable_2 = False
            fieldEdit2.AliasName_2 = "管线ObjId"
            fieldEdit2.DefaultValue_2 = 0
            fieldEdit2.Editable_2 = True
            添加到字段集中
            fieldsEdit.AddField(field2)
            fields = CType(fieldsEdit, IFields)
        End If
        Dim strShapeField As String = ""
        Dim j As Int32
        For j = 0 To fields.FieldCount
            If fields.Field(j).Type = esriFieldType.esriFieldTypeGeometry Then
                strShapeField = fields.Field(j).Name
                fields.Field(j).GeometryDef.GeometryType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline
                Exit For
            End If
        Next j
        Dim fieldChecker As IFieldChecker = New FieldChecker
        Dim enumFieldError As IEnumFieldError = Nothing
        Dim validatedFields As IFields = Nothing
        fieldChecker.ValidateWorkspace = workspace
        fieldChecker.Validate(fields, enumFieldError, validatedFields)
        featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword)

 

ArcEngine 创建线要素图层

标签:

原文地址:http://www.cnblogs.com/GIScore/p/5487287.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!