st_pjc
路人甲
路人甲
  • 注册日期2005-03-10
  • 发帖数11
  • QQ
  • 铜币156枚
  • 威望0点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
阅读:1477回复:0

[求助]create feature class 问题

楼主#
更多 发布于:2005-09-19 11:21
<P>Public Function CreateShapefile(mstrFolder As String, mstrName As String, strNewField As String, _<BR>pFeatCl As IFeatureClass, geotype As Integer) As IFeatureClass<BR><BR>Dim pFC As IFeatureClass 'used for spatialreference inherit<BR>Set pFC = pFeatCl<BR>Dim strFolder As String ' "D:\Data"<BR>strFolder = Left(mstrFolder, Len(mstrFolder) - 1)<BR>Dim strName As String ' "MyShapeFile" Dont include .shp extension<BR>mstrName = Trim(mstrName)<BR>strName = Left(mstrName, Len(mstrName) - 4)<BR>Const strShapeFieldName As String = "Shape"<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>Set pFWS = pWorkspaceFactory.OpenFromFile(strFolder, 0)<BR><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 = strShapeFieldName<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 = geotype 'esriGeometryPolygon<BR>Set .SpatialReference = New UnknownCoordinateSystem 'GetSpatialReference (pFC) '<BR>End With<BR>Set pFieldEdit.GeometryDef = pGeomDef<BR>pFieldsEdit.AddField pField<BR><BR>' Add another miscellaneous text field<BR>Set pField = New Field<BR>Set pFieldEdit = pField<BR>With pFieldEdit<BR>.Length = 20<BR>.Name = strNewField<BR>.Type = esriFieldTypeDouble<BR>End With<BR>pFieldsEdit.AddField pField<BR><BR>' Create the shapefile<BR>Set CreateShapefile = pFWS.CreateFeatureClass(strName, pFields, _<BR>Nothing, Nothing, esriFTSimple, strShapeFieldName, "")<BR><BR><BR>End Function<BR><BR>大家帮看看,VB+engine,arc9.0<BR>怎么上段代码在arcmap VBA中能通过,但在VB中不能够。<BR>两个地方有问题:<BR>1> Set .SpatialReference = New UnknownCoordinateSystem 'GetSpatialReference (pFC)<BR>在vb中如果改为Set .SpatialReference = GetSpatialReference (pFC)<BR>就提示出错,在vba中是可以的。vb中添加引用文件esriGeoprocessing,esriGeometry后,依然提示出错。<BR>2> Set CreateShapefile = pFWS.CreateFeatureClass(strName, pFields, _<BR>Nothing, Nothing, esriFTSimple, strShapeFieldName, "")<BR>运行到这里就不动了。不懂,望赐教<BR></P>
喜欢0 评分0
游客

返回顶部