fyl
fyl
路人甲
路人甲
  • 注册日期2004-05-12
  • 发帖数43
  • QQ
  • 铜币363枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2172回复:4

C#如何创建字段?(急急急)

楼主#
更多 发布于:2005-08-22 10:21
想新建一个shape文件,不知如何创建字段
喜欢0 评分0
fyl
fyl
路人甲
路人甲
  • 注册日期2004-05-12
  • 发帖数43
  • QQ
  • 铜币363枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2005-08-23 12:47
<P>自己顶一下</P>
举报 回复(0) 喜欢(0)     评分
wavvylia
路人甲
路人甲
  • 注册日期2003-07-28
  • 发帖数384
  • QQ
  • 铜币555枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2005-08-23 13:49
<P>俺给你个代码:</P>
<P>Public Function CreateShapefile(sPath As String, sName As String, sSpatial As ISpatialReference) As IFeatureClass  ' 名称不要加.shp后缀  <BR>   Dim pFWS As IFeatureWorkspace<BR>   Dim pWorkspaceFactory As IWorkspaceFactory<BR>   Set pWorkspaceFactory = New ShapefileWorkspaceFactory<BR>   Set pFWS = pWorkspaceFactory.OpenFromFile(sPath, 0)<BR>   <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>   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</P>
<P>   With pGeomDefEdit</P>
<P>      .GeometryType = esriGeometryPolygon<BR>      Set .SpatialReference = sSpatial ' New UnknownCoordinateSystem</P>
<P>   End With</P>
<P>   Set pFieldEdit.GeometryDef = pGeomDef<BR>   pFieldsEdit.AddField pField<BR>   <BR>   Set pField = New Field<BR>   Set pFieldEdit = pField</P>
<P>   With pFieldEdit</P>
<P>      .length = 30<BR>      .name = "MiscText"<BR>      .Type = esriFieldTypeString</P>
<P>   End With</P>
<P>   pFieldsEdit.AddField pField<BR>   <BR>   Dim pFeatClass As IFeatureClass<BR>   Set pFeatClass = pFWS.CreateFeatureClass(sName, pFields, Nothing, _<BR>      Nothing, esriFTSimple, "Shape", "")<BR>                                            <BR>   Set CreateShapefile = pFeatClass</P>
<P>End Function<BR></P>
举报 回复(0) 喜欢(0)     评分
fyl
fyl
路人甲
路人甲
  • 注册日期2004-05-12
  • 发帖数43
  • QQ
  • 铜币363枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2005-08-24 08:52
<P>可在c#中pFieldEdit pFieldsEdit等提示属性是只读的,不能赋值</P>
举报 回复(0) 喜欢(0)     评分
hjh0716
路人甲
路人甲
  • 注册日期2006-09-01
  • 发帖数2
  • QQ
  • 铜币105枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2006-10-10 09:13
<P>IFieldEdit pField=new FieldClass();</P>
<P>           </P>
<P>             <BR>   pField.Name_2 ="hjh";<BR>   pField.Type_2  = esriFieldType.esriFieldTypeString;<BR>   pField.Length_2  = 50;<BR>   pTable.AddField(pField);</P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部