博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ArcEngine创建要素类_面类型
阅读量:6513 次
发布时间:2019-06-24

本文共 4375 字,大约阅读时间需要 14 分钟。

public ESRI.ArcGIS.Geodatabase.IFeatureClass CreateFeatureClass(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, ESRI.ArcGIS.Geodatabase.IFeatureDataset featureDataset, System.String featureClassName)        {            ESRI.ArcGIS.esriSystem.UID CLSID = null;            ESRI.ArcGIS.esriSystem.UID CLSEXT = null;            System.String strConfigKeyword = null;            if (featureClassName == "") return null; // name was not passed in             ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass;            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast            if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, featureClassName)) //feature class with that name already exists             {                featureClass = featureWorkspace.OpenFeatureClass(featureClassName);                return featureClass;            }            // assign the class id value if not assigned            if (CLSID == null)            {                CLSID = new ESRI.ArcGIS.esriSystem.UIDClass();                CLSID.Value = "esriGeoDatabase.Feature";            }            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass();            ESRI.ArcGIS.Geodatabase.IFields fields = null;            // if a fields collection is not passed in then supply our own            if (fields == null)            {                // create the fields using the required fields method                fields = objectClassDescription.RequiredFields;                ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast                ESRI.ArcGIS.Geodatabase.IField field = new ESRI.ArcGIS.Geodatabase.FieldClass();                // create a user defined text field                ESRI.ArcGIS.Geodatabase.IFieldEdit fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field; // Explicit Cast                // setup field properties                fieldEdit.Name_2 = "ZBDID";                fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString;                fieldEdit.IsNullable_2 = true;                fieldEdit.AliasName_2 = "坐标编号";                fieldEdit.DefaultValue_2 = "0";                fieldEdit.Editable_2 = true;                fieldEdit.Length_2 = 100;                // add field to field collection                fieldsEdit.AddField(field);                fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast            }            System.String strShapeField = "";            // locate the shape field            for (int j = 0; j < fields.FieldCount; j++)            {                if (fields.get_Field(j).Type == ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry)                {                    strShapeField = fields.get_Field(j).Name;                }            }            // Use IFieldChecker to create a validated fields collection.            ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();            ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null;            ESRI.ArcGIS.Geodatabase.IFields validatedFields = null;            fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)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.            // finally create and return the feature class            if (featureDataset == null)// if no feature dataset passed in, create at the workspace level            {                featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);            }            else            {                featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);            }            return featureClass;        }

 

转载于:https://www.cnblogs.com/leebokeyuan/p/5578154.html

你可能感兴趣的文章