阅读:1998回复:4
在创建FeatureClass时遇到的问题
<P>RT:大家先看代码(VB</P>
<P>LayerName = pFeatureLayer.Name;</P> <P>Set pOutWorkspaceFactory = New ShapefileWorkspaceFactory<BR> Set pOutFeatureWorkspace = pOutWorkspaceFactory.OpenFromFile(pPath, 0)<BR> Set pFeatureClass = pOutFeatureWorkspace.CreateFeatureClass(LayerName, pFeaturelayer.FeatureClass.Fields, _<BR> pFeaturelayer.FeatureClass.CLSID, _<BR> pFeaturelayer.FeatureClass.EXTCLSID, _<BR> pFeaturelayer.FeatureClass.FeatureType, _<BR> pFeaturelayer.FeatureClass.ShapeFieldName, "")</P> <P>使用上面的代码创建FeatureClass的时候,对于少数的pFeatureLayer回出现系统错误现象,正个VB都被关闭了,有没有人遇到类似的问题,请高手请教,这里谢谢了先.</P> |
|
|
1楼#
发布于:2005-07-14 13:46
<P>我用的这个,没什么错误啊,应该和你的一样的</P>
<P>Public Function CreateShapefile(strFolder As String, strName As String, _<BR> geomType As esriGeometryType) As esriGeoDatabase.IFeatureClass</P> <P>'' 在目录里建立一个shp图层.<BR>'' 注意: shapefile的名字不包括 .shp 扩展名<BR>'' 作者:gisempire :)'' 修改时间 </P> <P> Const strShapeFieldName As String = "Shape"</P> <P> On Error GoTo EH<BR> Set CreateShapefile = Nothing<BR> If strFolder = "" Then Exit Function</P> <P> ' Open the folder to contain the shapefile as a workspace<BR> Dim pFWS As esriGeoDatabase.IFeatureWorkspace<BR> Dim pWorkspaceFactory As esriGeoDatabase.IWorkspaceFactory<BR> Set pWorkspaceFactory = New esriDataSourcesFile.ShapefileWorkspaceFactory<BR> Set pFWS = pWorkspaceFactory.OpenFromFile(strFolder, 0)</P> <P> ' Set up a simple fields collection<BR> Dim pFields As esriGeoDatabase.IFields<BR> Dim pFieldsEdit As esriGeoDatabase.IFieldsEdit<BR> Set pFields = New esriGeoDatabase.Fields<BR> Set pFieldsEdit = pFields</P> <P> Dim pField As esriGeoDatabase.IField<BR> Dim pFieldEdit As esriGeoDatabase.IFieldEdit</P> <P> ' Make the shape field<BR> ' it will need a geometry definition, with a spatial reference<BR> Set pField = New esriGeoDatabase.Field<BR> Set pFieldEdit = pField<BR> pFieldEdit.Name = strShapeFieldName<BR> pFieldEdit.Type = esriFieldTypeGeometry</P> <P> Dim pGeomDef As esriGeoDatabase.IGeometryDef<BR> Dim pGeomDefEdit As esriGeoDatabase.IGeometryDefEdit<BR> Set pGeomDef = New esriGeoDatabase.GeometryDef<BR> Set pGeomDefEdit = pGeomDef<BR> With pGeomDefEdit<BR> .GeometryType = geomType<BR> Set .SpatialReference = New esriGeometry.UnknownCoordinateSystem<BR> End With<BR> Set pFieldEdit.GeometryDef = pGeomDef<BR> pFieldsEdit.AddField pField</P> <P> ' Create the shapefile<BR> ' (some parameters apply to geodatabase options and can be defaulted as Nothing)</P> <P> Set CreateShapefile = pFWS.CreateFeatureClass(strName, pFields, Nothing, _<BR> Nothing, esriFTSimple, strShapeFieldName, "")<BR> Exit Function<BR>EH:<BR> MsgBox Err.Description, vbInformation, "createShapefile"<BR>End Function</P> |
|
|
2楼#
发布于:2005-07-14 16:48
<P>谢谢楼上的,不过还有一个要问问就是pFWS.CreateFeatureClass(strName, pFields, Nothing, _<BR> Nothing, esriFTSimple, strShapeFieldName, "")<BR>中的两个Nothing参数,代表什么意思,不付值也可以的啊</P>
|
|
|
3楼#
发布于:2005-07-15 10:11
<P>帮助里是这样解释的</P>
<P>The optional <STRONG>CLSID</STRONG> parameter is used to specify what GUID to use to instantiate the object representing a feature in that <STRONG>FeatureClass</STRONG>. If "Nothing" is passed in for the CLSID, the GeoDatabase will use the CLSID corresponding to <STRONG>esriGeoDatabase.Feature</STRONG>. This is OK in most instances. If you know the FeatureClass has a custom Feature other than esriGeoDatabase.Feature, you can pass in it's GUID at this time or later call methods on the FeatureClass's <STRONG><a href="mk:@MSITStore:C:\Program%20Files\ArcGIS\DeveloperKit\Help\COM\VB\esriGeoDatabase.chm::/IClassSchemaEdit.htm" target="_blank" >IClassSchemaEdit</A></STRONG> interface.</P> <P>The optional <STRONG>EXTCLSID</STRONG> parameter specifies the GUID to use to instantiate the object representing the <STRONG>FeatureClassExtension</STRONG>. This object must at least support the <STRONG><a href="mk:@MSITStore:C:\Program%20Files\ArcGIS\DeveloperKit\Help\COM\VB\esriGeoDatabase.chm::/IClassExtension.htm" target="_blank" >IClassExtension</A></STRONG> interface. If you pass in "Nothing" for the EXTCLSID, the newly created FeatureClass will not have a ClassExtension. Since ClassExtensions are not required, this is generally OK, unless the FeatureClass is for <STRONG>annotation</STRONG>, <STRONG>dimension lines</STRONG> or a custom FeatureClass that requires a ClassExtension. If you know the FeatureClass has a ClassExtension and you know the GUID for the ClassExtension, you can pass it in at this time or later call methods on the FeatureClass's <STRONG><a href="mk:@MSITStore:C:\Program%20Files\ArcGIS\DeveloperKit\Help\COM\VB\esriGeoDatabase.chm::/IClassSchemaEdit.htm" target="_blank" >IClassSchemaEdit</A></STRONG> interface.</P> |
|
|
4楼#
发布于:2008-03-18 22:20
<P>竟然搜到一个这么老的帖子,我刚也在写这个,就是不知道ShapeFieldName 什么意思 Help里解释的也不是很清楚</P>
<P>是字段名吗?我把strShapeFieldName的值改成"test",可生成的Shapefile属性里字段名还是Shape 不知道什么原因?</P> |
|
|