zhanghuibo2000
路人甲
路人甲
  • 注册日期2012-10-31
  • 发帖数1
  • QQ
  • 铜币106枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1448回复:1

[求助] arcgisserver9.3外部数据关联表后原有的单值专题图不显示了?

楼主#
更多 发布于:2012-10-31 09:36
<font face="Verdana">
<p>目地是做外部数据关联专题图,做图层表和数据库中一表进行关联后,原有的图层信息都查不到了 原有的单位专题图也没有了 跟踪调试发现是两表联合后原图层表的列名变了</p>
<p>原因是:area的列变成了 "图层名.area"  请问各位有什么办法?代码如下:<br/>            DataTable dt0 = this.MyConvertITable(primaryClass as ITable);//查看图层信息</p>
<p>            //读取文件数据<br/>            //IWorkspaceFactory pFact = (IWorkspaceFactory)serverContext.CreateObject("esriDataSourcesOleDB.TextFileWorkspaceFactory");<br/>            //IFeatureWorkspace pFeatws = pFact.OpenFromFile("D:\\test", 0) as IFeatureWorkspace;<br/>            //ITable pTable = pFeatws.OpenTable("9.txt");</p>
<p>            //DataTable dt3 = hys.MyConvertITable(pTable);</p>
<p><br/>            //进行关联<br/>            IMemoryRelationshipClassFactory memoryRelClassFactory = pServerContext.CreateObject("esriGeodatabase.MemoryRelationshipClassFactory") as IMemoryRelationshipClassFactory;<br/>            //如果是从文件读取<br/>            //IRelationshipClass relationshipClass = memoryRelClassFactory.Open("test", (IObjectClass)primaryClass, "OBJECTID", (IObjectClass)pTable, "OBJECTID", "forward", "backward", esriRelCardinality.esriRelCardinalityOneToOne);<br/>            //如果是从sql server读取<br/>            IRelationshipClass relationshipClass = memoryRelClassFactory.Open("test", (IObjectClass)primaryClass, "farm_code", (IObjectClass)ittemp, "farm_code", "forward", "backward", ESRI.ArcGIS.Geodatabase.esriRelCardinality.esriRelCardinalityOneToOne);<br/>            //IRelationshipClass relationshipClass = memoryRelClassFactory.Open("test", (IObjectClass)ittemp, "farm_code", (IObjectClass)primaryClass, "farm_code", "forward", "backward", ESRI.ArcGIS.Geodatabase.esriRelCardinality.esriRelCardinalityOneToMany);</p>
<p><br/>            //得到关联表<br/>            IRelQueryTableFactory iRelQryTabFactory = pServerContext.CreateObject("esriGeodatabase.RelQueryTableFactory") as IRelQueryTableFactory;</p>
<p>            ITable iRelQueryTable = iRelQryTabFactory.Open(relationshipClass, true, null, null, "a", true, true) as ITable;</p>
<p> </p>
<p> </p>
<p>            <font color="#ff0000">DataTable dt2 = this.MyConvertITable(iRelQueryTable);这块的原图层列名变成了“图层名.列名”导致原图层查不到信息 原有的专题图也没了</font></p>
<p>            featureLyer.FeatureClass = (IFeatureClass)iRelQueryTable;</p>
<p> </p>
<p> </p>
<p>后来我又试了在原图层表上加列的办法 代码如下:但红字地方出错 不知为何?</p>
<p><font face="Verdana"> IGeoFeatureLayer pGeoFeatureLyer = layer as IGeoFeatureLayer;<br/>        #region 添加字段</font></p>
<p><font face="Verdana">        bool havefield = false;</font></p>
<p><font face="Verdana">        IFields Ifields = pGeoFeatureLyer.FeatureClass.Fields as IFields;<br/>        IFieldsEdit fieldsEdit = (IFieldsEdit)Ifields;</font></p>
<p><font face="Verdana">        for (int col = 0; col < fields.Length; col++)//遍历要添加的字段是否与现在的字段重复<br/>        {</font></p>
<p><font face="Verdana">            for (int j = 0; j < Ifields.FieldCount; j++)<br/>            {</font></p>
<p><font face="Verdana">                if (fields[col] == Ifields.get_Field(j).Name)</font></p>
<p><font face="Verdana">                    havefield = true;</font></p>
<p><font face="Verdana">            }</font></p>
<p><font face="Verdana">            if (!havefield)<br/>            {</font></p>
<p><font face="Verdana">                IField oField = (IField)pServerContext.CreateObject("esriGeodatabase.Field");</font></p>
<p><font face="Verdana">                IFieldEdit oFieldEdit = oField as IFieldEdit;</font></p>
<p><font face="Verdana">                oFieldEdit.Name_2 = fields[col];</font></p>
<p><font face="Verdana">                oFieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDouble;<br/>                </font></p>
<p><font face="Verdana">               // pGeoFeatureLyer.FeatureClass.AddField(oField);<br/>                fieldsEdit.AddField(oField);</font></p>
<p><font face="Verdana"></font> </p>
<p><font face="Verdana">            }</font></p>
<p><font face="Verdana">            havefield = false;</font></p>
<p><font face="Verdana">        }</font></p>
<p><font face="Verdana">        #endregion<br/>        #region 设置数值</font></p>
<p><font face="Verdana">        ESRI.ArcGIS.Geodatabase.IQueryFilter2 queryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();</font></p>
<p><font face="Verdana">        //queryFilter.WhereClause = "PID in (" + sitePID + ")";</font></p>
<p><font face="Verdana">        for (int i = 0; i < pGeoFeatureLyer.FeatureClass.FeatureCount(queryFilter); i++)<br/>        {</font></p>
<p><font face="Verdana">            IFeature ifeature = pGeoFeatureLyer.FeatureClass.GetFeature(i);</font></p>
<p><font face="Verdana">            int pidindex = ifeature.Fields.FindField("farm_code");</font></p>
<p><font face="Verdana">           <br/>           <br/>                for (int col = 0; col < fields.Length; col++)<br/>                {</font></p>
<p><font face="Verdana">                    pidindex = ifeature.Fields.FindField(fields[col]);</font></p>
<p><font face="Verdana">                   // DataRow dr = dt.Select(" Station='" + siteen.Station + "' and Field='" + fields[col] + "'")[0];</font></p>
<p><font face="Verdana">                    ifeature.set_Value(pidindex, null);</font></p>
<p><font face="Verdana">                  <font color="#ff0000">  ifeature.Store();出错了 不知为什么</font><br/>                    </font></p>
<p><font face="Verdana">                }</font></p>
<p><font face="Verdana">            </font></p>
<p><font face="Verdana">        }<br/></font></p>
<p><br/> </p></font>
喜欢0 评分0
游客

返回顶部