阅读:1446回复:2
请看代码!!
<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> |
|
1楼#
发布于:2006-06-09 15:23
出现什么错误?另外请修改标题内容,具体发贴方式看顶贴
|
|
|
2楼#
发布于:2006-06-10 11:59
<P>就是执行不下去了 不知道为什么</P>
|
|