public int TryCeateFeatureClass(IFeatureDataSet dataset, string Name, IFieldInfoCollection fields, string[] indexField, out IFeatureClass fc) { fc = null; if (((dataset == null) || string.IsNullOrEmpty(Name)) || (fields == null)) { return(-1); } try { string[] namesByType = dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if ((namesByType != null) && (Array.IndexOf <string>(namesByType, Name) != -1)) { fc = dataset.OpenFeatureClass(Name); return(0); } fc = dataset.CreateFeatureClass(Name, fields); if (dataset == null) { return(-1); } IDbIndexInfo index = null; if (indexField != null) { foreach (string str in indexField) { try { index = new DbIndexInfoClass { Name = string.Format("Index_{0}_{1}", fc.Id, str) }; index.AppendFieldDefine(str, true); fc.AddDbIndex(index); } catch (Exception exception) { } } } return(1); } catch (Exception exception2) { return(-1); } }
private bool CreateFacClassReg(FacClass fc) { if (fc == null || fc.FacilityType == null) { return(false); } IFdeCursor cursor = null; IRowBuffer row = null; try { IFeatureDataSet fds = this._dsPipe.OpenFeatureDataset("DataSet_BIZ"); if (fds == null) { return(false); } IFeatureDataSet fdsActuality = this._dsPipe.OpenFeatureDataset("DataSet_GEO_Actuality"); if (fdsActuality == null) { return(false); } IObjectClass oc = fds.OpenObjectClass("OC_FacilityClass"); if (oc == null) { return(false); } row = oc.CreateRowBuffer(); cursor = oc.Insert(); if (row != null) { row.SetValue(row.FieldIndex("FacClassCode"), fc.Code); row.SetValue(row.FieldIndex("Name"), fc.Name); row.SetValue(row.FieldIndex("FacilityType"), fc.FacilityType.Name); row.SetValue(row.FieldIndex("LocationType"), fc.LocationType.ToString()); row.SetValue(row.FieldIndex("TurnerStyle"), fc.TurnerStyle.ToString()); row.SetValue(row.FieldIndex("Comment"), fc.Comment); string fcName = string.Format("FC_{0}_{1}", (int)DataLifeCyle.Actuality, fc.Code); List <CMFieldConfig> fieldConfig = GetFieldsConfig(fc.Code); IFieldInfoCollection fielInfoCol = CreateFieldInfoCollection(fieldConfig, fc.FacilityType.Name); IFeatureClass featureClass = fdsActuality.CreateFeatureClass(fcName, fielInfoCol); if (featureClass == null) { return(false); } featureClass.AliasName = fc.Name; featureClass.LockType = gviLockType.gviLockExclusiveSchema; IGridIndexInfo indexInfo = new GridIndexInfoClass { L1 = 500.0, L2 = 2000.0, L3 = 10000.0, GeoColumnName = "Geometry" }; featureClass.AddSpatialIndex(indexInfo); indexInfo.GeoColumnName = "Shape"; featureClass.AddSpatialIndex(indexInfo); indexInfo.GeoColumnName = "FootPrint"; featureClass.AddSpatialIndex(indexInfo); IRenderIndexInfo info2 = new RenderIndexInfoClass { L1 = 500.0, GeoColumnName = "Geometry" }; featureClass.AddRenderIndex(info2); info2.GeoColumnName = "Shape"; featureClass.AddRenderIndex(info2); info2.GeoColumnName = "FootPrint"; featureClass.AddRenderIndex(info2); featureClass.LockType = gviLockType.gviLockSharedSchema; row.SetValue(row.FieldIndex("FeatureClassId"), featureClass.Guid.ToString()); row.SetValue(row.FieldIndex("DataSetName"), "DataSet_GEO_Actuality"); row.SetValue(row.FieldIndex("FcName"), featureClass.Name); row.SetValue(row.FieldIndex("DataType"), DataLifeCyle.Actuality.ToString()); cursor.InsertRow(row); return(true); } else { return(false); } } catch (Exception ex) { WaitForm.SetCaption("创建管线库中的设施要素类【" + fc.Name + "】失败!"); return(false); } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } }
private void SyncTopoInfo() { try { IFeatureDataSet fds = this._dsPipe.OpenFeatureDataset("DataSet_BIZ"); if (fds == null) { return; } List <TopoClass> allTC = GetAllTopoClasses(); if (allTC == null || allTC.Count == 0) { return; } #region 检查删除管线库中的拓扑信息表,有就不删,没有就删除 WaitForm.SetCaption("检查管线库中的拓扑信息表..."); string[] namesByType = fds.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (namesByType == null) { return; } foreach (string str in namesByType) { if (str.ToUpper().IndexOf("TOPO_OC_") == 0) { bool flag = true; if ((allTC == null) || (allTC.Count == 0)) { flag = true; } else { foreach (TopoClass tc in allTC) { if (tc.TopoTable == str) { flag = false; break; } } } if (flag) { fds.DeleteByName(str); } } } #endregion #region 创建拓扑信息表 WaitForm.SetCaption("创建管线库中的拓扑信息表..."); foreach (TopoClass tc in allTC) { string topoTableName = tc.TopoTable; if (Array.IndexOf <string>(namesByType, topoTableName) == -1) { string[] arrDBIndex = null; IFeatureClass fc = fds.CreateFeatureClass(topoTableName, GetTopoInfoFields(out arrDBIndex)); if (fc != null) { fc.AliasName = tc.Name + "拓扑信息表"; } } } #endregion } catch (Exception ex) { XtraMessageBox.Show("同步管线库中的拓扑信息表失败!", "提示"); } }
private void createFeatureClassToolStripMenuItem_Click(object sender, EventArgs e) { FeatureClassForm fcForm = new FeatureClassForm(); if (fcForm.ShowDialog() != DialogResult.OK) { return; } IDataSource ds = null; IFeatureDataSet dset = null; IFeatureClass fc = null; try { myTreeNode node = (myTreeNode)selectNode.Parent; IConnectionInfo ci = node.con; ds = dsFactory.OpenDataSource(ci); dset = ds.OpenFeatureDataset(selectNode.Text); // 定义字段 IFieldInfoCollection fields = new FieldInfoCollection(); IFieldInfo field = new FieldInfo(); field.Name = "Name"; field.FieldType = gviFieldType.gviFieldString; field.Length = 255; fields.Add(field); field = new FieldInfo(); field.Name = "Groupid"; field.FieldType = gviFieldType.gviFieldInt32; field.RegisteredRenderIndex = true; //为支持逻辑图层树控制图层显示,需要注册渲染索引 fields.Add(field); field = new FieldInfo(); field.Name = "Geometry"; field.FieldType = gviFieldType.gviFieldGeometry; field.GeometryDef = new GeometryDef(); field.GeometryDef.GeometryColumnType = gviGeometryColumnType.gviGeometryColumnModelPoint; //模型 field.RegisteredRenderIndex = true; //为支持空间列在RenderControl中显示出来,必须注册渲染索引 fields.Add(field); fc = dset.CreateFeatureClass(fcForm.FeatureClassName, fields); //创建空间索引 IGridIndexInfo index = new GridIndexInfo(); //index.Name = fc.Guid; index.L1 = 500; index.L2 = 2000; index.L3 = 10000; index.GeoColumnName = "Geometry"; fc.AddSpatialIndex(index as IIndexInfo); IRenderIndexInfo rInfo = new RenderIndexInfo(); rInfo.GeoColumnName = "Geometry"; rInfo.L1 = 500; fc.AddRenderIndex(rInfo); // 往树上挂节点 TreeNode fcNode = new TreeNode(fcForm.FeatureClassName, 1, 1); fcNode.ContextMenuStrip = this.contextMenuStrip3; selectNode.Nodes.Add(fcNode); TreeNode fieldNode = new TreeNode("oid", 1, 1); fieldNode.ContextMenuStrip = this.contextMenuStrip4; fcNode.Nodes.Add(fieldNode); fieldNode = new TreeNode("Name", 1, 1); fieldNode.ContextMenuStrip = this.contextMenuStrip4; fcNode.Nodes.Add(fieldNode); fieldNode = new TreeNode("Groupid", 1, 1); fieldNode.ContextMenuStrip = this.contextMenuStrip4; fcNode.Nodes.Add(fieldNode); fieldNode = new TreeNode("Geometry", 1, 1); fieldNode.ContextMenuStrip = this.contextMenuStrip4; fcNode.Nodes.Add(fieldNode); } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } finally { if (ds != null) { //Marshal.ReleaseComObject(ds); ds = null; } if (dset != null) { //Marshal.ReleaseComObject(dset); dset = null; } if (fc != null) { //Marshal.ReleaseComObject(fc); fc = null; } } }
static void Main(string[] args) { //创建要素类要先定义属性字段 IFieldInfoCollection fields = new FieldInfoCollection(); { //名称列 IFieldInfo field = new FieldInfo(); field.Name = "Name"; field.FieldType = gviFieldType.gviFieldString; field.Length = 255; fields.Add(field); //空间列 field = new FieldInfo(); field.Name = "Geometry"; field.FieldType = gviFieldType.gviFieldGeometry; //列类型为空间类型 field.GeometryDef = new GeometryDef(); //需要实例化一个几何定义对象,里面有大量与空间有关的内容,比如: field.GeometryDef.HasZ = true; //是否在Z值,默认为false,只能存XY field.GeometryDef.GeometryColumnType = gviGeometryColumnType.gviGeometryColumnPoint; //空间列的几何类型 field.RegisteredRenderIndex = true; //注册渲染索引,允许在renderControl中显示 fields.Add(field); //多空间列 field = new FieldInfo(); field.Name = "Model"; field.FieldType = gviFieldType.gviFieldGeometry; //列类型为空间类型 field.GeometryDef = new GeometryDef(); //需要实例化一个几何定义对象,里面有大量与空间有关的内容,比如: field.GeometryDef.HasZ = true; //是否在Z值,默认为false,只能存XY field.GeometryDef.GeometryColumnType = gviGeometryColumnType.gviGeometryColumnModelPoint; //空间列的几何类型 field.RegisteredRenderIndex = true; //注册渲染索引,允许在renderControl中显示 fields.Add(field); //... 其它列 } //创建要素类 IFeatureClass FC = FDS.CreateFeatureClass("FC", fields); int nameID = FC.GetFields().IndexOf("Name"); //获取对应列的索引, int geomID = FC.GetFields().IndexOf("Geometry"); int fidIndex = FC.GetFields().IndexOf(FC.FidFieldName); //增加单条数据,并同步到FeatureLayer IFdeCursor fcu = FC.Insert(); //通过FC创建一个插入游标,用来操作rowBuffer IRowBuffer rb = FC.CreateRowBuffer(); //通过FC创建一条空要素实例,用来设置数据,设置完成后将其塞入FC IPoint p = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ); // 将要塞入空间列的几何对象,类型要对应 FC的field.GeometryDef.GeometryColumnType ,否则塞不进 rb.SetValue(nameID, "testPointA"); //塞名称 rb.SetValue(geomID, p); //塞几何 fcu.InsertRow(rb); //塞进FC int fid = fcu.LastInsertId; //成功后反回这条buffer的主键ID rb.SetValue(fidIndex, fid); //Cursor(FC)增加数据后会产生一个对应的FID,要把这个FID赋值给row才能在FLayer中显示 ax.FeatureManager.CreateFeature(FC, rb); //同步到renderControl //增加很大量数据时,参考以下方法 IFdeCursor cu = FC.Insert(); IRowBufferCollection rows = new RowBufferCollection(); for (int i = 0; i < 100000; i++) { IRowBuffer row = FC.CreateRowBuffer(); // do something ... row.SetValue(geomID, p); cu.InsertRow(row); row.SetValue(fidIndex, cu.LastInsertId); rows.Add(row); } ax.FeatureManager.CreateFeatures(FC, rows); //或直接整体更新 ax.FeatureManager.RefreshFeatureClass(FC); //查 string tagStr = "tagName"; IQueryFilter qf = new QueryFilter(); //过滤器 qf.WhereClause = $"Name = '{tagStr}'"; IFdeCursor res = FC.Search(qf, true); //条件查 IRowBuffer aBuffer = res.NextRow(); //遍历查询结果 //改 IFdeCursor upCu = FC.Update(qf); IRowBuffer upBuffer = upCu.NextRow(); upCu.UpdateRow(upBuffer); //删 FC.Delete(qf); FC.DeleteRow(0); FC.Truncate(); //保留表结构,清空表 }