arcEngine classic code(2)

简介:

1 新建shp文件
Public Sub CreatShapeFile(ByVal sFilePath As String, ByVal sFileName As String)     '创建shapefile层文件
On Error GoTo Errhandle:
    Dim pWorkspaceFactory As IWorkspaceFactory
    Dim pFeatureWorkspace As IFeatureWorkspace
    Dim pFields As IFields
    Dim pFieldsEdit As IFieldsEdit
    Dim pField As IField
    Dim pFieldEdit As IFieldEdit
    Dim pGeometryDef As IGeometryDef
    Dim pGeometryDefEdit As IGeometryDefEdit
    Dim pFeatClass As IFeatureClass
    Dim sShapeFieldName As String
    Dim sNewShapeFileName As String

    sNewShapeFileName = Dir(sFilePath & "\" & sFileName & ".shp")
    If (sNewShapeFileName <> "") Then
             MsgBox ("文件已经存在")
        Exit Sub
    End If
    sShapeFieldName = "Shape"                                '先创建一个字段名字
    '创建一个文件夹来存放shapefile文件
    Set pWorkspaceFactory = New ShapefileWorkspaceFactory
    Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(sFilePath, 0)
    
    'Set up a simple fields collection
    Set pFields = New esriGeoDatabase.Fields
    Set pFieldsEdit = pFields
    'Make the shape field
    'it will need a geometry definition, with a spatial reference
    Set pField = New esriGeoDatabase.Field
    Set pFieldEdit = pField
    '创建第一个字段
    pFieldEdit.Name = sShapeFieldName
    pFieldEdit.Type = esriFieldTypeGeometry
    Set pGeometryDef = New GeometryDef
    Set pGeometryDefEdit = pGeometryDef
    With pGeometryDefEdit
    .GeometryType = esriGeometryPolygon
    Set .SpatialReference = New UnknownCoordinateSystem
    End With
    Set pFieldEdit.GeometryDef = pGeometryDef
    pFieldsEdit.AddField pField               '添加字段到字段集中
    '再添加一个字段
    Set pField = New esriGeoDatabase.Field
    Set pFieldEdit = pField
    With pFieldEdit
        .Name = "type"
        .Type = esriFieldTypeString
    End With
    pFieldsEdit.AddField pField               '添加字段到字段集中
    '开始创建shapefile层文件
    '(some parameters apply to geodatabase options and can be defaulted as Nothing)
    Set pFeatClass = pFeatureWorkspace.CreateFeatureClass _
    (sFileName, pFields, Nothing, Nothing, _
    esriFTSimple, sShapeFieldName, "")
'    sNewShapeFileName = Dir(sFilePath & "\" & sFileName & ".shp")
'      If (sNewShapeFileName = "") Then
'        MsgBox ("Build Fail")
'    Else
'        MsgBox ("Build Success")
'    End If
Errhandle:
    Set pFeatClass = Nothing
    Set pGeometryDefEdit = Nothing
    Set pGeometryDef = Nothing
    Set pFieldEdit = Nothing
    Set pField = Nothing
    Set pFieldsEdit = Nothing
    Set pFields = Nothing
    Set pFeatureWorkspace = Nothing
    Set pWorkspaceFactory = Nothing


    If Err.Description <> "" Then
    MsgBox Err.Description & ":创建shapefile失败!", vbInformation, "提示信息"
    End If
End Sub




    本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/xiexiaokui/archive/2008/05/11/1192358.html,如需转载请自行联系原作者


相关文章
Latex更改字体颜色以及快速生成 SCI 论文的 revised version 和 pure version
Latex更改字体颜色以及快速生成 SCI 论文的 revised version 和 pure version
Latex更改字体颜色以及快速生成 SCI 论文的 revised version 和 pure version
|
2月前
|
算法 数据挖掘
文献讨论-Chromosome-Level Genome Assembly of the Green Peafowl (Pavo muticus)
关键词:长读长测序;基因测序;变异检测; 标题(英文):Chromosome-Level Genome Assembly of the Green Peafowl (Pavo muticus) 标题(中文):绿孔雀(Pavo muticus)的染色体级基因组组装 该研究发现了目前最全面、最完整的绿孔雀基因组,它将成为未来绿孔雀生态学、进化和保护研究的宝贵资源。
44 0
|
Unix
全网首发:configure: error: cannot guess build type; you must specify one
全网首发:configure: error: cannot guess build type; you must specify one
817 0
|
前端开发 JavaScript 测试技术
类型体操之实现 type-challenges 中的 built-in 的所有类型
#built-in 是 type-challenges 库中的一个 tag,里面一共包括了 7 个类型,其中前两个就是之前介绍过的 类型体操之实现 Pick 和 Omit 中的 Pick 和 Omit
|
机器学习/深度学习 人工智能 前端开发
VS Code settings.json 10 个高(装)阶(杯)配置!
VS Code settings.json 10 个高(装)阶(杯)配置!
|
C++
VS Code注释插件doxygen documentation generator
VS Code注释插件doxygen documentation generator
782 0
VS Code注释插件doxygen documentation generator
|
Android开发
Android Studio的怪错:AndroidManifest.xml unresolve symbol package/connot resolve symbol/Animations
Android Studio的怪错:AndroidManifest.xml unresolve symbol package/connot resolve symbol/Animations
86 0
Android Studio的怪错:AndroidManifest.xml unresolve symbol package/connot resolve symbol/Animations
PAT (Advanced Level) Practice - 1055 The World‘s Richest(25 分)
PAT (Advanced Level) Practice - 1055 The World‘s Richest(25 分)
114 0
PAT (Basic Level) Practice (中文)- 1052 卖个萌(20 分)
PAT (Basic Level) Practice (中文)- 1052 卖个萌(20 分)
111 0

热门文章

最新文章