shbq13952053115
路人甲
路人甲
  • 注册日期2005-05-24
  • 发帖数21
  • QQ
  • 铜币150枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1446回复:2

请看代码!!

楼主#
更多 发布于:2006-06-06 19:59
<P>Public Function CreateShapefile(sPath As String, sName As String) As IFeatureClass ' Dont include .shp extension<BR>  <BR>  ' Open the folder to contain the shapefile as a workspace<BR>  Dim pFWS As IFeatureWorkspace<BR>  Dim pWorkspaceFactory As IWorkspaceFactory<BR>  Set pWorkspaceFactory = New ShapefileWorkspaceFactory<BR>  <FONT color=#f70909>Set pFWS = pWorkspaceFactory.OpenFromFile(sPath, 0)<BR></FONT>  <BR>  ' Set up a simple fields collection<BR>  Dim pFields As IFields<BR>  Dim pFieldsEdit As IFieldsEdit<BR>  Set pFields = New Fields<BR>  Set pFieldsEdit = pFields<BR>  <BR>  Dim pField As IField<BR>  Dim pFieldEdit As IFieldEdit<BR>  <BR>  ' Make the shape field<BR>  ' it will need a geometry definition, with a spatial reference<BR>  Set pField = New Field<BR>  Set pFieldEdit = pField<BR>  pFieldEdit.Name = "Shape"<BR>  pFieldEdit.Type = esriFieldTypeGeometry<BR>  <BR>  Dim pGeomDef As IGeometryDef<BR>  Dim pGeomDefEdit As IGeometryDefEdit<BR>  Set pGeomDef = New GeometryDef<BR>  Set pGeomDefEdit = pGeomDef<BR>  With pGeomDefEdit<BR>    .GeometryType = esriGeometryPolygon<BR>    Set .SpatialReference = New UnknownCoordinateSystem<BR>  End With<BR>  Set pFieldEdit.GeometryDef = pGeomDef<BR>  pFieldsEdit.AddField pField</P>
<P>  ' Add another miscellaneous text field<BR>  Set pField = New Field<BR>  Set pFieldEdit = pField<BR>  With pFieldEdit<BR>      .Length = 30<BR>      .Name = "MiscText"<BR>      .Type = esriFieldTypeString<BR>  End With<BR>  pFieldsEdit.AddField pField<BR>  <BR>  ' Create the shapefile<BR>  ' (some parameters apply to geodatabase options and can be defaulted as Nothing)<BR>  Dim pFeatClass As IFeatureClass<BR>  Set pFeatClass = pFWS.CreateFeatureClass(sName, pFields, Nothing, _<BR>                                           Nothing, esriFTSimple, "Shape", "")<BR>                                           <BR>  Set CreateShapefile = pFeatClass<BR>End Function</P>
<P>Private Sub UIButtonControl1_Click()</P>
<P>    Dim pVBProject              As VBProject</P>
<P>On Error GoTo ErrorHandler:</P>
<P>    Set pVBProject = ThisDocument.VBProject</P>
<P>    </P>
<P>    'Dont include .shp extension</P>
<P>    CreateShapefile pVBProject.FileName ; "\..\..\..\.." ; "\data\", "MyShapeFile"</P>
<P>    Exit Sub</P>
<P>ErrorHandler:</P>
<P>    MsgBox Err.Description</P>
<P>End Sub</P>
<P> 初学AO : 想新建一个shapefile 文件  为什么到了红色的地方就出错了 请高手指点 </P>
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2006-06-09 15:23
出现什么错误?另外请修改标题内容,具体发贴方式看顶贴
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
shbq13952053115
路人甲
路人甲
  • 注册日期2005-05-24
  • 发帖数21
  • QQ
  • 铜币150枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2006-06-10 11:59
<P>就是执行不下去了 不知道为什么</P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部