Example #1
0
        protected override void OnClick()
        {
            string       tablePath   = Path.Combine(DataPath, @"Geodatabase\ManhattanKS.gdb\ParcelIDs");
            string       tableName   = Path.GetFileName(tablePath);
            const string searchField = "PID";

            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = Activator.CreateInstance(factoryType) as IWorkspaceFactory;
            IWorkspace        workspace        = workspaceFactory.OpenFromFile(Path.GetDirectoryName(tablePath), 0);

            IObjectClassDescription objClassDesc = new ObjectClassDescriptionClass();

            IFields     fields     = objClassDesc.RequiredFields;
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

            IField     field     = new FieldClass();
            IFieldEdit fieldEdit = (IFieldEdit)field;

            fieldEdit.Name_2       = searchField;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit.IsNullable_2 = true;
            fieldEdit.AliasName_2  = searchField;
            fieldEdit.Editable_2   = true;
            fieldEdit.Length_2     = 250;

            fieldsEdit.AddField(field);
            fields = fieldsEdit;

            ITable table = CreateTable((IWorkspace2)workspace, tableName, fields);

            using (ComReleaser releaser = new ComReleaser())
            {
                ICursor cursor = table.Insert(true);
                releaser.ManageLifetime(cursor);

                string txtPath          = Path.Combine(DataPath, "UniqueValues.txt");
                int    searchFieldIndex = table.FindField(searchField);

                IRowBuffer buffer = table.CreateRowBuffer();

                using (StreamReader reader = new StreamReader(txtPath))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        string id = line.Split(new[] { '.', ' ' }, StringSplitOptions.RemoveEmptyEntries)[1];
                        buffer.Value[searchFieldIndex] = id;
                        cursor.InsertRow(buffer);
                    }

                    cursor.Flush();
                }
            }

            ((ITableCollection)ArcMap.Document.FocusMap).AddTable(table);
            ArcMap.Document.UpdateContents();
            Marshal.FinalReleaseComObject(table);
        }
        protected override void OnClick()
        {
            string tablePath = Path.Combine(DataPath, @"Geodatabase\ManhattanKS.gdb\ParcelIDs");
            string tableName = Path.GetFileName(tablePath);
            const string searchField = "PID";

            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = Activator.CreateInstance(factoryType) as IWorkspaceFactory;
            IWorkspace workspace = workspaceFactory.OpenFromFile(Path.GetDirectoryName(tablePath), 0);

            IObjectClassDescription objClassDesc = new ObjectClassDescriptionClass();

            IFields fields = objClassDesc.RequiredFields;
            IFieldsEdit fieldsEdit = (IFieldsEdit) fields;

            IField field = new FieldClass();
            IFieldEdit fieldEdit = (IFieldEdit) field;

            fieldEdit.Name_2 = searchField;
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            fieldEdit.IsNullable_2 = true;
            fieldEdit.AliasName_2 = searchField;
            fieldEdit.Editable_2 = true;
            fieldEdit.Length_2 = 250;

            fieldsEdit.AddField(field);
            fields = fieldsEdit;

            ITable table = CreateTable((IWorkspace2) workspace, tableName, fields);

            using (ComReleaser releaser = new ComReleaser())
            {
                ICursor cursor = table.Insert(true);
                releaser.ManageLifetime(cursor);

                string txtPath = Path.Combine(DataPath, "UniqueValues.txt");
                int searchFieldIndex = table.FindField(searchField);

                IRowBuffer buffer = table.CreateRowBuffer();

                using (StreamReader reader = new StreamReader(txtPath))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        string id = line.Split(new[] {'.', ' '}, StringSplitOptions.RemoveEmptyEntries)[1];
                        buffer.Value[searchFieldIndex] = id;
                        cursor.InsertRow(buffer);
                    }

                    cursor.Flush();
                }
            }

            ((ITableCollection) ArcMap.Document.FocusMap).AddTable(table);
            ArcMap.Document.UpdateContents();
            Marshal.FinalReleaseComObject(table);
        }
Example #3
0
        /// <summary>
        /// 创建属性表
        /// </summary>
        /// <param name="pFeatureWorkspace"></param>
        /// <param name="tableStructureNode"></param>
        /// <param name="featureCodeNode"></param>
        /// <returns></returns>
        private TableLayer CreateTableLayer(IFeatureWorkspace pFeatureWorkspace, TableStructureNode tableStructureNode, FeatureCodeNode featureCodeNode)
        {
            try
            {
                if (pFeatureWorkspace != null&&tableStructureNode!=null&&featureCodeNode!=null)
                {
                    IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();
                    ///创建数据表字段
                    IFieldChecker fieldChecker = new FieldCheckerClass();
                    IFields validatedFields = CreateFileds(tableStructureNode, featureCodeNode);
                    ///字段信息验证
                    IFields fixFields = null;
                    fieldChecker.ValidateWorkspace = pFeatureWorkspace as IWorkspace;
                    IEnumFieldError enumFieldError = null;
                    fieldChecker.Validate(validatedFields, out enumFieldError, out fixFields);

                    ITable pTable = pFeatureWorkspace.CreateTable(tableStructureNode.TableName, fixFields,
                        ocDescription.InstanceCLSID, null, "");
                    if (pTable != null)
                    {
                        TableLayer pTableLayer = new TableLayer();

                        //从配置文件读取图形类型
                        string sGeometryType = "";
                        Metadata.MetaTable pMetaTalbe = Metadata.MetaDataFile.MetaTabls[tableStructureNode.TableName] as Metadata.MetaTable;
                        if (pMetaTalbe != null)
                        {
                            sGeometryType = pMetaTalbe.Type;
                        }
                        else
                            return null;

                        pTableLayer.GeometryType = sGeometryType;
                        pTableLayer.Table = pTable;
                        pTableLayer.UpdateFieldIndex();
                        return pTableLayer;
                    }
                    return null;
                }
                return null;
            }
            catch (Exception ex)
            {
                Logger.WriteErrorLog(ex);
                return null;
            }
        }
Example #4
0
        private void CreateDomainTable()
        {
            if (_workspace == null)
            {
                Connect();
            }

            IFieldsEdit fieldsEdit = new FieldsClass();
            IField      pField     = FieldHelper.CreateOIDField();

            fieldsEdit.AddField(pField);

            IFieldEdit pFieldEdit = new FieldClass();

            pFieldEdit.Name_2       = "DomainName";
            pFieldEdit.Length_2     = 255;
            pFieldEdit.AliasName_2  = "字典名称";
            pFieldEdit.IsNullable_2 = false;
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(pFieldEdit);

            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "DomainDescription";
            pFieldEdit.Length_2     = 255;
            pFieldEdit.AliasName_2  = "字典说明";
            pFieldEdit.IsNullable_2 = false;
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(pFieldEdit);

            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "DomainValues";
            pFieldEdit.Length_2     = 2147483647;
            pFieldEdit.AliasName_2  = "别名";
            pFieldEdit.IsNullable_2 = true;
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(pFieldEdit);



            IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();

            _workspace.CreateTable("YT_TEMPLATE_DOMAIN", (IFields)fieldsEdit, ocDescription.InstanceCLSID, null,
                                   "");

            return;
        }
Example #5
0
        public ITable CreateTable(IWorkspace2 workspace, string tableName, IFields fields)
        {
            ITable table;
            UID    uid = new UIDClass();

            if (workspace != null)
            {
                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
                if (!workspace.NameExists[esriDatasetType.esriDTTable, tableName])
                {
                    uid.Value = "esriGeoDatabase.Object";
                    IObjectClassDescription objectClassDescription = new ObjectClassDescriptionClass();
                    if (fields == null)
                    {
                        fields = objectClassDescription.RequiredFields;
                        IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
                        IField      field      = new FieldClass();
                        IFieldEdit  fieldEdit  = (IFieldEdit)field;
                        fieldEdit.Name_2         = "SampleField";
                        fieldEdit.Type_2         = esriFieldType.esriFieldTypeString;
                        fieldEdit.IsNullable_2   = true;
                        fieldEdit.AliasName_2    = "Sample Field Column";
                        fieldEdit.DefaultValue_2 = "test";
                        fieldEdit.Editable_2     = true;
                        fieldEdit.Length_2       = 100;
                        fieldsEdit.AddField(field);
                        fields = fieldsEdit;
                    }
                    IFieldChecker   fieldChecker    = new FieldCheckerClass();
                    IEnumFieldError enumFieldError  = null;
                    IFields         validatedFields = null;
                    fieldChecker.ValidateWorkspace = (IWorkspace)workspace;
                    fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
                    table = featureWorkspace.CreateTable(tableName, validatedFields, uid, null, "");
                }
                else
                {
                    table = featureWorkspace.OpenTable(tableName);
                }
            }
            else
            {
                table = null;
            }
            return(table);
        }
Example #6
0
        private void CreateDatasetTable()
        {
            if (_workspace == null)
            {
                Connect();
            }

            IFieldsEdit fieldsEdit = new FieldsClass();
            IField      pField     = FieldHelper.CreateOIDField();

            fieldsEdit.AddField(pField);

            IFieldEdit pFieldEdit = new FieldClass();

            pFieldEdit.Name_2       = "Dataset";
            pFieldEdit.Length_2     = 255;
            pFieldEdit.AliasName_2  = "数据集名称";
            pFieldEdit.IsNullable_2 = false;
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(pFieldEdit);

            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "BaseName";
            pFieldEdit.Length_2     = 255;
            pFieldEdit.AliasName_2  = "基本名称";
            pFieldEdit.IsNullable_2 = false;
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(pFieldEdit);

            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "AliasName";
            pFieldEdit.Length_2     = 255;
            pFieldEdit.AliasName_2  = "别名";
            pFieldEdit.IsNullable_2 = true;
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(pFieldEdit);



            IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();

            _workspace.CreateTable("YT_TEMPLATE_DATASET", (IFields)fieldsEdit, ocDescription.InstanceCLSID, null,
                                   "");

            return;
        }
Example #7
0
        public static ITable CreateObjectClass(IWorkspace workspace, String className, IFields fields)
        {
            IFeatureWorkspace       featureWorkspace = (IFeatureWorkspace)workspace;
            IObjectClassDescription ocDescription    = new ObjectClassDescriptionClass();

            // Use IFieldChecker to create a validated fields collection.
            IFieldChecker   fieldChecker    = new FieldCheckerClass();
            IEnumFieldError enumFieldError  = null;
            IFields         validatedFields = null;

            fieldChecker.ValidateWorkspace = workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.
            ITable table = featureWorkspace.CreateTable(className, validatedFields,
                                                        ocDescription.InstanceCLSID, null, "");

            return(table);
        }
        public static ITable CreateTimeZoneTable(string outputFileGdbPath, string timeZone)
        {
            // start with the initial set of required fields for a table

            IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();
            IFieldsEdit             outFields     = ocDescription.RequiredFields as IFieldsEdit;

            // add the MSTIMEZONE field to the table

            IFieldEdit field = new FieldClass();

            field.Name_2   = "MSTIMEZONE";
            field.Type_2   = esriFieldType.esriFieldTypeString;
            field.Length_2 = 50;
            outFields.AddField(field);

            // open the file geodatabase

            Type gdbFactoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            var  gdbWSF         = Activator.CreateInstance(gdbFactoryType) as IWorkspaceFactory;
            var  gdbFWS         = gdbWSF.OpenFromFile(outputFileGdbPath, 0) as IFeatureWorkspace;

            // create the table

            ITable t = gdbFWS.CreateTable("TimeZones", outFields, ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, "");

            // create a record in the table with the specified time zone

            ICursor    cur  = t.Insert(true);
            IRowBuffer buff = t.CreateRowBuffer();

            buff.set_Value(t.FindField("MSTIMEZONE"), timeZone);
            cur.InsertRow(buff);

            // Flush any outstanding writes to the table
            cur.Flush();

            return(t);
        }
        /// 输出结果为一个张表,这张表有3个字段,其中面ID为面要素数据的FID
        /// 个数用于记录这个面包含的点的个数
        ///
        public ITable CreateTable(string _TablePath, string _TableName)
        {
            IWorkspaceFactory pWks = new ShapefileWorkspaceFactoryClass();

            IFeatureWorkspace pFwk = pWks.OpenFromFile(_TablePath, 0) as IFeatureWorkspace;

            //用于记录面中的ID;

            IField pFieldID = new FieldClass();

            IFieldEdit pFieldIID = pFieldID as IFieldEdit;

            pFieldIID.Type_2 = esriFieldType.esriFieldTypeInteger;

            pFieldIID.Name_2 = "面ID";

            //用于记录个数的;
            IField pFieldCount = new FieldClass();

            IFieldEdit pFieldICount = pFieldCount as IFieldEdit;

            pFieldICount.Type_2 = esriFieldType.esriFieldTypeInteger;
            pFieldICount.Name_2 = "个数";

            //用于添加表中的必要字段
            IObjectClassDescription objectClassDescription = new ObjectClassDescriptionClass();

            IFields pTableFields = objectClassDescription.RequiredFields;

            IFieldsEdit pTableFieldsEdit = pTableFields as IFieldsEdit;

            pTableFieldsEdit.AddField(pFieldID);

            pTableFieldsEdit.AddField(pFieldCount);

            ITable pTable = pFwk.CreateTable(_TableName, pTableFields, null, null, "");

            return(pTable);
        }
        private void CreateDailyProfilesTable(ITable inputHSPRTable, string outputFileGdbPath, double fgdbVersion)
        {
            // Find the needed fields on the input HSPR table

            int profileIDField = inputHSPRTable.FindField("PROFILE_ID");
            int relSpField = inputHSPRTable.FindField("REL_SP");

            // Create the Profiles table in the output file geodatabase and open an InsertCursor on it

            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            var gdbWSF = Activator.CreateInstance(factoryType) as IWorkspaceFactory;
            var gdbFWS = gdbWSF.OpenFromFile(outputFileGdbPath, 0) as IFeatureWorkspace;
            var ocd = new ObjectClassDescriptionClass() as IObjectClassDescription;
            var tableFields = ocd.RequiredFields as IFieldsEdit;
            var newField = new FieldClass() as IFieldEdit;
            newField.Name_2 = "ProfileID";
            newField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            tableFields.AddField(newField as IField);
            for (int i = 0; i < 288; i++)
            {
                newField = new FieldClass();
                newField.Type_2 = esriFieldType.esriFieldTypeSingle;
                newField.Name_2 = ((fgdbVersion == 10.0) ? "TimeFactor_" : "SpeedFactor_") + String.Format("{0:00}", i / 12) + String.Format("{0:00}", (i % 12) * 5);
                tableFields.AddField(newField as IField);
            }
            ITable newTable = gdbFWS.CreateTable(ProfilesTableName, tableFields as IFields, ocd.InstanceCLSID, ocd.ClassExtensionCLSID, "");
            int newTableProfileIDField = newTable.FindField("ProfileID");
            IRowBuffer buff = newTable.CreateRowBuffer();
            ICursor insertCursor = newTable.Insert(true);

            // Loop through the HSPR table and populate the newly-created Profiles table

            ITableSort ts = new TableSortClass();
            ts.Table = inputHSPRTable;
            ts.Fields = "PROFILE_ID, TIME_SLOT";
            ts.set_Ascending("PROFILE_ID", true);
            ts.set_Ascending("TIME_SLOT", true);
            ts.Sort(null);
            ICursor cur = ts.Rows;
            IRow r = cur.NextRow();
            while (r != null)
            {
                buff.set_Value(newTableProfileIDField, r.get_Value(profileIDField));
                for (int i = 1; i <= 288; i++)
                {
                    buff.set_Value(newTableProfileIDField + i,
                                   (fgdbVersion == 10.0) ? (100 / (float)(r.get_Value(relSpField)))
                                                         : ((float)(r.get_Value(relSpField)) / 100));
                    r = cur.NextRow();
                }
                insertCursor.InsertRow(buff);
            }

            // Flush any outstanding writes to the table
            insertCursor.Flush();
        }
Example #11
0
        /// <summary>
        /// �����ֶμ���
        /// </summary>
        /// <param name="ocDescription">Ҫ��������</param>
        /// <param name="tableStructureNode">��ṹ�ڵ�</param>
        /// <returns></returns>
        private IFields CreateFileds(TableStructureNode tableStructureNode, FeatureCodeNode featureCodeNode)
        {
            try
            {
                ///�����ֶμ���
                IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
                IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();
                IFields fields = ocDescription.RequiredFields;

                //�������ļ���ȡͼ������
                string sGeometryType = "";
                Metadata.MetaTable pMetaTalbe = Metadata.MetaDataFile.MetaTabls[tableStructureNode.TableName] as Metadata.MetaTable;
                if (pMetaTalbe != null)
                {
                    sGeometryType = Metadata.MetaDataFile.GraphConfig.GetGraphTypeMark(pMetaTalbe.Type);
                }

                //����ͼ������
                if (sGeometryType != "NoneGeometry")
                {
                    ocDescription = (IObjectClassDescription)fcDescription;
                    fields = ocDescription.RequiredFields;
                    int shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName);
                    IField pGeometryfield = fields.get_Field(shapeFieldIndex);
                    IGeometryDef geometryDef = pGeometryfield.GeometryDef;
                    IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
                    if (sGeometryType == "Point")
                        geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                    else if (sGeometryType == "Line")
                        geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
                    else if (sGeometryType == "Polygon")
                        geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;

                }
                IFieldsEdit fieldsEdit = fields as IFieldsEdit;
                // ������ṹ����
                int FieldCount = tableStructureNode.FieldNodes.Count;
                for (int i = 0; i < FieldCount; i++)
                {
                    IField field = new FieldClass();
                    IFieldEdit fieldEdit = (IFieldEdit)field;
                    ///��ȡ�ֶ���Ϣ
                    FieldNode pFieldNode = tableStructureNode.FieldNodes[i];
                    if (pFieldNode != null)
                    {
                        ///�����ֶ�ֵ
                        fieldEdit.Name_2 = pFieldNode.FieldName;

                        //�������л�ȡ����
                        if (pMetaTalbe != null)
                            fieldEdit.AliasName_2 = pMetaTalbe.GetFiledALisNameByCode(pFieldNode.FieldName);
                        esriFieldType type = esriFieldType.esriFieldTypeString;
                        switch (pFieldNode.FieldType)
                        {
                            case "Char":
                                type = esriFieldType.esriFieldTypeString;
                                break;
                            case "Int":
                                type = esriFieldType.esriFieldTypeInteger;
                                break;
                            case "Float":
                                type = esriFieldType.esriFieldTypeDouble;
                                break;
                            case "Time":
                                type = esriFieldType.esriFieldTypeDate;
                                break;
                            case "DateTime":
                                type = esriFieldType.esriFieldTypeDate;
                                break;
                            case "Varchar":
                                type = esriFieldType.esriFieldTypeString;
                                break;
                            case "Varbin":
                                type = esriFieldType.esriFieldTypeString;
                                break;
                            default:
                                break;
                        }
                        fieldEdit.Type_2 = type;
                        fieldEdit.Length_2 = pFieldNode.FieldLength;
                        fieldEdit.Precision_2 = pFieldNode.FieldPrecision;
                        fieldsEdit.AddField(field);
                    }
                }
                return fields;
            }
            catch(Exception ex)
            {
                LogAPI.WriteErrorLog(ex);
                return null;
            }
        }
        public static ITable CreateSignsDetailTable(IFeatureClass linesFeatureClass, string name)
        {
            // Locations are all relative to the location of the reference lines.
            // For Geodatabase, signs feature class is at the same location and the streets table
            // is at the level of the containing feature dataset.
            // For shapefile, both are at the same location as the reference lines.

            // start with the initial set of required fields for a table

            IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();
            IFieldsEdit             outFields     = ocDescription.RequiredFields as IFieldsEdit;

            // add the SignpostID field to the table

            IFieldEdit field = new FieldClass();

            field.Name_2 = "SignpostID";
            field.Type_2 = esriFieldType.esriFieldTypeInteger;
            outFields.AddField(field);

            // add the other fields to the table

            field        = new FieldClass();
            field.Name_2 = "Sequence";
            field.Type_2 = esriFieldType.esriFieldTypeInteger;
            outFields.AddField(field);

            field        = new FieldClass();
            field.Name_2 = "EdgeFCID";
            field.Type_2 = esriFieldType.esriFieldTypeInteger;
            outFields.AddField(field);

            field        = new FieldClass();
            field.Name_2 = "EdgeFID";
            field.Type_2 = esriFieldType.esriFieldTypeInteger;
            outFields.AddField(field);

            field        = new FieldClass();
            field.Name_2 = "EdgeFrmPos";
            field.Type_2 = esriFieldType.esriFieldTypeDouble;
            outFields.AddField(field);

            field        = new FieldClass();
            field.Name_2 = "EdgeToPos";
            field.Type_2 = esriFieldType.esriFieldTypeDouble;
            outFields.AddField(field);

            // make the table

            IFeatureDataset featureDataset = linesFeatureClass.FeatureDataset;
            IWorkspace      workspace      = (linesFeatureClass as IDataset).Workspace;

            if (featureDataset != null)
            {
                // up a level
                IFeatureWorkspace createWS = featureDataset.Workspace as IFeatureWorkspace;
                return(createWS.CreateTable(name, outFields, ocDescription.InstanceCLSID, null, ""));
            }
            else if (workspace is IFeatureWorkspace)
            {
                return((workspace as IFeatureWorkspace).CreateTable(name, outFields, ocDescription.InstanceCLSID, null, ""));
            }
            else
            {
                return(null);   // not expected
            }
        }
Example #13
0
        private IFields CreateMatchedPolygonFCSettingFields(IWorkspace2 workspace)
        {
            IObjectClassDescription objectClassDescription = new ObjectClassDescriptionClass();
            IFields     fields     = new FieldsClass();
            IFieldsEdit fieldsEdit = fields as IFieldsEdit;

            fields = objectClassDescription.RequiredFields;

            IField     field     = new FieldClass();
            IFieldEdit fieldEdit = field as IFieldEdit;

            fieldEdit.Name_2       = "OBJECTID";
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeOID;
            fieldEdit.IsNullable_2 = false;
            fieldsEdit.AddField(field);

            IField     field16     = new FieldClass();
            IFieldEdit fieldEdit16 = field16 as IFieldEdit;

            fieldEdit16.Name_2       = "SourceFCName";
            fieldEdit16.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit16.IsNullable_2 = false;
            fieldEdit16.AliasName_2  = "源图层名称";
            fieldsEdit.AddField(field16);



            IField     field17     = new FieldClass();
            IFieldEdit fieldEdit17 = field17 as IFieldEdit;

            fieldEdit17.Name_2       = "SourcePath";
            fieldEdit17.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit17.IsNullable_2 = false;
            fieldEdit17.AliasName_2  = "源图层路径";
            fieldsEdit.AddField(field17);


            IField     field1     = new FieldClass();
            IFieldEdit fieldEdit1 = field1 as IFieldEdit;

            fieldEdit1.Name_2       = "MatchedFCName";
            fieldEdit1.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit1.IsNullable_2 = false;
            fieldEdit1.AliasName_2  = "更新图层名";
            fieldsEdit.AddField(field1);

            IField     field18     = new FieldClass();
            IFieldEdit fieldEdit18 = field18 as IFieldEdit;

            fieldEdit18.Name_2       = "WorkspacePath";
            fieldEdit18.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit18.IsNullable_2 = false;
            fieldEdit18.AliasName_2  = "工作区路径";
            fieldsEdit.AddField(field18);

            IField     field2     = new FieldClass();
            IFieldEdit fieldEdit2 = field2 as IFieldEdit;

            fieldEdit2.Name_2       = "FCSettingID";
            fieldEdit2.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit2.IsNullable_2 = false;
            fieldEdit2.AliasName_2  = "参数ID";
            fieldsEdit.AddField(field2);

            IField     field3     = new FieldClass();
            IFieldEdit fieldEdit3 = field3 as IFieldEdit;

            fieldEdit3.Name_2       = "Center";
            fieldEdit3.Type_2       = esriFieldType.esriFieldTypeInteger;
            fieldEdit3.AliasName_2  = "重心点匹配";
            fieldEdit3.IsNullable_2 = true;
            fieldsEdit.AddField(field3);

            IField     field4     = new FieldClass();
            IFieldEdit fieldEdit4 = field4 as IFieldEdit;

            fieldEdit4.Name_2       = "CenterNum";
            fieldEdit4.Type_2       = esriFieldType.esriFieldTypeDouble;
            fieldEdit4.AliasName_2  = "重心点阈值";
            fieldEdit4.IsNullable_2 = true;
            fieldsEdit.AddField(field4);

            //IField field5 = new FieldClass();
            //IFieldEdit fieldEdit5 = field5 as IFieldEdit;
            //fieldEdit5.Name_2 = "CenterWT";
            //fieldEdit5.Type_2 = esriFieldType.esriFieldTypeDouble;
            //fieldEdit5.AliasName_2 = "重心点权重";
            //fieldEdit5.IsNullable_2 = true;
            //fieldsEdit.AddField(field5);

            IField     field6     = new FieldClass();
            IFieldEdit fieldEdit6 = field6 as IFieldEdit;

            fieldEdit6.Name_2       = "Area";
            fieldEdit6.Type_2       = esriFieldType.esriFieldTypeInteger;
            fieldEdit6.AliasName_2  = "面积匹配";
            fieldEdit6.IsNullable_2 = true;
            fieldsEdit.AddField(field6);

            IField     field7     = new FieldClass();
            IFieldEdit fieldEdit7 = field7 as IFieldEdit;

            fieldEdit7.Name_2       = "AreaNum";
            fieldEdit7.Type_2       = esriFieldType.esriFieldTypeDouble;
            fieldEdit7.AliasName_2  = "面积阈值";
            fieldEdit7.IsNullable_2 = true;
            fieldsEdit.AddField(field7);

            //IField field8 = new FieldClass();
            //IFieldEdit fieldEdit8 = field8 as IFieldEdit;
            //fieldEdit8.Name_2 = "AreaWT";
            //fieldEdit8.Type_2 = esriFieldType.esriFieldTypeDouble;
            //fieldEdit8.AliasName_2 = "面积权重";
            //fieldEdit8.IsNullable_2 = true;
            //fieldsEdit.AddField(field8);


            IField     field9     = new FieldClass();
            IFieldEdit fieldEdit9 = field9 as IFieldEdit;

            fieldEdit9.Name_2       = "SP";
            fieldEdit9.Type_2       = esriFieldType.esriFieldTypeInteger;
            fieldEdit9.AliasName_2  = "形状匹配";
            fieldEdit9.IsNullable_2 = true;
            fieldsEdit.AddField(field9);

            IField     field10     = new FieldClass();
            IFieldEdit fieldEdit10 = field10 as IFieldEdit;

            fieldEdit10.Name_2       = "SPNum";
            fieldEdit10.Type_2       = esriFieldType.esriFieldTypeDouble;
            fieldEdit10.AliasName_2  = "形状阈值";
            fieldEdit10.IsNullable_2 = true;
            fieldsEdit.AddField(field10);

            //IField field11 = new FieldClass();
            //IFieldEdit fieldEdit11 = field11 as IFieldEdit;
            //fieldEdit11.Name_2 = "SPWT";
            //fieldEdit11.Type_2 = esriFieldType.esriFieldTypeDouble;
            //fieldEdit11.AliasName_2 = "形状权重";
            //fieldEdit11.IsNullable_2 = true;
            //fieldsEdit.AddField(field11);

            IField     field12     = new FieldClass();
            IFieldEdit fieldEdit12 = field12 as IFieldEdit;

            fieldEdit12.Name_2       = "Top";
            fieldEdit12.Type_2       = esriFieldType.esriFieldTypeInteger;
            fieldEdit12.AliasName_2  = "拓扑匹配";
            fieldEdit12.IsNullable_2 = true;
            fieldsEdit.AddField(field12);

            IField     field13     = new FieldClass();
            IFieldEdit fieldEdit13 = field13 as IFieldEdit;

            fieldEdit13.Name_2       = "Buffer";
            fieldEdit13.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit13.AliasName_2  = "拓扑缓冲区半径";
            fieldEdit13.IsNullable_2 = true;
            fieldsEdit.AddField(field13);

            IField     field14     = new FieldClass();
            IFieldEdit fieldEdit14 = field14 as IFieldEdit;

            fieldEdit14.Name_2       = "Attribute";
            fieldEdit14.Type_2       = esriFieldType.esriFieldTypeInteger;
            fieldEdit14.AliasName_2  = "属性匹配";
            fieldEdit14.IsNullable_2 = true;
            fieldsEdit.AddField(field14);

            IField     field15     = new FieldClass();
            IFieldEdit fieldEdit15 = field15 as IFieldEdit;

            fieldEdit15.Name_2       = "MatchedFields";
            fieldEdit15.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit15.AliasName_2  = "匹配属性字段";
            fieldEdit15.IsNullable_2 = true;
            fieldsEdit.AddField(field15);


            IField     field19     = new FieldClass();
            IFieldEdit fieldEdit19 = field19 as IFieldEdit;

            fieldEdit19.Name_2       = "Voronoi";
            fieldEdit19.Type_2       = esriFieldType.esriFieldTypeInteger;
            fieldEdit19.AliasName_2  = "泰森多边形";
            fieldEdit19.IsNullable_2 = true;
            fieldsEdit.AddField(field19);

            fields = fieldsEdit as IFieldsEdit;
            return(fields);
        }
Example #14
0
        private void CreateFeatureClassTable()
        {
            if (_workspace == null)
            {
                Connect();
            }

            IFieldsEdit fieldsEdit = new FieldsClass();
            IField      pField     = FieldHelper.CreateOIDField();

            fieldsEdit.AddField(pField);

            IFieldEdit pFieldEdit = new FieldClass();

            pFieldEdit.Name_2       = "TemplateName";
            pFieldEdit.Length_2     = 255;
            pFieldEdit.AliasName_2  = "模板名称";
            pFieldEdit.IsNullable_2 = false;
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(pFieldEdit);

            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "BaseName";
            pFieldEdit.Length_2     = 255;
            pFieldEdit.AliasName_2  = "基本名称";
            pFieldEdit.IsNullable_2 = false;
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(pFieldEdit);

            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "AliasName";
            pFieldEdit.Length_2     = 255;
            pFieldEdit.AliasName_2  = "别名";
            pFieldEdit.IsNullable_2 = true;
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(pFieldEdit);

            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "Dataset";
            pFieldEdit.Length_2     = 255;
            pFieldEdit.AliasName_2  = "数据集";
            pFieldEdit.IsNullable_2 = true;
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(pFieldEdit);

            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "FeatureType";
            pFieldEdit.Length_2     = 30;
            pFieldEdit.AliasName_2  = "要素类型";
            pFieldEdit.IsNullable_2 = true;
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(pFieldEdit);

            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "GeometryType";
            pFieldEdit.Length_2     = 30;
            pFieldEdit.AliasName_2  = "图形类型";
            pFieldEdit.IsNullable_2 = true;
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(pFieldEdit);

            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "FieldDefs";
            pFieldEdit.Length_2     = 2147483647;
            pFieldEdit.AliasName_2  = "字段定义";
            pFieldEdit.IsNullable_2 = true;
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(pFieldEdit);

            IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();

            _workspace.CreateTable("YT_TEMPLATE_FEATURECLASS", (IFields)fieldsEdit, ocDescription.InstanceCLSID, null,
                                   "");

            return;
        }
        private void ConvertTMCReferenceFileToFGDBTable(string referenceFilePath, string outputFileGdbPath)
        {
            // Create the Reference table in the output file geodatabase and open an InsertCursor on it

            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            var gdbWSF = Activator.CreateInstance(factoryType) as IWorkspaceFactory;
            var gdbFWS = gdbWSF.OpenFromFile(outputFileGdbPath, 0) as IFeatureWorkspace;
            var ocd = new ObjectClassDescriptionClass() as IObjectClassDescription;
            var tableFields = ocd.RequiredFields as IFieldsEdit;
            var newField = new FieldClass() as IFieldEdit;
            newField.Name_2 = "TMC";
            newField.Type_2 = esriFieldType.esriFieldTypeString;
            newField.Length_2 = 9;
            tableFields.AddField(newField as IField);
            newField = new FieldClass();
            newField.Name_2 = "U";
            newField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            tableFields.AddField(newField as IField);
            newField = new FieldClass();
            newField.Name_2 = "M";
            newField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            tableFields.AddField(newField as IField);
            newField = new FieldClass();
            newField.Name_2 = "T";
            newField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            tableFields.AddField(newField as IField);
            newField = new FieldClass();
            newField.Name_2 = "W";
            newField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            tableFields.AddField(newField as IField);
            newField = new FieldClass();
            newField.Name_2 = "R";
            newField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            tableFields.AddField(newField as IField);
            newField = new FieldClass();
            newField.Name_2 = "F";
            newField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            tableFields.AddField(newField as IField);
            newField = new FieldClass();
            newField.Name_2 = "S";
            newField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            tableFields.AddField(newField as IField);
            ITable newTable = gdbFWS.CreateTable("TempRefTable", tableFields as IFields, ocd.InstanceCLSID, ocd.ClassExtensionCLSID, "");
            int newTableTMCField = newTable.FindField("TMC");
            IRowBuffer buff = newTable.CreateRowBuffer();
            ICursor insertCursor = newTable.Insert(true);

            // Read each line of the Reference file and populate the newly-created Reference table

            System.IO.StreamReader f = new System.IO.StreamReader(referenceFilePath);
            string s = f.ReadLine();    // skip the first line (header)
            while ((s = f.ReadLine()) != null)
            {
                int commaPos = s.IndexOf(",");

                // First value is the TMC
                string tmc = s.Remove(commaPos);
                buff.set_Value(newTableTMCField, tmc);

                // Remaining values are the ProfileIDs for each day
                for (int i = 1; i <= 7; i++)
                {
                    s = s.Substring(commaPos + 1);
                    commaPos = s.IndexOf(",");

                    int profileID = Convert.ToInt32((commaPos < 0) ? s : s.Remove(commaPos), System.Globalization.CultureInfo.InvariantCulture);
                    buff.set_Value(newTableTMCField + i, profileID);
                }

                // Insert the row into the table
                insertCursor.InsertRow(buff);
            }
            f.Close();

            // Flush any outstanding writes to the table
            insertCursor.Flush();
        }
Example #16
0
        public bool StartImport()
        {
            int    kk;
            string pFieldName;
            int    pFieldIndex;
            bool   flag;

            DataRow[] dataRowArray;
            int       l;
            var       xyzTableName = string.Concat("XYZ_", Basename);
            IFields   pFields      = new FieldsClass();
            var       pFieldsEdit  = pFields as IFieldsEdit;
            var       xyzTable     = new DataTable("XYZ");

            xyzTable.Columns.Add(new DataColumn("SurveyNO", typeof(string)));
            xyzTable.Columns.Add(new DataColumn("CX", typeof(double)));
            xyzTable.Columns.Add(new DataColumn("CY", typeof(double)));
            xyzTable.Columns.Add(new DataColumn("CZ", typeof(double)));
            xyzTable.Columns.Add(new DataColumn("PNTCODE", typeof(string)));
            IFieldEdit pFieldEdit = new FieldClass();

            pFieldEdit.Name_2       = "SurveyNO";
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            pFieldEdit.IsNullable_2 = true;
            pFieldEdit.Length_2     = 10;
            pFieldsEdit.AddField(pFieldEdit);
            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "CX";
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
            pFieldEdit.IsNullable_2 = true;
            pFieldEdit.Length_2     = 10;
            pFieldsEdit.AddField(pFieldEdit);
            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "CY";
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
            pFieldEdit.IsNullable_2 = true;
            pFieldEdit.Length_2     = 10;
            pFieldsEdit.AddField(pFieldEdit);
            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "CZ";
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
            pFieldEdit.IsNullable_2 = true;
            pFieldEdit.Length_2     = 10;
            pFieldsEdit.AddField(pFieldEdit);
            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "PNTCODE";
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            pFieldEdit.IsNullable_2 = true;
            pFieldEdit.Length_2     = 10;
            pFieldsEdit.AddField(pFieldEdit);
            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "Surveyer";
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            pFieldEdit.IsNullable_2 = true;
            pFieldEdit.Length_2     = 10;
            pFieldsEdit.AddField(pFieldEdit);
            pFieldEdit              = new FieldClass();
            pFieldEdit.Name_2       = "PNTCODE";
            pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDate;
            pFieldEdit.IsNullable_2 = true;
            pFieldEdit.Length_2     = 10;
            pFieldsEdit.AddField(pFieldEdit);
            if (new FileInfo(Xyzfile).Exists)
            {
                var     sr    = new StreamReader(Xyzfile, Encoding.GetEncoding("gb2312"));
                var     pLine = sr.ReadLine().Trim();
                DataRow pRow;
                while (true)
                {
                    var str = sr.ReadLine();
                    pLine = str;
                    if (str == null)
                    {
                        break;
                    }
                    if (pLine == null ? false : pLine.Trim().Length != 0)
                    {
                        pLine = pLine.Trim();
                        var pSubs = pLine.Split(',');
                        pRow             = xyzTable.NewRow();
                        pRow["SurveyNo"] = pSubs[0];
                        switch (CoordType)
                        {
                        case SurveyCoordType.NOXY:
                        {
                            pRow["CX"] = double.Parse(pSubs[1]);
                            pRow["CY"] = double.Parse(pSubs[2]);
                            break;
                        }

                        case SurveyCoordType.NOYX:
                        {
                            pRow["CX"] = double.Parse(pSubs[2]);
                            pRow["CY"] = double.Parse(pSubs[1]);
                            break;
                        }

                        case SurveyCoordType.NOCODEXY:
                        {
                            pRow["CX"]      = double.Parse(pSubs[2]);
                            pRow["CY"]      = double.Parse(pSubs[3]);
                            pRow["PNTCODE"] = pSubs[1];
                            break;
                        }

                        case SurveyCoordType.NOCODEYX:
                        {
                            pRow["CX"]      = double.Parse(pSubs[3]);
                            pRow["CY"]      = double.Parse(pSubs[2]);
                            pRow["PNTCODE"] = pSubs[1];
                            break;
                        }

                        case SurveyCoordType.NOXYZ:
                        {
                            pRow["CX"] = double.Parse(pSubs[1]);
                            pRow["CY"] = double.Parse(pSubs[2]);
                            pRow["CZ"] = double.Parse(pSubs[3]);
                            break;
                        }

                        case SurveyCoordType.NOYXZ:
                        {
                            pRow["CX"] = double.Parse(pSubs[2]);
                            pRow["CY"] = double.Parse(pSubs[1]);
                            pRow["CZ"] = double.Parse(pSubs[3]);
                            break;
                        }

                        case SurveyCoordType.NOCODEXYZ:
                        {
                            pRow["PNTCODE"] = pSubs[1];
                            pRow["CX"]      = double.Parse(pSubs[2]);
                            pRow["CY"]      = double.Parse(pSubs[3]);
                            pRow["CZ"]      = double.Parse(pSubs[4]);
                            break;
                        }

                        case SurveyCoordType.NOCODEYXZ:
                        {
                            pRow["PNTCODE"] = pSubs[1];
                            pRow["CX"]      = double.Parse(pSubs[3]);
                            pRow["CY"]      = double.Parse(pSubs[2]);
                            pRow["CZ"]      = double.Parse(pSubs[4]);
                            break;
                        }

                        default:
                        {
                            flag = false;
                            return(flag);
                        }
                        }
                        xyzTable.Rows.Add(pRow);
                    }
                }
                sr.Close();
                var xlsxTable    = new DataTable("XLSXTABLE");
                var ws           = new XLWorkbook(Xlsxfile).Worksheet("Data");
                var firstRowUsed = ws.FirstRowUsed();
                ws.LastRowUsed();
                var firstColumnUsed = ws.FirstColumnUsed();
                ws.LastColumnUsed();
                firstColumnUsed.CellCount();
                var compcodeIndex = 0;
                var k             = 0;
                foreach (var xlCell in firstRowUsed.Cells())
                {
                    var columnName = xlCell.GetValue <string>().Trim();
                    columnName = columnName.Replace(" ", "");
                    var column = new DataColumn(columnName, typeof(string))
                    {
                        AllowDBNull = true
                    };
                    xlsxTable.Columns.Add(column);
                    if (columnName == "CompCode")
                    {
                        compcodeIndex = k;
                    }
                    k++;
                    if (!(columnName == "SurveyNO"))
                    {
                        pFieldEdit        = new FieldClass();
                        pFieldEdit.Name_2 = columnName;
                        pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                        pFieldsEdit.AddField(pFieldEdit);
                    }
                }
                var firstvalueAddress = firstRowUsed.RowBelow().FirstCell().Address;
                var lastvalueAddress  = ws.LastCellUsed().Address;
                int j;
                foreach (
                    var xlRangeRow in ws.Range(firstvalueAddress, lastvalueAddress).Rows((Func <IXLRangeRow, bool>)null)
                    )
                {
                    j    = 0;
                    pRow = xlsxTable.NewRow();
                    foreach (var xLCell in xlRangeRow.Cells())
                    {
                        if (j == compcodeIndex)
                        {
                            pRow[j] = xLCell.GetString().PadLeft(4, '0');
                        }
                        else
                        {
                            pRow[j] = xLCell.GetString();
                        }
                        j++;
                    }
                    xlsxTable.Rows.Add(pRow);
                }
                var geoFields     = new FeatureClassDescriptionClass().RequiredFields;
                var geoFieldsEdit = geoFields as IFieldsEdit;
                var xyFields      = new ObjectClassDescriptionClass().RequiredFields;
                var xyFieldsEdit  = xyFields as IFieldsEdit;
                for (var ii = 0; ii < pFields.FieldCount; ii++)
                {
                    xyFieldsEdit.AddField(pFields.get_Field(ii));
                    geoFieldsEdit.AddField(pFields.get_Field(ii));
                }
                var esriTable = GSCSUtilsGen.Instance.CreateTable((IWorkspace2)TargetWks, xyzTableName, xyFields);
                var pointFC   = GSCSUtilsGen.Instance.CreateFeatureClass((IWorkspace2)TargetWks, null,
                                                                         string.Concat("PNT_", Basename), geoFields, null, null, "", esriGeometryType.esriGeometryPoint);
                var lineFC = GSCSUtilsGen.Instance.CreateFeatureClass((IWorkspace2)TargetWks, null,
                                                                      string.Concat("LINE_", Basename), geoFields, null, null, "", esriGeometryType.esriGeometryPolyline);
                var areaFC = GSCSUtilsGen.Instance.CreateFeatureClass((IWorkspace2)TargetWks, null,
                                                                      string.Concat("AREA_", Basename), geoFields, null, null, "", esriGeometryType.esriGeometryPolygon);
                var dataTable  = xlsxTable;
                var dataTable1 = xyzTable;
                Func <DataRow, DataRow, bool>[] funcArray =
                {
                    (rowA, rowB) => rowA.Field <string>("SurveyNO") == rowB.Field <string>("SurveyNO")
                };
                var vResult        = JoinDataTables(dataTable, dataTable1, funcArray);
                var pWorkspaceEdit = TargetWks as IWorkspaceEdit;
                pWorkspaceEdit.StartEditing(false);
                pWorkspaceEdit.StartEditOperation();
                var pCount             = vResult.Rows.Count;
                var pColCount          = vResult.Columns.Count;
                var pRowIndexes        = new int[pColCount];
                var pPntFieldIndexes   = new int[pColCount];
                var pLineFieldIndexes  = new int[pColCount];
                var pAreaFieldIndexes  = new int[pColCount];
                var surveyIndex        = esriTable.FindField("Surveyer");
                var surveyDateIndex    = esriTable.FindField("SurveyDate");
                var surveyPntIndex     = pointFC.FindField("Surveyer");
                var surveyDatePntIndex = pointFC.FindField("SurveyDate");
                int i;
                for (i = 0; i < vResult.Columns.Count; i++)
                {
                    pRowIndexes[i]       = esriTable.FindField(vResult.Columns[i].ColumnName);
                    pPntFieldIndexes[i]  = pointFC.FindField(vResult.Columns[i].ColumnName);
                    pLineFieldIndexes[i] = lineFC.FindField(vResult.Columns[i].ColumnName);
                    pAreaFieldIndexes[i] = areaFC.FindField(vResult.Columns[i].ColumnName);
                }
                DataRow dataRow;
                for (i = 0; i < pCount; i++)
                {
                    dataRow = vResult.Rows[i];
                    var    esriRow  = esriTable.CreateRow();
                    var    pFeature = pointFC.CreateFeature();
                    IPoint pnt      = new PointClass();
                    pnt.PutCoords((double)dataRow["CX"], (double)dataRow["CY"]);
                    pFeature.Shape = pnt;
                    for (j = 0; j < pColCount; j++)
                    {
                        if (pRowIndexes[j] >= 0)
                        {
                            esriRow.set_Value(pRowIndexes[j], dataRow[j]);
                            pFeature.set_Value(pPntFieldIndexes[j], dataRow[j]);
                        }
                    }
                    esriRow.set_Value(surveyIndex, Surveyer);
                    esriRow.set_Value(surveyDateIndex, SurveyDate);
                    pFeature.set_Value(surveyPntIndex, Surveyer);
                    pFeature.set_Value(surveyDatePntIndex, SurveyDate);
                    esriRow.Store();
                    pFeature.Store();
                }
                pWorkspaceEdit.StopEditOperation();
                pWorkspaceEdit.StopEditing(true);
                pWorkspaceEdit.StartEditing(false);
                pWorkspaceEdit.StartEditOperation();
                var rows     = vResult.Select("PointType='LinePoint' AND LinkedSurveyNO =''", "RecordID");
                var lineRows = vResult.Select("PointType='LinePoint'");
                IPointCollection pnts;
                IPoint           pPnt;
                IPointCollection pPnts;
                IFeature         pLineFeature;
                if (rows == null ? false : rows.Length > 0)
                {
                    dataRowArray = rows;
                    for (l = 0; l < dataRowArray.Length; l++)
                    {
                        dataRow = dataRowArray[l];
                        pnts    = new PolylineClass();
                        pPnt    = new PointClass();
                        pPnt.PutCoords((double)dataRow["CX"], (double)dataRow["CY"]);
                        object r__ComRefCallLocal0 = Missing.Value;
                        object r__ComRefCallLocal1 = Missing.Value;
                        pnts.AddPoint(pPnt, ref r__ComRefCallLocal0, ref r__ComRefCallLocal1);
                        pPnts = CreateLine(pnts, dataRow, lineRows);
                        if (pPnts == null ? false : pPnts.PointCount > 1)
                        {
                            pLineFeature = lineFC.CreateFeature();
                            for (kk = 0; kk < vResult.Columns.Count; kk++)
                            {
                                pFieldName  = vResult.Columns[kk].ColumnName;
                                pFieldIndex = pLineFeature.Fields.FindField(pFieldName);
                                if (pFieldIndex > 0)
                                {
                                    pLineFeature.set_Value(pFieldIndex, dataRow[kk]);
                                }
                            }
                            pLineFeature.Shape = pPnts as IGeometry;
                            pLineFeature.Store();
                        }
                    }
                }
                pWorkspaceEdit.StopEditOperation();
                pWorkspaceEdit.StopEditing(true);
                pWorkspaceEdit.StartEditing(false);
                pWorkspaceEdit.StartEditOperation();
                rows     = vResult.Select("PointType='AreaPoint' AND LinkedSurveyNO =''", "RecordID");
                lineRows = vResult.Select("PointType='AreaPoint'");
                if (rows == null ? false : rows.Length > 0)
                {
                    dataRowArray = rows;
                    for (l = 0; l < dataRowArray.Length; l++)
                    {
                        dataRow = dataRowArray[l];
                        pnts    = new PolygonClass();
                        pPnt    = new PointClass();
                        pPnt.PutCoords((double)dataRow["CX"], (double)dataRow["CY"]);
                        object r__ComRefCallLocal2 = Missing.Value;
                        object r__ComRefCallLocal3 = Missing.Value;
                        pnts.AddPoint(pPnt, ref r__ComRefCallLocal2, ref r__ComRefCallLocal3);
                        pPnts = CreateLine(pnts, dataRow, lineRows);
                        if (pPnts == null ? false : pPnts.PointCount > 2)
                        {
                            pLineFeature = areaFC.CreateFeature();
                            for (kk = 0; kk < vResult.Columns.Count; kk++)
                            {
                                pFieldName  = vResult.Columns[kk].ColumnName;
                                pFieldIndex = pLineFeature.Fields.FindField(pFieldName);
                                if (pFieldIndex > 0)
                                {
                                    pLineFeature.set_Value(pFieldIndex, dataRow[kk]);
                                }
                            }
                            pPnt = new PointClass();
                            pPnt.PutCoords((double)dataRow["CX"], (double)dataRow["CY"]);
                            object r__ComRefCallLocal4 = Missing.Value;
                            object r__ComRefCallLocal5 = Missing.Value;
                            pnts.AddPoint(pPnt, ref r__ComRefCallLocal4, ref r__ComRefCallLocal5);
                            pLineFeature.Shape = (IGeometry)pPnts;
                            pLineFeature.Store();
                        }
                    }
                }
                pWorkspaceEdit.StopEditOperation();
                pWorkspaceEdit.StopEditing(true);
                flag = true;
            }
            else
            {
                flag = false;
            }
            return(flag);
        }
        public ITable createTable(IWorkspace wks, string tableName, IFields atrflds)
        {
            IWorkspace2 wks2 = (IWorkspace2)wks;
            IFeatureWorkspace ftrWks = (IFeatureWorkspace)wks;
            ITable tbl = null;
            try
            {

                if (wks2.get_NameExists(esriDatasetType.esriDTTable, tableName))
                {
                    return tbl;
                }

                IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();
                IFields fields = ocDescription.RequiredFields;
                IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
                if (atrflds != null)
                {
                    for (int i = 0; i < atrflds.FieldCount; i++)
                    {
                        IField fld = atrflds.get_Field(i);
                        fieldsEdit.AddField(fld);
                    }
                }
                // Use IFieldChecker to create a validated fields collection.
                IFieldChecker fieldChecker = new FieldCheckerClass();
                IEnumFieldError enumFieldError = null;
                IFields validatedFields = null;
                fieldChecker.ValidateWorkspace = (IWorkspace)wks;
                fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
                tbl = ftrWks.CreateTable(tableName, validatedFields, ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, "");
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.ToString());
            }
            return tbl;
        }
        /// <summary>
        /// 设置匹配多边形字段
        /// </summary>
        /// <param name="workspace">根据工作图层路径打开的工具空间</param>
        /// <returns></returns>
        public IFields CreateMatchPolygonTFields(IWorkspace2 workspace)
        {
            IObjectClassDescription objectClassDescription = new ObjectClassDescriptionClass();
            IFields     fields     = new FieldsClass();
            IFieldsEdit fieldsEdit = fields as IFieldsEdit;

            fields = objectClassDescription.RequiredFields;

            //test
            //false
            bool test = ClsDeclare.g_SameScaleMatch && !ClsDeclare.g_DifScaleMatch;
            //true
            bool test2 = !ClsDeclare.g_SameScaleMatch && ClsDeclare.g_DifScaleMatch;

            //同一比例尺的匹配
            if (ClsDeclare.g_SameScaleMatch && !ClsDeclare.g_DifScaleMatch)
            {
                IField     field     = new FieldClass();
                IFieldEdit fieldEdit = field as IFieldEdit;
                fieldEdit.Name_2       = "OBJECTID";
                fieldEdit.Type_2       = esriFieldType.esriFieldTypeOID;
                fieldEdit.IsNullable_2 = false;
                fieldsEdit.AddField(field);

                IField     field1     = new FieldClass();
                IFieldEdit fieldEdit1 = field1 as IFieldEdit;
                fieldEdit1.Name_2       = "源OID";
                fieldEdit1.Type_2       = esriFieldType.esriFieldTypeString;
                fieldEdit1.IsNullable_2 = true;
                fieldEdit1.AliasName_2  = "源OID";
                fieldEdit1.Editable_2   = true;
                fieldsEdit.AddField(field1);

                IField     field2     = new FieldClass();
                IFieldEdit fieldEdit2 = field2 as IFieldEdit;
                fieldEdit2.Name_2       = "待更新OID";
                fieldEdit2.Type_2       = esriFieldType.esriFieldTypeString;
                fieldEdit2.IsNullable_2 = true;
                fieldEdit2.AliasName_2  = "待更新OID";
                fieldEdit2.Editable_2   = true;
                fieldsEdit.AddField(field2);

                IField     field3     = new FieldClass();
                IFieldEdit fieldEdit3 = field3 as IFieldEdit;
                fieldEdit3.Name_2       = "变化标记";
                fieldEdit3.Type_2       = esriFieldType.esriFieldTypeString;
                fieldEdit3.IsNullable_2 = true;
                fieldEdit3.AliasName_2  = "变化标记";
                fieldEdit3.Editable_2   = true;
                fieldsEdit.AddField(field3);

                //    IField field4 = new FieldClass();
                //    IFieldEdit fieldEdit4 = field4 as IFieldEdit;
                //    fieldEdit4.Name_2 = "源编码";
                //    fieldEdit4.Type_2 = esriFieldType.esriFieldTypeString;
                //    fieldEdit4.IsNullable_2 = true;
                //    fieldEdit4.AliasName_2 = "源编码";
                //    fieldEdit4.Editable_2 = true;
                //    fieldsEdit.AddField(field4);



                //    IField field5 = new FieldClass();
                //    IFieldEdit fieldEdit5 = field5 as IFieldEdit;
                //    fieldEdit5.Name_2 = "更新编码";
                //    fieldEdit5.Type_2 = esriFieldType.esriFieldTypeString;
                //    fieldEdit5.IsNullable_2 = true;
                //    fieldEdit5.AliasName_2 = "更新编码";
                //    fieldEdit5.Editable_2 = true;
                //    fieldsEdit.AddField(field5);


                IField     field4     = new FieldClass();
                IFieldEdit fieldEdit4 = field4 as IFieldEdit;
                fieldEdit4.Name_2       = "位置相似度";
                fieldEdit4.Type_2       = esriFieldType.esriFieldTypeString;
                fieldEdit4.IsNullable_2 = true;
                fieldEdit4.AliasName_2  = "位置相似度";
                fieldEdit4.Editable_2   = true;
                fieldsEdit.AddField(field4);

                IField     field5     = new FieldClass();
                IFieldEdit fieldEdit5 = field5 as IFieldEdit;
                fieldEdit5.Name_2       = "面积相似度";
                fieldEdit5.Type_2       = esriFieldType.esriFieldTypeString;
                fieldEdit5.IsNullable_2 = true;
                fieldEdit5.AliasName_2  = "面积相似度";
                fieldEdit5.Editable_2   = true;
                fieldsEdit.AddField(field5);

                IField     field6     = new FieldClass();
                IFieldEdit fieldEdit6 = field6 as IFieldEdit;
                fieldEdit6.Name_2       = "形状相似度";
                fieldEdit6.Type_2       = esriFieldType.esriFieldTypeString;
                fieldEdit6.IsNullable_2 = true;
                fieldEdit6.AliasName_2  = "形状相似度";
                fieldEdit6.Editable_2   = true;
                fieldsEdit.AddField(field6);

                IField     field7     = new FieldClass();
                IFieldEdit fieldEdit7 = field7 as IFieldEdit;
                fieldEdit7.Name_2       = "综合相似度";
                fieldEdit7.Type_2       = esriFieldType.esriFieldTypeString;
                fieldEdit7.IsNullable_2 = true;
                fieldEdit7.AliasName_2  = "综合相似度";
                fieldEdit7.Editable_2   = true;
                fieldsEdit.AddField(field7);
            }
            //不同比例尺的匹配
            else if (!ClsDeclare.g_SameScaleMatch && ClsDeclare.g_DifScaleMatch)
            {
                IField     field     = new FieldClass();
                IFieldEdit fieldEdit = field as IFieldEdit;
                fieldEdit.Name_2       = "OBJECTID";
                fieldEdit.Type_2       = esriFieldType.esriFieldTypeOID;
                fieldEdit.IsNullable_2 = false;
                fieldsEdit.AddField(field);

                IField     field1     = new FieldClass();
                IFieldEdit fieldEdit1 = field1 as IFieldEdit;
                fieldEdit1.Name_2       = "源OID";
                fieldEdit1.Type_2       = esriFieldType.esriFieldTypeString;
                fieldEdit1.IsNullable_2 = true;
                fieldEdit1.AliasName_2  = "源OID";
                fieldEdit1.Editable_2   = true;
                fieldsEdit.AddField(field1);

                IField     field2     = new FieldClass();
                IFieldEdit fieldEdit2 = field2 as IFieldEdit;
                //fieldEdit2.Name_2 = "待更新OID";
                fieldEdit2.Name_2       = "待匹配OID";
                fieldEdit2.Type_2       = esriFieldType.esriFieldTypeString;
                fieldEdit2.IsNullable_2 = true;
                //fieldEdit2.AliasName_2 = "待更新OID";
                fieldEdit2.AliasName_2 = "待匹配OID";
                fieldEdit2.Editable_2  = true;
                fieldsEdit.AddField(field2);

                IField     field4     = new FieldClass();
                IFieldEdit fieldEdit4 = field4 as IFieldEdit;
                //fieldEdit4.Name_2 = "源编码";
                fieldEdit4.Name_2       = "源要素分类码";
                fieldEdit4.Type_2       = esriFieldType.esriFieldTypeString;
                fieldEdit4.IsNullable_2 = true;
                //fieldEdit4.AliasName_2 = "源编码";
                fieldEdit4.AliasName_2 = "源要素分类码";
                fieldEdit4.Editable_2  = true;
                fieldsEdit.AddField(field4);

                IField     field5     = new FieldClass();
                IFieldEdit fieldEdit5 = field5 as IFieldEdit;
                //fieldEdit5.Name_2 = "更新编码";
                fieldEdit5.Name_2       = "待匹配要素分类码";
                fieldEdit5.Type_2       = esriFieldType.esriFieldTypeString;
                fieldEdit5.IsNullable_2 = true;
                //fieldEdit5.AliasName_2 = "更新编码";
                fieldEdit5.AliasName_2 = "待匹配要素分类码";
                fieldEdit5.Editable_2  = true;
                fieldsEdit.AddField(field5);

                IField     field3     = new FieldClass();
                IFieldEdit fieldEdit3 = field3 as IFieldEdit;
                fieldEdit3.Name_2       = "变化标记";
                fieldEdit3.Type_2       = esriFieldType.esriFieldTypeString;
                fieldEdit3.IsNullable_2 = true;
                fieldEdit3.AliasName_2  = "变化标记";

                fieldEdit3.Editable_2 = true;
                fieldsEdit.AddField(field3);
            }
            fields = fieldsEdit as IFields;

            return(fields);
        }
        public static ITable CreateSignsDetailTable(IFeatureClass linesFeatureClass, string name)
        {
            // Locations are all relative to the location of the reference lines.
            // For Geodatabase, signs feature class is at the same location and the streets table
            // is at the level of the containing feature dataset.
            // For shapefile, both are at the same location as the reference lines.

            // start with the initial set of required fields for a table

            IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();
            IFieldsEdit outFields = ocDescription.RequiredFields as IFieldsEdit;

            // add the SignpostID field to the table

            IFieldEdit field = new FieldClass();
            field.Name_2 = "SignpostID";
            field.Type_2 = esriFieldType.esriFieldTypeInteger;
            outFields.AddField(field);

            // add the other fields to the table

            field = new FieldClass();
            field.Name_2 = "Sequence";
            field.Type_2 = esriFieldType.esriFieldTypeInteger;
            outFields.AddField(field);

            field = new FieldClass();
            field.Name_2 = "EdgeFCID";
            field.Type_2 = esriFieldType.esriFieldTypeInteger;
            outFields.AddField(field);

            field = new FieldClass();
            field.Name_2 = "EdgeFID";
            field.Type_2 = esriFieldType.esriFieldTypeInteger;
            outFields.AddField(field);

            field = new FieldClass();
            field.Name_2 = "EdgeFrmPos";
            field.Type_2 = esriFieldType.esriFieldTypeDouble;
            outFields.AddField(field);

            field = new FieldClass();
            field.Name_2 = "EdgeToPos";
            field.Type_2 = esriFieldType.esriFieldTypeDouble;
            outFields.AddField(field);

            // make the table

            IFeatureDataset featureDataset = linesFeatureClass.FeatureDataset;
            IWorkspace workspace = (linesFeatureClass as IDataset).Workspace;

            if (featureDataset != null)
            {
                // up a level
                IFeatureWorkspace createWS = featureDataset.Workspace as IFeatureWorkspace;
                return createWS.CreateTable(name, outFields, ocDescription.InstanceCLSID, null, "");
            }
            else if (workspace is IFeatureWorkspace)
                return (workspace as IFeatureWorkspace).CreateTable(name, outFields, ocDescription.InstanceCLSID, null, "");
            else
                return null;   // not expected
        }
        private void CreateAndPopulateRoadSplitsTable(string outputFileGdbPath, string BifurcationMPTableName,
                                                      IGPMessages messages, ITrackCancel trackcancel)
        {
            // Open the Rdms table and find all the fields we need

            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            var wsf = Activator.CreateInstance(factoryType) as IWorkspaceFactory;
            var fws = wsf.OpenFromFile(outputFileGdbPath, 0) as IFeatureWorkspace;

            // Open the MP table and find the fields we need

            ITable mpTable = fws.OpenTable(BifurcationMPTableName);
            int seqNrField = mpTable.FindField("SEQNR");
            int trpElIDField = mpTable.FindField("TRPELID");
            int idFieldOnMP = mpTable.FindField("ID");
            int mpJnctIDField = mpTable.FindField("JNCTID");
            int FJnctIDField = mpTable.FindField("F_JNCTID");
            int TJnctIDField = mpTable.FindField("T_JNCTID");
            int StreetsOIDField = mpTable.FindField("StreetsOID");

            // Open the Streets feature class and get its feature class ID

            IFeatureClass inputLineFeatures = fws.OpenFeatureClass(StreetsFCName);
            int streetsFCID = inputLineFeatures.FeatureClassID;

            // Define the fields for the RoadSplits table

            var ocd = new ObjectClassDescriptionClass() as IObjectClassDescription;
            var fieldsEdit = ocd.RequiredFields as IFieldsEdit;
            IFieldEdit field;

            // Add the anchor edge fields to the table

            field = new FieldClass();
            field.Name_2 = "EdgeFCID";
            field.Type_2 = esriFieldType.esriFieldTypeInteger;
            fieldsEdit.AddField(field);

            field = new FieldClass();
            field.Name_2 = "EdgeFID";
            field.Type_2 = esriFieldType.esriFieldTypeInteger;
            fieldsEdit.AddField(field);

            field = new FieldClass();
            field.Name_2 = "EdgeFrmPos";
            field.Type_2 = esriFieldType.esriFieldTypeDouble;
            fieldsEdit.AddField(field);

            field = new FieldClass();
            field.Name_2 = "EdgeToPos";
            field.Type_2 = esriFieldType.esriFieldTypeDouble;
            fieldsEdit.AddField(field);

            // Add the branch edge fields to the table

            for (short i = 0; i < 3; i++)
            {
                field = new FieldClass();
                field.Name_2 = "Branch" + i + "FCID";
                field.Type_2 = esriFieldType.esriFieldTypeInteger;
                fieldsEdit.AddField(field);

                field = new FieldClass();
                field.Name_2 = "Branch" + i + "FID";
                field.Type_2 = esriFieldType.esriFieldTypeInteger;
                fieldsEdit.AddField(field);

                field = new FieldClass();
                field.Name_2 = "Branch" + i + "FrmPos";
                field.Type_2 = esriFieldType.esriFieldTypeDouble;
                fieldsEdit.AddField(field);

                field = new FieldClass();
                field.Name_2 = "Branch" + i + "ToPos";
                field.Type_2 = esriFieldType.esriFieldTypeDouble;
                fieldsEdit.AddField(field);
            }

            // Check the fields and create the RoadSplits table

            var fieldChk = new FieldCheckerClass() as IFieldChecker;
            IEnumFieldError enumFieldErr = null;
            IFields validatedFields = null;
            fieldChk.ValidateWorkspace = fws as IWorkspace;
            fieldChk.Validate(fieldsEdit as IFields, out enumFieldErr, out validatedFields);
            var roadSplitsTable = fws.CreateTable(RoadSplitsTableName, validatedFields, ocd.InstanceCLSID, ocd.ClassExtensionCLSID, "") as ITable;

            // Find all the fields
            int EdgeFCIDFI = roadSplitsTable.FindField("EdgeFCID");
            int EdgeFIDFI = roadSplitsTable.FindField("EdgeFID");
            int EdgeFrmPosFI = roadSplitsTable.FindField("EdgeFrmPos");
            int EdgeToPosFI = roadSplitsTable.FindField("EdgeToPos");
            int Branch0FCIDFI = roadSplitsTable.FindField("Branch0FCID");
            int Branch0FIDFI = roadSplitsTable.FindField("Branch0FID");
            int Branch0FrmPosFI = roadSplitsTable.FindField("Branch0FrmPos");
            int Branch0ToPosFI = roadSplitsTable.FindField("Branch0ToPos");
            int Branch1FCIDFI = roadSplitsTable.FindField("Branch1FCID");
            int Branch1FIDFI = roadSplitsTable.FindField("Branch1FID");
            int Branch1FrmPosFI = roadSplitsTable.FindField("Branch1FrmPos");
            int Branch1ToPosFI = roadSplitsTable.FindField("Branch1ToPos");
            int Branch2FCIDFI = roadSplitsTable.FindField("Branch2FCID");
            int Branch2FIDFI = roadSplitsTable.FindField("Branch2FID");
            int Branch2FrmPosFI = roadSplitsTable.FindField("Branch2FrmPos");
            int Branch2ToPosFI = roadSplitsTable.FindField("Branch2ToPos");

            // Create insert cursor and row buffer for output

            ICursor tableInsertCursor = roadSplitsTable.Insert(true);
            IRowBuffer tableBuffer = roadSplitsTable.CreateRowBuffer();
            IRow row = tableBuffer as IRow;
            tableBuffer.set_Value(EdgeFCIDFI, null);
            tableBuffer.set_Value(EdgeFIDFI, null);
            tableBuffer.set_Value(EdgeFrmPosFI, null);
            tableBuffer.set_Value(EdgeToPosFI, null);
            tableBuffer.set_Value(Branch0FCIDFI, null);
            tableBuffer.set_Value(Branch0FIDFI, null);
            tableBuffer.set_Value(Branch0FrmPosFI, null);
            tableBuffer.set_Value(Branch0ToPosFI, null);
            tableBuffer.set_Value(Branch1FCIDFI, null);
            tableBuffer.set_Value(Branch1FIDFI, null);
            tableBuffer.set_Value(Branch1FrmPosFI, null);
            tableBuffer.set_Value(Branch1ToPosFI, null);
            tableBuffer.set_Value(Branch2FCIDFI, null);
            tableBuffer.set_Value(Branch2FIDFI, null);
            tableBuffer.set_Value(Branch2FrmPosFI, null);
            tableBuffer.set_Value(Branch2ToPosFI, null);

            // Create input cursor for the MP table we are importing

            ITableSort tableSort = new TableSortClass();
            tableSort.Fields = "ID, SEQNR";
            tableSort.set_Ascending("ID", true);
            tableSort.set_Ascending("SEQNR", true);
            tableSort.QueryFilter = null;
            tableSort.Table = mpTable;
            tableSort.Sort(null);
            ICursor inputCursor = tableSort.Rows;

            IRow inputTableRow = inputCursor.NextRow();
            if (inputTableRow == null)
                return;     // if MP table is empty, there's nothing to do

            long currentID = Convert.ToInt64(inputTableRow.get_Value(idFieldOnMP));

            int streetsOID = Convert.ToInt32(inputTableRow.get_Value(StreetsOIDField));
            int seqNr = Convert.ToInt32(inputTableRow.get_Value(seqNrField));
            double frmPos = 0.0;
            double toPos = 1.0;
            if (seqNr == 1)
            {
                if (Convert.ToInt64(inputTableRow.get_Value(mpJnctIDField)) == Convert.ToInt64(inputTableRow.get_Value(FJnctIDField)))
                {
                    frmPos = 1.0;
                    toPos = 0.0;
                }
            }
            else
            {
                if (Convert.ToInt64(inputTableRow.get_Value(mpJnctIDField)) == Convert.ToInt64(inputTableRow.get_Value(TJnctIDField)))
                {
                    frmPos = 1.0;
                    toPos = 0.0;
                }
            }

            switch (seqNr)
            {
                case 1:
                    tableBuffer.set_Value(EdgeFCIDFI, streetsFCID);
                    tableBuffer.set_Value(EdgeFIDFI, streetsOID);
                    tableBuffer.set_Value(EdgeFrmPosFI, frmPos);
                    tableBuffer.set_Value(EdgeToPosFI, toPos);
                    break;
                case 2:
                    tableBuffer.set_Value(Branch0FCIDFI, streetsFCID);
                    tableBuffer.set_Value(Branch0FIDFI, streetsOID);
                    tableBuffer.set_Value(Branch0FrmPosFI, frmPos);
                    tableBuffer.set_Value(Branch0ToPosFI, toPos);
                    break;
                case 3:
                    tableBuffer.set_Value(Branch1FCIDFI, streetsFCID);
                    tableBuffer.set_Value(Branch1FIDFI, streetsOID);
                    tableBuffer.set_Value(Branch1FrmPosFI, frmPos);
                    tableBuffer.set_Value(Branch1ToPosFI, toPos);
                    break;
                case 4:
                    tableBuffer.set_Value(Branch2FCIDFI, streetsFCID);
                    tableBuffer.set_Value(Branch2FIDFI, streetsOID);
                    tableBuffer.set_Value(Branch2FrmPosFI, frmPos);
                    tableBuffer.set_Value(Branch2ToPosFI, toPos);
                    break;
            }

            double previousID = currentID;

            while ((inputTableRow = inputCursor.NextRow()) != null)
            {
                currentID = Convert.ToInt64(inputTableRow.get_Value(idFieldOnMP));

                if (currentID != previousID)
                {
                    // write out the previous buffered row and reinitialize the buffer
                    tableInsertCursor.InsertRow(tableBuffer);

                    tableBuffer.set_Value(EdgeFCIDFI, null);
                    tableBuffer.set_Value(EdgeFIDFI, null);
                    tableBuffer.set_Value(EdgeFrmPosFI, null);
                    tableBuffer.set_Value(EdgeToPosFI, null);
                    tableBuffer.set_Value(Branch0FCIDFI, null);
                    tableBuffer.set_Value(Branch0FIDFI, null);
                    tableBuffer.set_Value(Branch0FrmPosFI, null);
                    tableBuffer.set_Value(Branch0ToPosFI, null);
                    tableBuffer.set_Value(Branch1FCIDFI, null);
                    tableBuffer.set_Value(Branch1FIDFI, null);
                    tableBuffer.set_Value(Branch1FrmPosFI, null);
                    tableBuffer.set_Value(Branch1ToPosFI, null);
                    tableBuffer.set_Value(Branch2FCIDFI, null);
                    tableBuffer.set_Value(Branch2FIDFI, null);
                    tableBuffer.set_Value(Branch2FrmPosFI, null);
                    tableBuffer.set_Value(Branch2ToPosFI, null);
                }

                streetsOID = Convert.ToInt32(inputTableRow.get_Value(StreetsOIDField));
                seqNr = Convert.ToInt32(inputTableRow.get_Value(seqNrField));
                frmPos = 0.0;
                toPos = 1.0;
                if (seqNr == 1)
                {
                    if (Convert.ToInt64(inputTableRow.get_Value(mpJnctIDField)) == Convert.ToInt64(inputTableRow.get_Value(FJnctIDField)))
                    {
                        frmPos = 1.0;
                        toPos = 0.0;
                    }
                }
                else
                {
                    if (Convert.ToInt64(inputTableRow.get_Value(mpJnctIDField)) == Convert.ToInt64(inputTableRow.get_Value(TJnctIDField)))
                    {
                        frmPos = 1.0;
                        toPos = 0.0;
                    }
                }

                switch (seqNr)
                {
                    case 1:
                        tableBuffer.set_Value(EdgeFCIDFI, streetsFCID);
                        tableBuffer.set_Value(EdgeFIDFI, streetsOID);
                        tableBuffer.set_Value(EdgeFrmPosFI, frmPos);
                        tableBuffer.set_Value(EdgeToPosFI, toPos);
                        break;
                    case 2:
                        tableBuffer.set_Value(Branch0FCIDFI, streetsFCID);
                        tableBuffer.set_Value(Branch0FIDFI, streetsOID);
                        tableBuffer.set_Value(Branch0FrmPosFI, frmPos);
                        tableBuffer.set_Value(Branch0ToPosFI, toPos);
                        break;
                    case 3:
                        tableBuffer.set_Value(Branch1FCIDFI, streetsFCID);
                        tableBuffer.set_Value(Branch1FIDFI, streetsOID);
                        tableBuffer.set_Value(Branch1FrmPosFI, frmPos);
                        tableBuffer.set_Value(Branch1ToPosFI, toPos);
                        break;
                    case 4:
                        tableBuffer.set_Value(Branch2FCIDFI, streetsFCID);
                        tableBuffer.set_Value(Branch2FIDFI, streetsOID);
                        tableBuffer.set_Value(Branch2FrmPosFI, frmPos);
                        tableBuffer.set_Value(Branch2ToPosFI, toPos);
                        break;
                }

                previousID = currentID;
            }

            // Write out the final row and flush
            tableInsertCursor.InsertRow(tableBuffer);
            tableInsertCursor.Flush();
        }
        private void CreateRoadSplitsTable(string inputRdmsTable, string outputFileGdbPath, IGPMessages messages, ITrackCancel trackcancel)
        {
            // Open the Rdms table and find all the fields we need

            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            var wsf = Activator.CreateInstance(factoryType) as IWorkspaceFactory;
            var fws = wsf.OpenFromFile(outputFileGdbPath, 0) as IFeatureWorkspace;
            ITable rdmsTable = fws.OpenTable(inputRdmsTable);
            int seqNumberField = rdmsTable.FindField("SEQ_NUMBER");
            int linkIDFieldOnRdms = rdmsTable.FindField("LINK_ID");
            int manLinkIDField = rdmsTable.FindField("MAN_LINKID");
            int condIDFieldOnRdms = rdmsTable.FindField("COND_ID");
            int endOfLkFieldOnRdms = rdmsTable.FindField("END_OF_LK");

            // Open the Streets feature class and get its feature class ID

            IFeatureClass inputLineFeatures = fws.OpenFeatureClass(StreetsFCName);
            int streetsFCID = inputLineFeatures.FeatureClassID;

            // Define the fields for the RoadSplits table

            var ocd = new ObjectClassDescriptionClass() as IObjectClassDescription;
            var fieldsEdit = ocd.RequiredFields as IFieldsEdit;
            IFieldEdit field;

            // Add the anchor edge fields to the table

            field = new FieldClass();
            field.Name_2 = "EdgeFCID";
            field.Type_2 = esriFieldType.esriFieldTypeInteger;
            fieldsEdit.AddField(field);

            field = new FieldClass();
            field.Name_2 = "EdgeFID";
            field.Type_2 = esriFieldType.esriFieldTypeInteger;
            fieldsEdit.AddField(field);

            field = new FieldClass();
            field.Name_2 = "EdgeFrmPos";
            field.Type_2 = esriFieldType.esriFieldTypeDouble;
            fieldsEdit.AddField(field);

            field = new FieldClass();
            field.Name_2 = "EdgeToPos";
            field.Type_2 = esriFieldType.esriFieldTypeDouble;
            fieldsEdit.AddField(field);

            // Add the branch edge fields to the table

            for (int i = 0; i < 3; i++)
            {
                field = new FieldClass();
                field.Name_2 = "Branch" + i + "FCID";
                field.Type_2 = esriFieldType.esriFieldTypeInteger;
                fieldsEdit.AddField(field);

                field = new FieldClass();
                field.Name_2 = "Branch" + i + "FID";
                field.Type_2 = esriFieldType.esriFieldTypeInteger;
                fieldsEdit.AddField(field);

                field = new FieldClass();
                field.Name_2 = "Branch" + i + "FrmPos";
                field.Type_2 = esriFieldType.esriFieldTypeDouble;
                fieldsEdit.AddField(field);

                field = new FieldClass();
                field.Name_2 = "Branch" + i + "ToPos";
                field.Type_2 = esriFieldType.esriFieldTypeDouble;
                fieldsEdit.AddField(field);
            }

            // Check the fields and create the RoadSplits table

            var fieldChk = new FieldCheckerClass() as IFieldChecker;
            IEnumFieldError enumFieldErr = null;
            IFields validatedFields = null;
            fieldChk.ValidateWorkspace = fws as IWorkspace;
            fieldChk.Validate(fieldsEdit as IFields, out enumFieldErr, out validatedFields);
            var roadSplitsTable = fws.CreateTable(RoadSplitsTableName, validatedFields, ocd.InstanceCLSID, ocd.ClassExtensionCLSID, "") as ITable;

            // Find all the fields
            int EdgeFCIDFI = roadSplitsTable.FindField("EdgeFCID");
            int EdgeFIDFI = roadSplitsTable.FindField("EdgeFID");
            int EdgeFrmPosFI = roadSplitsTable.FindField("EdgeFrmPos");
            int EdgeToPosFI = roadSplitsTable.FindField("EdgeToPos");
            int Branch0FCIDFI = roadSplitsTable.FindField("Branch0FCID");
            int Branch0FIDFI = roadSplitsTable.FindField("Branch0FID");
            int Branch0FrmPosFI = roadSplitsTable.FindField("Branch0FrmPos");
            int Branch0ToPosFI = roadSplitsTable.FindField("Branch0ToPos");
            int Branch1FCIDFI = roadSplitsTable.FindField("Branch1FCID");
            int Branch1FIDFI = roadSplitsTable.FindField("Branch1FID");
            int Branch1FrmPosFI = roadSplitsTable.FindField("Branch1FrmPos");
            int Branch1ToPosFI = roadSplitsTable.FindField("Branch1ToPos");
            int Branch2FCIDFI = roadSplitsTable.FindField("Branch2FCID");
            int Branch2FIDFI = roadSplitsTable.FindField("Branch2FID");
            int Branch2FrmPosFI = roadSplitsTable.FindField("Branch2FrmPos");
            int Branch2ToPosFI = roadSplitsTable.FindField("Branch2ToPos");

            // Fetch all line features referenced by the input Rdms table.  We do the
            // "join" this hard way to support all data sources in the sample.
            // Also, for large numbers of special explications, this strategy of fetching all
            // related features and holding them in RAM could be a problem.  To fix
            // this, one could process the input records from the Rdms table in batches.

            System.Collections.Hashtable lineFeaturesList = SignpostUtilities.FillFeatureCache(rdmsTable, linkIDFieldOnRdms, manLinkIDField,
                                                                                               inputLineFeatures, "LINK_ID", trackcancel);

            // Create insert cursor and row buffer for output

            ICursor tableInsertCursor = roadSplitsTable.Insert(true);
            IRowBuffer tableBuffer = roadSplitsTable.CreateRowBuffer();
            IRow row = tableBuffer as IRow;

            // Create input cursor for the Rdms table we are importing

            ITableSort tableSort = new TableSortClass();
            tableSort.Fields = "LINK_ID, COND_ID, SEQ_NUMBER";
            tableSort.set_Ascending("LINK_ID", true);
            tableSort.set_Ascending("COND_ID", true);
            tableSort.set_Ascending("SEQ_NUMBER", true);
            tableSort.QueryFilter = null;
            tableSort.Table = rdmsTable;
            tableSort.Sort(null);
            ICursor inputCursor = tableSort.Rows;

            IRow inputTableRow = inputCursor.NextRow();
            if (inputTableRow == null)
                return;     // if Rdms table is empty, there's nothing to do

            // these are initialized to prevent uninitialized variable compiler error
            SignpostUtilities.FeatureData linkFeatureData = new SignpostUtilities.FeatureData(-1, null);
            SignpostUtilities.FeatureData manLinkFeatureData = new SignpostUtilities.FeatureData(-1, null);

            ICurve fromEdgeCurve, toEdgeCurve;
            IPoint fromEdgeStart, fromEdgeEnd, toEdgeStart, toEdgeEnd;
            double fromEdgeFromPos = 0.0;
            double fromEdgeToPos = 1.0;
            double toEdgeFromPos = 0.0;
            double toEdgeToPos = 1.0;

            long currentLinkID = Convert.ToInt64(inputTableRow.get_Value(linkIDFieldOnRdms));
            long manLinkID = Convert.ToInt64(inputTableRow.get_Value(manLinkIDField));
            try
            {
                linkFeatureData = (SignpostUtilities.FeatureData)lineFeaturesList[currentLinkID];
                manLinkFeatureData = (SignpostUtilities.FeatureData)lineFeaturesList[manLinkID];

                // To set from and to position in the output table, we need see where and
                // if the two edge features connect to figure out their digitized direction.

                fromEdgeCurve = linkFeatureData.feature as ICurve;
                toEdgeCurve = manLinkFeatureData.feature as ICurve;

                fromEdgeStart = fromEdgeCurve.FromPoint;
                fromEdgeEnd = fromEdgeCurve.ToPoint;
                toEdgeStart = toEdgeCurve.FromPoint;
                toEdgeEnd = toEdgeCurve.ToPoint;

                // flip the from edge?

                if (TurnGeometryUtilities.EqualPoints(fromEdgeStart, toEdgeStart) || TurnGeometryUtilities.EqualPoints(fromEdgeStart, toEdgeEnd))
                {
                    fromEdgeFromPos = 1.0;
                    fromEdgeToPos = 0.0;
                }

                // flip the to edge?

                if (TurnGeometryUtilities.EqualPoints(toEdgeEnd, fromEdgeStart) || TurnGeometryUtilities.EqualPoints(toEdgeEnd, fromEdgeEnd))
                {
                    toEdgeFromPos = 1.0;
                    toEdgeToPos = 0.0;
                }

                // set the field values in the buffer

                tableBuffer.set_Value(EdgeFCIDFI, streetsFCID);
                tableBuffer.set_Value(EdgeFIDFI, linkFeatureData.OID);
                tableBuffer.set_Value(EdgeFrmPosFI, fromEdgeFromPos);
                tableBuffer.set_Value(EdgeToPosFI, fromEdgeToPos);
                tableBuffer.set_Value(Branch0FCIDFI, streetsFCID);
                tableBuffer.set_Value(Branch0FIDFI, manLinkFeatureData.OID);
                tableBuffer.set_Value(Branch0FrmPosFI, toEdgeFromPos);
                tableBuffer.set_Value(Branch0ToPosFI, toEdgeToPos);
                tableBuffer.set_Value(Branch1FCIDFI, null);
                tableBuffer.set_Value(Branch1FIDFI, null);
                tableBuffer.set_Value(Branch1FrmPosFI, null);
                tableBuffer.set_Value(Branch1ToPosFI, null);
                tableBuffer.set_Value(Branch2FCIDFI, null);
                tableBuffer.set_Value(Branch2FIDFI, null);
                tableBuffer.set_Value(Branch2FrmPosFI, null);
                tableBuffer.set_Value(Branch2ToPosFI, null);
            }
            catch
            {
                messages.AddWarning("Line feature not found for explication with from ID: " +
                    Convert.ToString(currentLinkID, System.Globalization.CultureInfo.InvariantCulture) +
                    ", To ID: " + Convert.ToString(manLinkID, System.Globalization.CultureInfo.InvariantCulture));
            }

            long previousLinkID = currentLinkID;
            int nextBranch = 1;

            while ((inputTableRow = inputCursor.NextRow()) != null)
            {
                currentLinkID = Convert.ToInt64(inputTableRow.get_Value(linkIDFieldOnRdms));
                manLinkID = Convert.ToInt64(inputTableRow.get_Value(manLinkIDField));
                try
                {
                    linkFeatureData = (SignpostUtilities.FeatureData)lineFeaturesList[currentLinkID];
                    manLinkFeatureData = (SignpostUtilities.FeatureData)lineFeaturesList[manLinkID];
                }
                catch
                {
                    messages.AddWarning("Line feature not found for explication with from ID: " +
                        Convert.ToString(currentLinkID, System.Globalization.CultureInfo.InvariantCulture) +
                        ", To ID: " + Convert.ToString(manLinkID, System.Globalization.CultureInfo.InvariantCulture));
                    continue;
                }

                // To set from and to position in the output table, we need see where and
                // if the two edge features connect to figure out their digitized direction.

                fromEdgeCurve = linkFeatureData.feature as ICurve;
                toEdgeCurve = manLinkFeatureData.feature as ICurve;

                fromEdgeStart = fromEdgeCurve.FromPoint;
                fromEdgeEnd = fromEdgeCurve.ToPoint;
                toEdgeStart = toEdgeCurve.FromPoint;
                toEdgeEnd = toEdgeCurve.ToPoint;

                fromEdgeFromPos = 0.0;
                fromEdgeToPos = 1.0;
                toEdgeFromPos = 0.0;
                toEdgeToPos = 1.0;

                // flip the from edge?

                if (TurnGeometryUtilities.EqualPoints(fromEdgeStart, toEdgeStart) || TurnGeometryUtilities.EqualPoints(fromEdgeStart, toEdgeEnd))
                {
                    fromEdgeFromPos = 1.0;
                    fromEdgeToPos = 0.0;
                }

                // flip the to edge?

                if (TurnGeometryUtilities.EqualPoints(toEdgeEnd, fromEdgeStart) || TurnGeometryUtilities.EqualPoints(toEdgeEnd, fromEdgeEnd))
                {
                    toEdgeFromPos = 1.0;
                    toEdgeToPos = 0.0;
                }

                // set the field values in the buffer

                if (previousLinkID == currentLinkID)
                {
                    switch (nextBranch)
                    {
                        case 1:
                            tableBuffer.set_Value(Branch1FCIDFI, streetsFCID);
                            tableBuffer.set_Value(Branch1FIDFI, manLinkFeatureData.OID);
                            tableBuffer.set_Value(Branch1FrmPosFI, toEdgeFromPos);
                            tableBuffer.set_Value(Branch1ToPosFI, toEdgeToPos);
                            nextBranch = 2;
                            break;
                        case 2:
                            tableBuffer.set_Value(Branch2FCIDFI, streetsFCID);
                            tableBuffer.set_Value(Branch2FIDFI, manLinkFeatureData.OID);
                            tableBuffer.set_Value(Branch2FrmPosFI, toEdgeFromPos);
                            tableBuffer.set_Value(Branch2ToPosFI, toEdgeToPos);
                            nextBranch = 3;
                            break;
                        case 3:
                            messages.AddWarning("There are more than three road splits for From ID: " +
                                Convert.ToString(currentLinkID, System.Globalization.CultureInfo.InvariantCulture));
                            nextBranch = 4;
                            break;
                        case 4:
                            // do nothing here, as there's no need to repeat the warning message.
                            break;
                    }
                }
                else
                {
                    // write out the previous buffered row...
                    tableInsertCursor.InsertRow(tableBuffer);

                    // ...and then set field values in the fresh buffer
                    tableBuffer.set_Value(EdgeFCIDFI, streetsFCID);
                    tableBuffer.set_Value(EdgeFIDFI, linkFeatureData.OID);
                    tableBuffer.set_Value(EdgeFrmPosFI, fromEdgeFromPos);
                    tableBuffer.set_Value(EdgeToPosFI, fromEdgeToPos);
                    tableBuffer.set_Value(Branch0FCIDFI, streetsFCID);
                    tableBuffer.set_Value(Branch0FIDFI, manLinkFeatureData.OID);
                    tableBuffer.set_Value(Branch0FrmPosFI, toEdgeFromPos);
                    tableBuffer.set_Value(Branch0ToPosFI, toEdgeToPos);
                    tableBuffer.set_Value(Branch1FCIDFI, null);
                    tableBuffer.set_Value(Branch1FIDFI, null);
                    tableBuffer.set_Value(Branch1FrmPosFI, null);
                    tableBuffer.set_Value(Branch1ToPosFI, null);
                    tableBuffer.set_Value(Branch2FCIDFI, null);
                    tableBuffer.set_Value(Branch2FIDFI, null);
                    tableBuffer.set_Value(Branch2FrmPosFI, null);
                    tableBuffer.set_Value(Branch2ToPosFI, null);
                    nextBranch = 1;
                }
                previousLinkID = currentLinkID;
            }

            // Write out the final row and flush
            tableInsertCursor.InsertRow(tableBuffer);
            tableInsertCursor.Flush();
        }
        private string CreatePatternsTable(string speedFilePath, string outputFileGdbPath, double fgdbVersion)
        {
            // Create the Profiles table in the output file geodatabase and open an InsertCursor on it

            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            var gdbWSF = Activator.CreateInstance(factoryType) as IWorkspaceFactory;
            var gdbFWS = gdbWSF.OpenFromFile(outputFileGdbPath, 0) as IFeatureWorkspace;
            var ocd = new ObjectClassDescriptionClass() as IObjectClassDescription;
            var tableFields = ocd.RequiredFields as IFieldsEdit;
            var newField = new FieldClass() as IFieldEdit;
            newField.Name_2 = "PatternID";
            newField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            tableFields.AddField(newField as IField);
            newField = new FieldClass();
            newField.Name_2 = "BaseSpeed";
            newField.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            tableFields.AddField(newField as IField);
            for (int i = 0; i < 96; i++)
            {
                newField = new FieldClass();
                newField.Type_2 = esriFieldType.esriFieldTypeSingle;
                newField.Name_2 = ((fgdbVersion == 10.0) ? "TimeFactor_" : "SpeedFactor_") + String.Format("{0:00}", i / 4) + String.Format("{0:00}", (i % 4) * 15);
                tableFields.AddField(newField as IField);
            }
            newField = new FieldClass();
            newField.Name_2 = "AverageSpeed";
            newField.Type_2 = esriFieldType.esriFieldTypeSingle;
            tableFields.AddField(newField as IField);
            ITable newTable = gdbFWS.CreateTable(ProfilesTableName, tableFields as IFields, ocd.InstanceCLSID, ocd.ClassExtensionCLSID, "");
            int newTablePatternIDField = newTable.FindField("PatternID");
            int newTableBaseSpeedField = newTable.FindField("BaseSpeed");
            int newTableAverageSpeedField = newTable.FindField("AverageSpeed");
            IRowBuffer buff = newTable.CreateRowBuffer();
            ICursor insertCursor = newTable.Insert(true);

            // Read each line of the Speed file and populate the newly-created Patterns table

            string listOfConstantPatterns = "";
            System.IO.StreamReader f = new System.IO.StreamReader(speedFilePath);
            string s = f.ReadLine();    // skip the first line (header)
            while ((s = f.ReadLine()) != null)
            {
                bool isConstantPattern = true;
                int commaPos = s.IndexOf(",");

                // First value is the ProfileID
                int patternID = Convert.ToInt32(s.Remove(commaPos), System.Globalization.CultureInfo.InvariantCulture);
                buff.set_Value(newTablePatternIDField, patternID);

                s = s.Substring(commaPos + 1);
                commaPos = s.IndexOf(",");

                // Second value is the BaseSpeed (midnight speed)
                int baseSpeed = Convert.ToInt32(s.Remove(commaPos), System.Globalization.CultureInfo.InvariantCulture);
                buff.set_Value(newTableBaseSpeedField, baseSpeed);

                // The midnight ratio is always 1.0
                buff.set_Value(newTableBaseSpeedField + 1, 1.0);
                float timeFactorSum = (float)1.0;
                float timeFactorSqSum = (float)1.0;

                // Remaining values are the other speeds
                for (int i = 2; i <= 96; i++)
                {
                    s = s.Substring(commaPos + 1);
                    commaPos = s.IndexOf(",");

                    int speed = Convert.ToInt32((commaPos < 0) ? s : s.Remove(commaPos), System.Globalization.CultureInfo.InvariantCulture);
                    float timeFactor = (float)baseSpeed / speed;
                    float timeFactorSq = timeFactor * timeFactor;
                    timeFactorSum += timeFactor;
                    timeFactorSqSum += timeFactorSq;
                    buff.set_Value(newTableBaseSpeedField + i, ((fgdbVersion == 10.0) ? timeFactor : (1 / timeFactor)));

                    if (speed != baseSpeed)
                        isConstantPattern = false;
                }

                buff.set_Value(newTableAverageSpeedField, baseSpeed * timeFactorSum / timeFactorSqSum);

                // Insert the row into the table
                insertCursor.InsertRow(buff);

                // If this is a constant pattern, add it to the list
                if (isConstantPattern)
                    listOfConstantPatterns += (patternID.ToString() + ", ");
            }
            f.Close();

            // Flush any outstanding writes to the table
            insertCursor.Flush();

            // Trim the excess ", " off the last item
            if (listOfConstantPatterns != "")
                listOfConstantPatterns = listOfConstantPatterns.Remove(listOfConstantPatterns.Length - 2);

            return listOfConstantPatterns;
        }
        private void CreateNonHistoricalPatternsTable(string outputFileGdbPath)
        {
            // Create the Patterns table in the output file geodatabase and open an InsertCursor on it

            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            var gdbWSF = Activator.CreateInstance(factoryType) as IWorkspaceFactory;
            var gdbFWS = gdbWSF.OpenFromFile(outputFileGdbPath, 0) as IFeatureWorkspace;
            var ocd = new ObjectClassDescriptionClass() as IObjectClassDescription;
            var tableFields = ocd.RequiredFields as IFieldsEdit;
            var newField = new FieldClass() as IFieldEdit;
            newField = new FieldClass();
            newField.Type_2 = esriFieldType.esriFieldTypeSingle;
            newField.Name_2 = "SpeedFactor_AM";
            tableFields.AddField(newField as IField);
            newField = new FieldClass();
            newField.Type_2 = esriFieldType.esriFieldTypeSingle;
            newField.Name_2 = "SpeedFactor_PM";
            tableFields.AddField(newField as IField);
            ITable newTable = gdbFWS.CreateTable(ProfilesTableName, tableFields as IFields, ocd.InstanceCLSID, ocd.ClassExtensionCLSID, "");
            IRowBuffer buff = newTable.CreateRowBuffer();
            ICursor insertCursor = newTable.Insert(true);

            int speedFactorAMField = newTable.FindField("SpeedFactor_AM");
            int speedFactorPMField = newTable.FindField("SpeedFactor_PM");
            buff.set_Value(speedFactorAMField, (float)1.0);
            buff.set_Value(speedFactorPMField, (float)1.0);
            insertCursor.InsertRow(buff);
            insertCursor.Flush();
        }
Example #24
0
        /// <summary>
        /// 创建字段集合
        /// </summary>
        /// <param name="ocDescription">要素类描述</param>
        /// <param name="tableStructureNode">表结构节点</param>
        /// <returns></returns>
        private IFields CreateFileds(TableStructureNode tableStructureNode, FeatureCodeNode featureCodeNode)
        {
            try
            {
                ///创建字段集合
                IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
                IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();
                IFields fields = ocDescription.RequiredFields;

                //从配置文件读取图形类型
                string sGeometryType = "";
                Metadata.MetaTable pMetaTalbe = Metadata.MetaDataFile.MetaTabls[tableStructureNode.TableName] as Metadata.MetaTable;
                if (pMetaTalbe != null)
                {
                    sGeometryType = Metadata.MetaDataFile.GraphConfig.GetGraphTypeMark(pMetaTalbe.Type);
                }

                //设置图形类型
                if (sGeometryType != "NoneGeometry")
                {
                    ocDescription = (IObjectClassDescription)fcDescription;
                    fields = ocDescription.RequiredFields;
                    int shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName);
                    IField pGeometryfield = fields.get_Field(shapeFieldIndex);
                    IGeometryDef geometryDef = pGeometryfield.GeometryDef;
                    IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
                    if (sGeometryType == "Point")
                        geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                    else if (sGeometryType == "Line")
                        geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
                    else if (sGeometryType == "Polygon")
                        geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;

                }
                IFieldsEdit fieldsEdit = fields as IFieldsEdit;
                // 遍历表结构数据
                int FieldCount = tableStructureNode.FieldNodes.Count;
                for (int i = 0; i < FieldCount; i++)
                {
                    IField field = new FieldClass();
                    IFieldEdit fieldEdit = (IFieldEdit)field;
                    ///获取字段信息
                    FieldNode pFieldNode = tableStructureNode.FieldNodes[i];
                    if (pFieldNode != null)
                    {
                        ///设置字段值
                        fieldEdit.Name_2 = pFieldNode.FieldName;

                        //从配置中获取别名
                        if (pMetaTalbe != null)
                            fieldEdit.AliasName_2 = pMetaTalbe.GetFiledALisNameByCode(pFieldNode.FieldName);
                        esriFieldType type = esriFieldType.esriFieldTypeString;
                        switch (pFieldNode.FieldType)
                        {
                            case "Char":
                                type = esriFieldType.esriFieldTypeString;         
                                break;
                            case "Int":
                                type = esriFieldType.esriFieldTypeInteger;
                                break;
                            case "Float":
                                type = esriFieldType.esriFieldTypeDouble;
                                break;
                            case "Time":
                                type = esriFieldType.esriFieldTypeDate;
                                break;
                            case "DateTime":
                                type = esriFieldType.esriFieldTypeDate;
                                break;
                            case "Varchar":
                                type = esriFieldType.esriFieldTypeString;
                                break;
                            case "Varbin":
                                type = esriFieldType.esriFieldTypeString;
                                break;
                            default:
                                break;
                        }
                        fieldEdit.Type_2 = type;
                        fieldEdit.Length_2 = pFieldNode.FieldLength;
                        fieldEdit.Precision_2 = pFieldNode.FieldPrecision;
                        fieldsEdit.AddField(field);
                    }
                }
                return fields;
            }
            catch(Exception ex)
            {
                Logger.WriteErrorLog(ex);
                return null;
            }

        }
        /// <summary>
        /// 创建反向匹配多边形字段
        /// </summary>
        /// <param name="workspace"></param>
        /// <returns></returns>
        public IFields CreateReverseMatchPolygonTFields(IWorkspace2 workspace)
        {
            IObjectClassDescription objectClassDescription = new ObjectClassDescriptionClass();
            IFields     fields     = new FieldsClass();
            IFieldsEdit fieldsEdit = fields as IFieldsEdit;

            fields = objectClassDescription.RequiredFields;

            IField     field     = new FieldClass();
            IFieldEdit fieldEdit = field as IFieldEdit;

            fieldEdit.Name_2       = "OBJECTID";
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeOID;
            fieldEdit.IsNullable_2 = false;
            fieldsEdit.AddField(field);

            IField     field1     = new FieldClass();
            IFieldEdit fieldEdit1 = field1 as IFieldEdit;

            fieldEdit1.Name_2       = "待更新OID";
            fieldEdit1.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit1.IsNullable_2 = true;
            fieldEdit1.AliasName_2  = "待更新OID";
            fieldEdit1.Editable_2   = true;
            fieldsEdit.AddField(field1);

            IField     field2     = new FieldClass();
            IFieldEdit fieldEdit2 = field2 as IFieldEdit;

            fieldEdit2.Name_2       = "源OID";
            fieldEdit2.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit2.IsNullable_2 = true;
            fieldEdit2.AliasName_2  = "源OID";
            fieldEdit2.Editable_2   = true;
            fieldsEdit.AddField(field2);

            IField     field3     = new FieldClass();
            IFieldEdit fieldEdit3 = field3 as IFieldEdit;

            fieldEdit3.Name_2       = "变化标记";
            fieldEdit3.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit3.IsNullable_2 = true;
            fieldEdit3.AliasName_2  = "变化标记";
            fieldEdit3.Editable_2   = true;
            fieldsEdit.AddField(field3);

            //    IField field4 = new FieldClass();
            //    IFieldEdit fieldEdit4 = field4 as IFieldEdit;
            //    fieldEdit4.Name_2 = "源编码";
            //    fieldEdit4.Type_2 = esriFieldType.esriFieldTypeString;
            //    fieldEdit4.IsNullable_2 = true;
            //    fieldEdit4.AliasName_2 = "源编码";
            //    fieldEdit4.Editable_2 = true;
            //    fieldsEdit.AddField(field4);

            //    IField field5 = new FieldClass();
            //    IFieldEdit fieldEdit5 = field5 as IFieldEdit;
            //    fieldEdit5.Name_2 = "更新编码";
            //    fieldEdit5.Type_2 = esriFieldType.esriFieldTypeString;
            //    fieldEdit5.IsNullable_2 = true;
            //    fieldEdit5.AliasName_2 = "更新编码";
            //    fieldEdit5.Editable_2 = true;
            //    fieldsEdit.AddField(field5);

            IField     field4     = new FieldClass();
            IFieldEdit fieldEdit4 = field4 as IFieldEdit;

            fieldEdit4.Name_2       = "位置相似度";
            fieldEdit4.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit4.IsNullable_2 = true;
            fieldEdit4.AliasName_2  = "位置相似度";
            fieldEdit4.Editable_2   = true;
            fieldsEdit.AddField(field4);

            IField     field5     = new FieldClass();
            IFieldEdit fieldEdit5 = field5 as IFieldEdit;

            fieldEdit5.Name_2       = "面积相似度";
            fieldEdit5.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit5.IsNullable_2 = true;
            fieldEdit5.AliasName_2  = "面积相似度";
            fieldEdit5.Editable_2   = true;
            fieldsEdit.AddField(field5);

            IField     field6     = new FieldClass();
            IFieldEdit fieldEdit6 = field6 as IFieldEdit;

            fieldEdit6.Name_2       = "形状相似度";
            fieldEdit6.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit6.IsNullable_2 = true;
            fieldEdit6.AliasName_2  = "形状相似度";
            fieldEdit6.Editable_2   = true;
            fieldsEdit.AddField(field6);

            IField     field7     = new FieldClass();
            IFieldEdit fieldEdit7 = field7 as IFieldEdit;

            fieldEdit7.Name_2       = "综合相似度";
            fieldEdit7.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit7.IsNullable_2 = true;
            fieldEdit7.AliasName_2  = "综合相似度";
            fieldEdit7.Editable_2   = true;
            fieldsEdit.AddField(field7);
            fields = fieldsEdit as IFields;
            return(fields);
        }
Example #26
0
        public IFields get_Fields(int ClassIndex)
        {
            IFieldEdit              fieldEdit;
            IFields                 fields;
            IFieldsEdit             fieldsEdit;
            IObjectClassDescription fcDesc;

            if (this.DatasetType == esriDatasetType.esriDTTable)
            {
                fcDesc = new ObjectClassDescriptionClass();
            }
            else
            {
                fcDesc = new FeatureClassDescriptionClass();
            }

            fields     = fcDesc.RequiredFields;
            fieldsEdit = (IFieldsEdit)fields;

            fieldEdit          = new FieldClass();
            fieldEdit.Length_2 = 1;
            fieldEdit.Name_2   = "ColumnOne";
            fieldEdit.Type_2   = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField((IField)fieldEdit);

            //HIGHLIGHT: Add extra int column
            fieldEdit        = new FieldClass();
            fieldEdit.Name_2 = "Extra";
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
            fieldsEdit.AddField((IField)fieldEdit);

            //HIGHLIGHT: Set shape field geometry definition
            if (this.DatasetType != esriDatasetType.esriDTTable)
            {
                IField field = fields.get_Field(fields.FindField("Shape"));
                fieldEdit = (IFieldEdit)field;
                IGeometryDefEdit geomDefEdit = (IGeometryDefEdit)field.GeometryDef;
                geomDefEdit.GeometryType_2 = geometryTypeByID(ClassIndex);
                ISpatialReference shapeSRef = this.spatialReference;

                #region M & Z
                //M
                if ((ClassIndex >= 3 && ClassIndex <= 5) || ClassIndex >= 9)
                {
                    geomDefEdit.HasM_2 = true;
                    shapeSRef.SetMDomain(0, 1000);
                }
                else
                {
                    geomDefEdit.HasM_2 = false;
                }

                //Z
                if (ClassIndex >= 6)
                {
                    geomDefEdit.HasZ_2 = true;
                    shapeSRef.SetZDomain(0, 1000);
                }
                else
                {
                    geomDefEdit.HasZ_2 = false;
                }
                #endregion

                geomDefEdit.SpatialReference_2 = shapeSRef;
            }

            return(fields);
        }
Example #27
0
        /// <summary>
        /// �������Ա�
        /// </summary>
        /// <param name="pFeatureWorkspace"></param>
        /// <param name="tableStructureNode"></param>
        /// <param name="featureCodeNode"></param>
        /// <returns></returns>
        private TableLayer CreateTableLayer(IFeatureWorkspace pFeatureWorkspace, TableStructureNode tableStructureNode, FeatureCodeNode featureCodeNode)
        {
            try
            {
                if (pFeatureWorkspace != null&&tableStructureNode!=null&&featureCodeNode!=null)
                {
                    IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();
                    ///�������ݱ��ֶ�
                    IFieldChecker fieldChecker = new FieldCheckerClass();
                    IFields validatedFields = CreateFileds(tableStructureNode, featureCodeNode);
                    ///�ֶ���Ϣ��֤
                    IFields fixFields = null;
                    fieldChecker.ValidateWorkspace = pFeatureWorkspace as IWorkspace;
                    IEnumFieldError enumFieldError = null;
                    fieldChecker.Validate(validatedFields, out enumFieldError, out fixFields);

                    ITable pTable = pFeatureWorkspace.CreateTable(tableStructureNode.TableName, fixFields,
                        ocDescription.InstanceCLSID, null, "");
                    if (pTable != null)
                    {
                        TableLayer pTableLayer = new TableLayer();

                        //�������ļ���ȡͼ������
                        string sGeometryType = "";
                        Metadata.MetaTable pMetaTalbe = Metadata.MetaDataFile.MetaTabls[tableStructureNode.TableName] as Metadata.MetaTable;
                        if (pMetaTalbe != null)
                        {
                            sGeometryType = pMetaTalbe.Type;
                        }
                        else
                            return null;

                        pTableLayer.GeometryType = sGeometryType;
                        pTableLayer.Table = pTable;
                        pTableLayer.UpdateFieldIndex();
                        return pTableLayer;
                    }
                    return null;
                }
                return null;
            }
            catch (Exception ex)
            {
                LogAPI.WriteErrorLog(ex);
                return null;
            }
        }
        public static ITable CreateTimeZoneTable(string outputFileGdbPath, string timeZone)
        {
            // start with the initial set of required fields for a table

            IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();
            IFieldsEdit outFields = ocDescription.RequiredFields as IFieldsEdit;

            // add the MSTIMEZONE field to the table

            IFieldEdit field = new FieldClass();
            field.Name_2 = "MSTIMEZONE";
            field.Type_2 = esriFieldType.esriFieldTypeString;
            field.Length_2 = 50;
            outFields.AddField(field);

            // open the file geodatabase

            Type gdbFactoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            var gdbWSF = Activator.CreateInstance(gdbFactoryType) as IWorkspaceFactory;
            var gdbFWS = gdbWSF.OpenFromFile(outputFileGdbPath, 0) as IFeatureWorkspace;

            // create the table

            ITable t = gdbFWS.CreateTable("TimeZones", outFields, ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, "");

            // create a record in the table with the specified time zone

            ICursor cur = t.Insert(true);
            IRowBuffer buff = t.CreateRowBuffer();
            buff.set_Value(t.FindField("MSTIMEZONE"), timeZone);
            cur.InsertRow(buff);

            // Flush any outstanding writes to the table
            cur.Flush();

            return t;
        }
        /// <summary>
        /// creates the Connection database used to auto download info from services
        /// </summary>
        public void createConnectionDb()
        {
            //servWks = gdutil.CreateWorkSpace(LcServiceCacheDir, System.IO.Path.GetFileName(LcCacheDb));// gdutil.CreateFileGdbOldWorkSpace(LcCacheDb, "9.3");
            try
            {
                UID uid = new UIDClass();
                uid.Value = "esriGeoDatabase.Object";
                IObjectClassDescription objectClassDescription = new ObjectClassDescriptionClass();

                fWks = (IFeatureWorkspace)servWks;
                //Create ServiceConnections table
                IFields tblFlds = objectClassDescription.RequiredFields;
                IFieldsEdit tblFldsE = (IFieldsEdit)tblFlds;
                IField fld = new FieldClass();
                IFieldEdit fldE = (IFieldEdit)fld;
                fldE.Name_2 = "CONNECTION";
                fldE.Type_2 = esriFieldType.esriFieldTypeString;
                fldE.Length_2 = 1000;
                fldE.IsNullable_2 = true;
                fldE.Editable_2 = true;
                fldE.AliasName_2 = "CONNECTION";
                tblFldsE.AddField(fldE);
                tblCon = fWks.CreateTable("SERVICECONNECTIONS", tblFldsE, uid, null, "");
                //Create Services Table related to ServiceConnctions
                tblFlds = objectClassDescription.RequiredFields;
                tblFldsE = (IFieldsEdit)tblFlds;
                fld = new FieldClass();
                fldE = (IFieldEdit)fld;
                fldE.Name_2 = "FKID";
                fldE.Type_2 = esriFieldType.esriFieldTypeInteger;
                fldE.IsNullable_2 = true;
                fldE.Editable_2 = true;
                fldE.AliasName_2 = "FKID";
                tblFldsE.AddField(fldE);
                fld = new FieldClass();
                fldE = (IFieldEdit)fld;
                fldE.Name_2 = "SERVICE";
                fldE.Type_2 = esriFieldType.esriFieldTypeString;
                fldE.Length_2 = 50;
                fldE.IsNullable_2 = true;
                fldE.Editable_2 = true;
                fldE.AliasName_2 = "SERVICE";
                tblFldsE.AddField(fldE);
                fld = new FieldClass();
                fldE = (IFieldEdit)fld;
                fldE.Name_2 = "URL";
                fldE.Type_2 = esriFieldType.esriFieldTypeString;
                fldE.Length_2 = 1000;
                fldE.IsNullable_2 = true;
                fldE.Editable_2 = true;
                fldE.AliasName_2 = "URL";
                tblFldsE.AddField(fldE);
                fld = new FieldClass();
                fldE = (IFieldEdit)fld;
                fldE.Name_2 = "STYPE";
                fldE.Type_2 = esriFieldType.esriFieldTypeString;
                fldE.Length_2 = 20;
                fldE.IsNullable_2 = true;
                fldE.Editable_2 = true;
                fldE.AliasName_2 = "STYPE";
                tblFldsE.AddField(fldE);
                tblSrv = fWks.CreateTable("SERVICES", tblFldsE, uid, null, "");
                //Create Layer Table related to Services
                tblFlds = objectClassDescription.RequiredFields;
                tblFldsE = (IFieldsEdit)tblFlds;
                fld = new FieldClass();
                fldE = (IFieldEdit)fld;
                fldE.Name_2 = "FKID";
                fldE.Type_2 = esriFieldType.esriFieldTypeInteger;
                fldE.IsNullable_2 = true;
                fldE.Editable_2 = true;
                fldE.AliasName_2 = "FKID";
                tblFldsE.AddField(fldE);
                fld = new FieldClass();
                fldE = (IFieldEdit)fld;
                fldE.Name_2 = "LAYERS";
                fldE.Type_2 = esriFieldType.esriFieldTypeString;
                fldE.Length_2 = 50;
                fldE.IsNullable_2 = true;
                fldE.Editable_2 = true;
                fldE.AliasName_2 = "LAYERS";
                tblFldsE.AddField(fldE);
                fld = new FieldClass();
                fldE = (IFieldEdit)fld;
                fldE.Name_2 = "LAYERID";
                fldE.Type_2 = esriFieldType.esriFieldTypeInteger;
                fldE.IsNullable_2 = true;
                fldE.Editable_2 = true;
                fldE.AliasName_2 = "LAYERID";
                tblFldsE.AddField(fldE);
                fld = new FieldClass();
                fldE = (IFieldEdit)fld;
                fldE.Name_2 = "UPDATE";
                fldE.Type_2 = esriFieldType.esriFieldTypeString;
                fldE.Length_2 = 3;
                fldE.IsNullable_2 = true;
                fldE.DefaultValue_2 = "NO";
                fldE.Editable_2 = true;
                fldE.AliasName_2 = "UPDATE";
                tblFldsE.AddField(fldE);
                tblLyr = fWks.CreateTable("LAYERS", tblFldsE, uid, null, "");
                int conIndex = tblCon.FindField("CONNECTION");
                IWorkspaceEdit wksE = (IWorkspaceEdit)servWks;
                bool weStart = false;
                if (!wksE.IsBeingEdited())
                {
                    wksE.StartEditing(false);
                    weStart = true;
                }
                wksE.StartEditOperation();
                IRow row = tblCon.CreateRow();
                row.set_Value(conIndex, gisProdServer);
                row.Store();
                wksE.StopEditOperation();
                if (weStart)
                {
                    wksE.StopEditing(true);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
            }
        }
Example #30
0
 public void InitFields()
 {
     if (this.m_IsFeatureClass)
     {
         IFeatureClassDescription description;
         IField            field;
         IGeometryDef      geometryDef;
         ISpatialReference spatialReference;
         if (this.m_FeatreType == esriFeatureType.esriFTSimple)
         {
             description         = new FeatureClassDescriptionClass();
             this.ShapeFieldName = description.ShapeFieldName;
             this.m_pFieds       = (description as IObjectClassDescription).RequiredFields;
             field       = this.m_pFieds.get_Field(this.m_pFieds.FindField(description.ShapeFieldName));
             geometryDef = field.GeometryDef;
             if (this.ifeatureDataset_0 != null)
             {
                 spatialReference = (this.ifeatureDataset_0 as IGeoDataset).SpatialReference;
             }
             else
             {
                 spatialReference = geometryDef.SpatialReference;
                 this.method_0(spatialReference);
             }
             (geometryDef as IGeometryDefEdit).SpatialReference_2 = spatialReference;
             (field as IFieldEdit).GeometryDef_2 = geometryDef;
         }
         else if (this.m_FeatreType == esriFeatureType.esriFTDimension)
         {
             description         = new DimensionClassDescriptionClass();
             this.ShapeFieldName = description.ShapeFieldName;
             this.m_pFieds       = (description as IObjectClassDescription).RequiredFields;
             field       = this.m_pFieds.get_Field(this.m_pFieds.FindField(description.ShapeFieldName));
             geometryDef = field.GeometryDef;
             if (this.ifeatureDataset_0 != null)
             {
                 spatialReference = (this.ifeatureDataset_0 as IGeoDataset).SpatialReference;
             }
             else
             {
                 spatialReference = geometryDef.SpatialReference;
                 this.method_0(spatialReference);
             }
             (geometryDef as IGeometryDefEdit).SpatialReference_2 = spatialReference;
             (field as IFieldEdit).GeometryDef_2 = geometryDef;
         }
         else if (this.m_FeatreType == esriFeatureType.esriFTAnnotation)
         {
             description         = new AnnotationFeatureClassDescriptionClass();
             this.ShapeFieldName = description.ShapeFieldName;
             this.m_pFieds       = (description as IObjectClassDescription).RequiredFields;
             field       = this.m_pFieds.get_Field(this.m_pFieds.FindField(description.ShapeFieldName));
             geometryDef = field.GeometryDef;
             if (this.ifeatureDataset_0 != null)
             {
                 spatialReference = (this.ifeatureDataset_0 as IGeoDataset).SpatialReference;
             }
             else
             {
                 spatialReference = geometryDef.SpatialReference;
                 this.method_0(spatialReference);
             }
             (geometryDef as IGeometryDefEdit).SpatialReference_2 = spatialReference;
             (field as IFieldEdit).GeometryDef_2 = geometryDef;
         }
     }
     else
     {
         IObjectClassDescription description2 = new ObjectClassDescriptionClass();
         this.m_pFieds = description2.RequiredFields;
     }
 }
Example #31
0
        /// <summary>
        /// 生成实体表字段
        /// </summary>
        /// <param name="workspace">保存路径</param>
        /// <returns></returns>
        public IFields CreateEntiTableFields(IWorkspace2 workspace)
        {
            IObjectClassDescription objectClassDescription = new ObjectClassDescriptionClass();
            IFields     fields     = new FieldsClass();
            IFieldsEdit fieldsEdit = fields as IFieldsEdit;

            fields = objectClassDescription.RequiredFields;

            IField     field     = new FieldClass();
            IFieldEdit fieldEdit = field as IFieldEdit;

            fieldEdit.Name_2       = "OBJECTID";
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeOID;
            fieldEdit.IsNullable_2 = false;
            fieldsEdit.AddField(field);

            IField     field0     = new FieldClass();
            IFieldEdit fieldEdit0 = field0 as IFieldEdit;

            fieldEdit0.Name_2       = "ENTIID";
            fieldEdit0.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit0.IsNullable_2 = false;
            fieldEdit0.AliasName_2  = "地理实体标识码";
            fieldEdit0.Editable_2   = true;
            fieldsEdit.AddField(field0);

            IField     field1     = new FieldClass();
            IFieldEdit fieldEdit1 = field1 as IFieldEdit;

            fieldEdit1.Name_2       = "FNAME";
            fieldEdit1.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit1.IsNullable_2 = true;
            fieldEdit1.AliasName_2  = "实体中文描述";
            fieldEdit1.Editable_2   = true;
            fieldsEdit.AddField(field1);

            IField     field2     = new FieldClass();
            IFieldEdit fieldEdit2 = field2 as IFieldEdit;

            fieldEdit2.Name_2       = "STARTDATE";
            fieldEdit2.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit2.IsNullable_2 = true;
            fieldEdit2.AliasName_2  = "起始时间";
            fieldEdit2.Editable_2   = true;
            fieldsEdit.AddField(field2);

            IField     field3     = new FieldClass();
            IFieldEdit fieldEdit3 = field3 as IFieldEdit;

            fieldEdit3.Name_2       = "ENDDATE";
            fieldEdit3.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit3.IsNullable_2 = true;
            fieldEdit3.AliasName_2  = "消亡时间";
            fieldEdit3.Editable_2   = true;
            fieldsEdit.AddField(field3);

            IField     field4     = new FieldClass();
            IFieldEdit fieldEdit4 = field4 as IFieldEdit;

            fieldEdit4.Name_2       = "UPDATEDATE";
            fieldEdit4.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit4.IsNullable_2 = true;
            fieldEdit4.AliasName_2  = "更新时间";
            fieldEdit4.Editable_2   = true;
            fieldsEdit.AddField(field4);



            IField     field5     = new FieldClass();
            IFieldEdit fieldEdit5 = field5 as IFieldEdit;

            fieldEdit5.Name_2       = "USOURCE";
            fieldEdit5.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit5.IsNullable_2 = true;
            fieldEdit5.AliasName_2  = "更新数据源";
            fieldEdit5.Editable_2   = true;
            fieldsEdit.AddField(field5);


            IField     field6     = new FieldClass();
            IFieldEdit fieldEdit6 = field6 as IFieldEdit;

            fieldEdit6.Name_2       = "ESOURCE";
            fieldEdit6.Type_2       = esriFieldType.esriFieldTypeString;
            fieldEdit6.IsNullable_2 = true;
            fieldEdit6.AliasName_2  = "实体所在数据源";
            fieldEdit6.Editable_2   = true;
            fieldsEdit.AddField(field6);


            fields = fieldsEdit as IFields;
            return(fields);
        }