コード例 #1
0
ファイル: FieldOpt.cs プロジェクト: zhongshuiyuan/WLib
 /// <summary>
 /// 检查字段集合中是否存在指定类型的字段
 /// </summary>
 /// <param name="fieldsEdit"></param>
 /// <param name="fieldType"></param>
 /// <returns></returns>
 public static bool IsExistFieldType(this IFieldsEdit fieldsEdit, esriFieldType fieldType)
 {
     for (int i = 0; i < fieldsEdit.FieldCount; i++)
     {
         if (fieldsEdit.get_Field(i).Type == fieldType)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #2
0
        private IFeatureClass method_2(IFeatureWorkspace ifeatureWorkspace_0, string string_4,
                                       esriFeatureType esriFeatureType_0, esriGeometryType esriGeometryType_0, IFields ifields_0)
        {
            IFeatureClass class2 = null;
            string        str;
            IFieldChecker checker = new FieldCheckerClass
            {
                ValidateWorkspace = ifeatureWorkspace_0 as IWorkspace
            };

            checker.ValidateTableName(string_4, out str);
            IObjectClassDescription description = null;

            if (esriFeatureType_0 == esriFeatureType.esriFTAnnotation)
            {
                return(this.method_1(ifeatureWorkspace_0, string_4, 1000.0, new TextSymbolClass(), ifields_0));
            }
            description = new FeatureClassDescriptionClass();
            IFieldsEdit requiredFields = description.RequiredFields as IFieldsEdit;
            IFieldEdit  edit2          = null;
            int         index          = requiredFields.FindField((description as IFeatureClassDescription).ShapeFieldName);

            edit2 = requiredFields.get_Field(index) as IFieldEdit;
            IGeometryDefEdit geometryDef  = edit2.GeometryDef as IGeometryDefEdit;
            esriFeatureType  esriFTSimple = esriFeatureType.esriFTSimple;

            edit2.GeometryDef_2 = geometryDef;
            for (int i = 0; i < ifields_0.FieldCount; i++)
            {
                requiredFields.AddField(ifields_0.get_Field(i));
            }
            try
            {
                class2 = ifeatureWorkspace_0.CreateFeatureClass(string_4, requiredFields, null, null, esriFTSimple,
                                                                (description as IFeatureClassDescription).ShapeFieldName, "");
            }
            catch (Exception exception)
            {
                Logger.Current.Error("", exception, "");
            }
            return(class2);
        }
コード例 #3
0
        private IFeatureClass method_1()
        {
            IFeatureClass class2 = null;

            if (this.iname_0 == null)
            {
                return(null);
            }
            object          obj2      = this.iname_0.Open();
            IWorkspace      workspace = null;
            IFeatureDataset dataset   = null;

            if (obj2 is IWorkspace)
            {
                workspace = obj2 as IWorkspace;
            }
            else if (obj2 is IFeatureDataset)
            {
                dataset   = obj2 as IFeatureDataset;
                workspace = dataset.Workspace;
            }
            IObjectClassDescription description = null;

            description = new FeatureClassDescriptionClass();
            IFieldsEdit requiredFields = description.RequiredFields as IFieldsEdit;
            IFieldEdit  field          = null;
            IFieldEdit  edit3          = null;
            int         index          = requiredFields.FindField((description as IFeatureClassDescription).ShapeFieldName);

            edit3 = requiredFields.get_Field(index) as IFieldEdit;
            IGeometryDefEdit geometryDef = edit3.GeometryDef as IGeometryDefEdit;

            if (this.cboGeometryType.SelectedIndex == 0)
            {
                geometryDef.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            }
            else if (this.cboGeometryType.SelectedIndex == 1)
            {
                geometryDef.GeometryType_2 = esriGeometryType.esriGeometryMultipoint;
            }
            else if (this.cboGeometryType.SelectedIndex == 2)
            {
                geometryDef.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
            }
            else if (this.cboGeometryType.SelectedIndex == 3)
            {
                geometryDef.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            }
            ISpatialReference spatialReference = geometryDef.SpatialReference;

            if (this.txtCoordinate.Tag is ISpatialReference)
            {
                spatialReference = this.txtCoordinate.Tag as ISpatialReference;
            }
            geometryDef.HasZ_2 = this.chkHasZ.Checked;
            geometryDef.HasM_2 = this.chkHasM.Checked;
            SpatialReferenctOperator.ChangeCoordinateSystem(workspace as IGeodatabaseRelease, spatialReference, false);
            geometryDef.SpatialReference_2 = spatialReference;
            esriFeatureType esriFTSimple = esriFeatureType.esriFTSimple;

            field             = new FieldClass();
            field.Name_2      = "Code";
            field.AliasName_2 = "要素编号";
            field.Type_2      = esriFieldType.esriFieldTypeInteger;
            requiredFields.AddField(field);
            string name = this.method_0(workspace, this.txtFeatureClassName.Text);

            try
            {
                if (dataset == null)
                {
                    class2 = (workspace as IFeatureWorkspace).CreateFeatureClass(name, requiredFields, null, null,
                                                                                 esriFTSimple, "Shape", "");
                }
                else
                {
                    class2 = dataset.CreateFeatureClass(name, requiredFields, null, null, esriFTSimple, "Shape", "");
                }
            }
            catch (Exception exception)
            {
                Logger.Current.Error("", exception, "");
            }
            return(class2);
        }
コード例 #4
0
        public static IFeatureClass CreateSignsFeatureClass(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 feature class

            IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDescription = fcDescription as IObjectClassDescription;
            IFieldsEdit outFields = ocDescription.RequiredFields as IFieldsEdit;

            // make the shape field to be of type polyline with the same spatial reference as the reference lines

            IField           shapeField  = outFields.get_Field(outFields.FindField(fcDescription.ShapeFieldName));
            IGeometryDefEdit geomDefEdit = shapeField.GeometryDef as IGeometryDefEdit;

            geomDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPolyline;
            geomDefEdit.SpatialReference_2 = (linesFeatureClass as IGeoDataset).SpatialReference;

            // add the other fields to the feature class

            IFieldEdit field = new FieldClass();

            field.Name_2   = "ExitName";
            field.Type_2   = esriFieldType.esriFieldTypeString;
            field.Length_2 = 24;
            outFields.AddField(field);

            string currentNumber;

            for (int i = 0; i < MaxBranchCount; i++)
            {
                currentNumber = Convert.ToString(i, System.Globalization.CultureInfo.InvariantCulture);

                field          = new FieldClass();
                field.Name_2   = "Branch" + currentNumber;
                field.Type_2   = esriFieldType.esriFieldTypeString;
                field.Length_2 = 180;
                outFields.AddField(field);

                field          = new FieldClass();
                field.Name_2   = "Branch" + currentNumber + "Dir";
                field.Type_2   = esriFieldType.esriFieldTypeString;
                field.Length_2 = 5;
                outFields.AddField(field);

                field          = new FieldClass();
                field.Name_2   = "Branch" + currentNumber + "Lng";
                field.Type_2   = esriFieldType.esriFieldTypeString;
                field.Length_2 = 2;
                outFields.AddField(field);

                field          = new FieldClass();
                field.Name_2   = "Toward" + currentNumber;
                field.Type_2   = esriFieldType.esriFieldTypeString;
                field.Length_2 = 180;
                outFields.AddField(field);

                field          = new FieldClass();
                field.Name_2   = "Toward" + currentNumber + "Lng";
                field.Type_2   = esriFieldType.esriFieldTypeString;
                field.Length_2 = 2;
                outFields.AddField(field);
            }

            // make the feature class

            IFeatureDataset pFeatureDataset = linesFeatureClass.FeatureDataset;
            IWorkspace      pWorkspace      = (linesFeatureClass as IDataset).Workspace;

            if (pFeatureDataset != null)
            {
                return(pFeatureDataset.CreateFeatureClass(name, outFields, ocDescription.InstanceCLSID,
                                                          ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDescription.ShapeFieldName, ""));
            }
            else if (pWorkspace is IFeatureWorkspace)
            {
                return((pWorkspace as IFeatureWorkspace).CreateFeatureClass(name, outFields, ocDescription.InstanceCLSID,
                                                                            ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDescription.ShapeFieldName, ""));
            }
            else
            {
                return(null);   // not expected
            }
        }