Ejemplo n.º 1
0
        public ESRI.ArcGIS.Geodatabase.IField CreateFieldInt(string fieldName)
        {
            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         = fieldName;
            fieldEdit.Type_2         = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeInteger;
            fieldEdit.IsNullable_2   = true;
            fieldEdit.AliasName_2    = fieldName;
            fieldEdit.DefaultValue_2 = 0;
            fieldEdit.Editable_2     = true;

            return(field);
        }
Ejemplo n.º 2
0
        public ESRI.ArcGIS.Geodatabase.IField CreateFieldDouble(string fieldName, int precision, int scale)
        {
            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         = fieldName;
            fieldEdit.Type_2         = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDouble;
            fieldEdit.IsNullable_2   = true;
            fieldEdit.AliasName_2    = fieldName;
            fieldEdit.DefaultValue_2 = 0;
            fieldEdit.Editable_2     = true;
            fieldEdit.Precision_2    = precision;
            fieldEdit.Scale_2        = scale;

            return(field);
        }
Ejemplo n.º 3
0
        public static IFeatureClass CreateFeatureClassInPGDB(IWorkspace2 workspace, IFeatureDataset featureDataset, string featureClassName, IFields fields, UID CLSID, UID CLSEXT, string strConfigKeyword, esriGeometryType esriGeometryType)
        {
            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();


            // 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         = "SampleField";
                fieldEdit.Type_2         = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString;
                fieldEdit.IsNullable_2   = true;
                fieldEdit.AliasName_2    = "Sample Field Column";
                fieldEdit.DefaultValue_2 = "test";
                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 == esriFieldType.esriFieldTypeGeometry)
                {
                    strShapeField = fields.get_Field(j).Name;
                    ((IGeometryDefEdit)fields.get_Field(j).GeometryDef).GeometryType_2 = esriGeometryType;
                }
            }

            // 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);
        }