阅读:2057回复:4
如何通过sdeworkspacefactory新建featureclass
<P>怎么样用ae实现在sde数据库中新建一个featureclass呢?或者说新建一个shapefile然后把它用程序导入到sde数据库中?下面是我的代码,但是有错误,请大家帮忙看一下</P>
<P><BR> IFeatureWorkspace pFWS;<BR> IWorkspaceFactory pWorkspaceFactory;<BR> pWorkspaceFactory=new SdeWorkspaceFactoryClass ();<BR> IPropertySet pPropSet = new PropertySetClass();<BR> pPropSet.SetProperty("SERVER", "ARCGIS");<BR> //pPropSet.SetProperty("INSTANCE", Instance);<BR> pPropSet.SetProperty("DATABASE", "sde");<BR> pPropSet.SetProperty("USER", "sde");<BR> pPropSet.SetProperty("PASSWORD", "sde");<BR> pPropSet.SetProperty("VERSION", "sde.DEFAULT");<BR> pFWS=(IFeatureWorkspace)pWorkspaceFactory1.Open (pPropSet,0); <BR> IFields pFields;<BR> IFieldsEdit pFieldsEdit;<BR> pFields=new FieldsClass ();<BR> pFieldsEdit=(IFieldsEdit)pFields;<BR> IField pField;<BR> IFieldEdit pFieldEdit;<BR> pField=new FieldClass ();<BR> pFieldEdit=(IFieldEdit)pField;<BR> pFieldEdit.Name_2 ="Shape";<BR> MessageBox.Show (pFieldEdit.Name.ToString ());// ="Shape";<BR> pFieldEdit.Type_2 =ESRI.ArcGIS .Geodatabase .esriFieldType .esriFieldTypeGeometry ;<BR> IGeometryDef pGeomDef;<BR> IGeometryDefEdit pGeomDefEdit;<BR> pGeomDef=new GeometryDefClass ();<BR> pGeomDefEdit=(IGeometryDefEdit)pGeomDef;<BR> if(sType=="polygon")<BR> {<BR> pGeomDefEdit.GeometryType_2 =ESRI.ArcGIS.Geometry .esriGeometryType .esriGeometryPolygon ;<BR> }<BR> else if(sType=="point")<BR> {<BR> pGeomDefEdit.GeometryType_2 =ESRI.ArcGIS.Geometry .esriGeometryType.esriGeometryPoint ;<BR> }<BR> else if(sType=="line")<BR> {<BR> pGeomDefEdit.GeometryType_2 =ESRI.ArcGIS.Geometry .esriGeometryType.esriGeometryPolyline ;<BR> }<BR> pGeomDefEdit.SpatialReference_2 =new UnknownCoordinateSystemClass ();<BR> pFieldEdit.GeometryDef_2 =pGeomDef;<BR> pFieldsEdit.AddField (pField);<BR> IField pField1;<BR> pField1=new FieldClass ();<BR> IFieldEdit pFieldEdit1;<BR> pFieldEdit1=(IFieldEdit)pField1;<BR> pFieldEdit1.Length_2 =30;<BR> pFieldEdit1.Name_2 ="MiscText";<BR> pFieldEdit1.Type_2 =ESRI.ArcGIS .Geodatabase .esriFieldType .esriFieldTypeString ;<BR> pFieldsEdit.AddField(pField1);<BR> IFeatureClass pFeatClass;<BR> try<BR> {<BR> pFeatClass=pFWS.CreateFeatureClass (sName,pFields,null,null,ESRI.ArcGIS .Geodatabase .esriFeatureType .esriFTSimple,"Shape","");<BR> <BR> }<BR> catch(Exception t)<BR> {<BR> MessageBox.Show (t.Message );<BR> }</P> <P>错误提示为:</P> <P>DBMS table not found[Microsoft OLE DB Provider for SQL Server:Deferred prepare could not be completed.对象名'sde.sde.GDB_NetDatasets'无效。][sde.sde.GDB_NetDatasets][STATE_ID=7455]</P> |
|
1楼#
发布于:2006-10-17 11:24
数据库版本注册了吗?
|
|
|
2楼#
发布于:2006-10-17 15:30
<P>谢谢老大的回复!!!</P>
<P>恕我愚钝,我没怎么明白您的意思!</P> |
|
3楼#
发布于:2006-10-17 15:51
哦,注册了。在数据库的SDE.versions表中已经含有DEFAULT行,它的state_id为0
|
|
4楼#
发布于:2006-11-07 09:28
<P>gis老大,我的代码也和上面的一样,我的数据库也注册了,但是提示:</P>
<P>HRESULT ERROR: 0x8004021 </P> |
|
|