Esempio n. 1
0
        /// <summary>
        /// Gets all the fields from the object's type with specified attribute
        /// </summary>
        public static FieldInfoCollection GetFieldsWithAttribute(Type type, Type attribute)
        {
            var fields = new FieldInfoCollection();

            foreach (FieldInfo field in type.GetFields())
            {
                if (field.GetCustomAttributes(attribute, true).Length > 0)
                {
                    fields.Add(field);
                }
            }
            return(fields);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets all the fields WITHOUT ANY of the specified attributes.
        /// </summary>
        public static FieldInfoCollection GetFieldsWithOutAttributes(Type type, params Type[] types)
        {
            var fields = new FieldInfoCollection();

            bool match;

            foreach (FieldInfo field in type.GetFields())
            {
                match = true;
                foreach (Type attType in types)
                {
                    if (field.GetCustomAttributes(attType, true).Length != 0)
                    {
                        match = false;
                    }
                }
                if (match)
                {
                    fields.Add(field);
                }
            }

            return(fields);
        }
Esempio n. 3
0
        private IFieldInfoCollection CreateFieldInfoCollection(List <CMFieldConfig> list, string facType)
        {
            if (list == null)
            {
                return(null);
            }
            IFieldInfoCollection infos = new FieldInfoCollection();

            IFieldInfo newVal = null;

            foreach (CMFieldConfig cmfc in list)
            {
                newVal           = new FieldInfoClass();
                newVal.Name      = cmfc.Name;
                newVal.Alias     = cmfc.Alias;
                newVal.FieldType = cmfc.FieldType;
                newVal.Nullable  = cmfc.Nullable;
                if (newVal.FieldType == gviFieldType.gviFieldString)
                {
                    newVal.Length = cmfc.Length;
                }
                if (infos.IndexOf(newVal.Name) == -1)
                {
                    infos.Add(newVal);
                }
                if (cmfc.SystemName == "Diameter")
                {
                    newVal = new FieldInfoClass
                    {
                        Name      = cmfc.Name + "1",
                        Alias     = "横截面宽",
                        FieldType = gviFieldType.gviFieldDouble
                    };
                    if (infos.IndexOf(newVal.Name) == -1)
                    {
                        infos.Add(newVal);
                    }
                    newVal = new FieldInfoClass
                    {
                        Name      = cmfc.Name + "2",
                        Alias     = "横截面高",
                        FieldType = gviFieldType.gviFieldDouble
                    };
                    if (infos.IndexOf(newVal.Name) == -1)
                    {
                        infos.Add(newVal);
                    }
                }
            }
            newVal = new FieldInfoClass
            {
                Name      = "FacilityId",
                Alias     = "设施编号",
                FieldType = gviFieldType.gviFieldString,
                Length    = 50
            };
            infos.Add(newVal);
            newVal = new FieldInfoClass
            {
                Name                  = "GroupId",
                Alias                 = "逻辑组ID",
                FieldType             = gviFieldType.gviFieldInt32,
                RegisteredRenderIndex = true
            };
            infos.Add(newVal);
            newVal = new FieldInfoClass
            {
                Name      = "StyleId",
                Alias     = "风格编号",
                FieldType = gviFieldType.gviFieldString,
                Length    = 50
            };
            infos.Add(newVal);
            newVal = new FieldInfoClass
            {
                Name      = "ModelName",
                Alias     = "模型名称",
                FieldType = gviFieldType.gviFieldString,
                Length    = 80
            };
            infos.Add(newVal);
            newVal = new FieldInfoClass
            {
                Name      = "Metadata",
                Alias     = "Metadata",
                FieldType = gviFieldType.gviFieldBlob
            };
            infos.Add(newVal);
            newVal = new FieldInfoClass
            {
                Name  = "Geometry",
                Alias = "三维空间列",
                RegisteredRenderIndex = true,
                FieldType             = gviFieldType.gviFieldGeometry
            };
            IGeometryDef def = new GeometryDefClass
            {
                GeometryColumnType = gviGeometryColumnType.gviGeometryColumnModelPoint,
                HasZ = true
            };

            newVal.GeometryDef = def;
            infos.Add(newVal);
            newVal = new FieldInfoClass
            {
                Name  = "Shape",
                Alias = "二维空间列",
                RegisteredRenderIndex = true,
                FieldType             = gviFieldType.gviFieldGeometry
            };
            gviGeometryColumnType gviGeometryColumnUnknown = gviGeometryColumnType.gviGeometryColumnUnknown;

            switch (facType)
            {
            case "PipeNode":
                gviGeometryColumnUnknown = gviGeometryColumnType.gviGeometryColumnPoint;
                break;

            case "PipeLine":
                gviGeometryColumnUnknown = gviGeometryColumnType.gviGeometryColumnPolyline;
                break;

            case "PipeBuild":
                gviGeometryColumnUnknown = gviGeometryColumnType.gviGeometryColumnPolygon;
                break;

            case "PipeBuild1":
                gviGeometryColumnUnknown = gviGeometryColumnType.gviGeometryColumnPolyline;
                break;
            }
            IGeometryDef def2 = new GeometryDefClass
            {
                GeometryColumnType = gviGeometryColumnUnknown,
                HasZ = true
            };

            newVal.GeometryDef = def2;
            infos.Add(newVal);
            newVal = new FieldInfoClass
            {
                Name  = "FootPrint",
                Alias = "投影二维",
                RegisteredRenderIndex = true,
                FieldType             = gviFieldType.gviFieldGeometry
            };
            IGeometryDef def3 = new GeometryDefClass
            {
                GeometryColumnType = gviGeometryColumnUnknown,
                HasZ = false
            };

            newVal.GeometryDef = def3;
            infos.Add(newVal);
            return(infos);
        }
Esempio n. 4
0
        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;
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 创建普通表
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        public bool CreateLogicTreeTable(IDataSource ds)
        {
            IFieldInfoCollection fields = new FieldInfoCollection();
            IFieldInfo           field  = new FieldInfo();

            try
            {
                if (ds != null)
                {
                    field.Name      = "id";
                    field.FieldType = gviFieldType.gviFieldFID;
                    field.Nullable  = false;
                    fields.Add(field);

                    field           = new FieldInfo();
                    field.Name      = "groupid";
                    field.FieldType = gviFieldType.gviFieldString;
                    field.Length    = 255;
                    field.Nullable  = false;
                    fields.Add(field);

                    field           = new FieldInfo();
                    field.Name      = "name";
                    field.FieldType = gviFieldType.gviFieldString;
                    field.Length    = 255;
                    field.Nullable  = false;
                    fields.Add(field);

                    field           = new FieldInfo();
                    field.Name      = "founder";
                    field.FieldType = gviFieldType.gviFieldString;
                    field.Length    = 255;
                    fields.Add(field);

                    field           = new FieldInfo();
                    field.Name      = "content";
                    field.FieldType = gviFieldType.gviFieldBlob;
                    field.Nullable  = false;
                    fields.Add(field);
                    ds.CreateTable("cm_logictree", "id", fields);

                    fields.Clear();
                    field           = new FieldInfo();
                    field.Name      = "id";
                    field.FieldType = gviFieldType.gviFieldFID;
                    field.Nullable  = false;
                    fields.Add(field);

                    field           = new FieldInfo();
                    field.Name      = "groupuid";
                    field.FieldType = gviFieldType.gviFieldString;
                    field.Length    = 255;
                    field.Nullable  = false;
                    fields.Add(field);

                    field           = new FieldInfo();
                    field.Name      = "DataSet";
                    field.FieldType = gviFieldType.gviFieldString;
                    field.Length    = 255;
                    field.Nullable  = false;
                    fields.Add(field);
                    ds.CreateTable("cm_group", "id", fields);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (COMException comEx)
            {
                System.Diagnostics.Trace.WriteLine(comEx.Message);
                return(false);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return(false);
            }
            finally
            {
                //Marshal.ReleaseComObject(field);
                field = null;
                //Marshal.ReleaseComObject(fields);
                fields = null;
            }
        }
Esempio n. 6
0
        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();          //保留表结构,清空表
        }