youlitai
路人甲
路人甲
  • 注册日期2008-01-25
  • 发帖数9
  • QQ
  • 铜币146枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1521回复:1

关于创建shape文件

楼主#
更多 发布于:2008-10-05 22:40
<P>
<TABLE  cellSpacing=0 cellPadding=0 border=0>

<TR >
<TD  vAlign=top width=473>
<P >我是按arc GIS 开发宝典做的,就是在arc map  工具-》宏-》vb编辑器 ,然后在normal节点下,创建了一个窗体,在button 按钮的响应函数中复制了这些代码:</P>
<P >Private Sub CreatShapeFile(ByVal sFilePath As String, ByVal sFileName As String)<p></p></P>
<P >    Dim pFeatureWorkspace           As IFeatureWorkspace<p></p></P>
<P >    Dim pWorkspaceFactory           As IWorkspaceFactory<p></p></P>
<P >    Dim pFields                     As IFields<p></p></P>
<P >    Dim pFieldsEdit                 As IFieldsEdit<p></p></P>
<P >    Dim pField                      As IField<p></p></P>
<P >    Dim pFieldEdit                  As IFieldEdit<p></p></P>
<P >    Dim pGeometryDef                As IGeometryDef<p></p></P>
<P >    Dim pGeometryDefEdit            As IGeometryDefEdit<p></p></P>
<P >    Dim pFeatClass                  As IFeatureClass<p></p></P>
<P >    Dim sShapeFieldName             As String<p></p></P>
<P >    Dim sNewShapeFileName           As String<p></p></P>
<P >    <p></p></P>
<P >On Error GoTo ErrorHandler:<p></p></P>
<P >    sNewShapeFileName = Dir(sFilePath ; sFileName ; ".shp")<p></p></P>
<P >    If (sNewShapeFileName <> "") Then<p></p></P>
<P >        MsgBox ("文件已经存在")<p></p></P>
<P >        Exit Sub<p></p></P>
<P >    End If<p></p></P>
<P >    <p></p></P>
<P >    sShapeFieldName = "Shape"<p></p></P>
<P >  <p></p></P>
<P >    'Open the folder to contain the shapefile as a workspace<p></p></P>
<P >    Set pWorkspaceFactory = New ShapefileWorkspaceFactory<p></p></P>
<P >    Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(sFilePath, 0)<p></p></P>
<P >    <p></p></P>
<P >    'Set up a simple fields collection<p></p></P>
<P >    Set pFields = New esriCore.Fields<p></p></P>
<P >    Set pFieldsEdit = pFields<p></p></P>
<P >    <p></p></P>
<P >    'Make the shape field<p></p></P>
<P >    'it will need a geometry definition, with a spatial reference<p></p></P>
<P >    Set pField = New esriCore.Field<p></p></P>
<P >    Set pFieldEdit = pField<p></p></P>
<P >    pFieldEdit.Name = sShapeFieldName<p></p></P>
<P >    pFieldEdit.Type = esriFieldTypeGeometry<p></p></P>
<P >    <p></p></P>
<P >    Set pGeometryDef = New GeometryDef<p></p></P>
<P >    Set pGeometryDefEdit = pGeometryDef<p></p></P>
<P >    With pGeometryDefEdit<p></p></P>
<P >        .GeometryType = esriGeometryPolygon<p></p></P>
<P >        Set .SpatialReference = New UnknownCoordinateSystem<p></p></P>
<P >    End With<p></p></P>
<P >    Set pFieldEdit.GeometryDef = pGeometryDef<p></p></P>
<P >    pFieldsEdit.AddField pField<p></p></P>
<P >        'Add others miscellaneous text field<p></p></P>
<P >    Set pField = New esriCore.Field<p></p></P>
<P >    Set pFieldEdit = pField<p></p></P>
<P >    With pFieldEdit<p></p></P>
<P >        .Name = "SmallInteger"<p></p></P>
<P >        .Type = esriFieldTypeSmallInteger<p></p></P>
<P >    End With<p></p></P>
<P >    pFieldsEdit.AddField pField<p></p></P>
<P >    <p></p></P>
<P >    Set pField = New esriCore.Field<p></p></P>
<P >    Set pFieldEdit = pField<p></p></P>
<P >    With pFieldEdit<p></p></P>
<P >        .Name = "Integer"<p></p></P>
<P >        .Type = esriFieldTypeInteger<p></p></P>
<P >    End With<p></p></P>
<P >    pFieldsEdit.AddField pField<p></p></P>
<P >    <p></p></P>
<P >    Set pField = New esriCore.Field<p></p></P>
<P >    Set pFieldEdit = pField<p></p></P>
<P >    With pFieldEdit<p></p></P>
<P >        .Name = "Single"<p></p></P>
<P >        .Type = esriFieldTypeSingle<p></p></P>
<P >    End With<p></p></P>
<P >    pFieldsEdit.AddField pField<p></p></P>
<P >    <p></p></P>
<P >    Set pField = New esriCore.Field<p></p></P>
<P >    Set pFieldEdit = pField<p></p></P>
<P >    With pFieldEdit<p></p></P>
<P >        .Precision = 5<p></p></P>
<P >        .Scale = 5<p></p></P>
<P >.Name = "Double"<p></p></P>
<P >        .Type = esriFieldTypeDouble<p></p></P>
<P >    End With<p></p></P>
<P >    pFieldsEdit.AddField pField<p></p></P>
<P >    <p></p></P>
<P >    Set pField = New esriCore.Field<p></p></P>
<P >    Set pFieldEdit = pField<p></p></P>
<P >    With pFieldEdit<p></p></P>
<P >        .Length = 30<p></p></P>
<P >        .Name = "String"<p></p></P>
<P >        .Type = esriFieldTypeString<p></p></P>
<P >    End With<p></p></P>
<P >    pFieldsEdit.AddField pField<p></p></P>
<P >    <p></p></P>
<P >    Set pField = New esriCore.Field<p></p></P>
<P >    Set pFieldEdit = pField<p></p></P>
<P >    With pFieldEdit<p></p></P>
<P >        .Name = "Date"<p></p></P>
<P >        .Type = esriFieldTypeDate<p></p></P>
<P >    End With<p></p></P>
<P >    pFieldsEdit.AddField pField<p></p></P>
<P >    <p></p></P>
<P >    'Create the shapefile<p></p></P>
<P >    '(some parameters apply to geodatabase options and can be defaulted as Nothing)<p></p></P>
<P >    Set pFeatClass = pFeatureWorkspace.CreateFeatureClass _<p></p></P>
<P >        (sFileName, pFields, Nothing, Nothing, _<p></p></P>
<P >        esriFTSimple, sShapeFieldName, "")<p></p></P>
<P > <p></p></P>
<P >    sNewShapeFileName = Dir(sFilePath ; "\MyShapeFile.shp")<p></p></P>
<P >    If (sNewShapeFileName = "") Then<p></p></P>
<P >        MsgBox ("Build Success")<p></p></P>
<P >    Else<p></p></P>
<P >        MsgBox ("Build Fail")<p></p></P>
<P >    End If<p></p></P>
<P >    Exit Sub<p></p></P>
<P >ErrorHandler:<p></p></P>
<P >    MsgBox Err.Description<p></p></P>
<P >End Sub<p></p></P>
<P ><p> </p></P>
<P >Private Sub UIButtonControl1_Click()<p></p></P>
<P >    Dim pVBProject              As VBProject<p></p></P>
<P >On Error GoTo ErrorHandler:<p></p></P>
<P >    Set pVBProject = ThisDocument.VBProject<p></p></P>
<P >    <p></p></P>
<P >    'Dont include .shp extension<p></p></P>
<P >    CreatShapeFile pVBProject.FileName ; "\..\..\..\.." ; "\data\", "MyShapeFile"<p></p></P>
<P >    Exit Sub<p></p></P>
<P >ErrorHandler:<p></p></P>
<P >    MsgBox Err.Description<p></p></P>
<P >End Sub<p></p></P>
<P ><p> </p></P>
<P >Private Sub UIButtonControl1_Click()<p></p></P>
<P >    Dim pVBProject              As VBProject<p></p></P>
<P >On Error GoTo ErrorHandler:<p></p></P>
<P >    Set pVBProject = ThisDocument.VBProject<p></p></P>
<P >    <p></p></P>
<P >    'Dont include .shp extension<p></p></P>
<P >    CreatShapeFile pVBProject.FileName ; "\..\..\..\.." ; "\data\", "MyShapeFile"<p></p></P>
<P >    Exit Sub<p></p></P>
<P >ErrorHandler:<p></p></P>
<P >    MsgBox Err.Description<p></p></P>
<P >End Sub<p></p></P></TD></TR></TABLE></P>
<P>编译的时候类似这样的语句:Set pFields = New esriCore.Fields   提示:New esriCore.Fields 用户定义类型未定义   这个该怎么解决呢?</P>
喜欢0 评分0
youlitai
路人甲
路人甲
  • 注册日期2008-01-25
  • 发帖数9
  • QQ
  • 铜币146枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2008-10-07 10:05
<P>自己搞定 ,网上看到一篇博文说 在8.3下是esriCore.Fields   ,但在9.0以后esriGeoDatabase.Field </P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部